parent
1513e201bb
commit
83c19a1fbc
|
@ -42,6 +42,8 @@ import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
* When operating on a [List], the returned list is always a copy even when all
|
* When operating on a [List], the returned list is always a copy even when all
|
||||||
* the elements are being returned.
|
* the elements are being returned.
|
||||||
*
|
*
|
||||||
|
* When operating on a blank value, returns it.
|
||||||
|
*
|
||||||
* ## List Example
|
* ## List Example
|
||||||
*
|
*
|
||||||
* This `ngFor` example:
|
* This `ngFor` example:
|
||||||
|
@ -62,10 +64,10 @@ import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SlicePipe implements PipeTransform {
|
export class SlicePipe implements PipeTransform {
|
||||||
transform(value: any, start: number, end: number = null): any {
|
transform(value: any, start: number, end: number = null): any {
|
||||||
|
if (isBlank(value)) return value;
|
||||||
if (!this.supports(value)) {
|
if (!this.supports(value)) {
|
||||||
throw new InvalidPipeArgumentException(SlicePipe, value);
|
throw new InvalidPipeArgumentException(SlicePipe, value);
|
||||||
}
|
}
|
||||||
if (isBlank(value)) return value;
|
|
||||||
if (isString(value)) {
|
if (isString(value)) {
|
||||||
return StringWrapper.slice(value, start, end);
|
return StringWrapper.slice(value, start, end);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ export function main() {
|
||||||
|
|
||||||
describe("transform", () => {
|
describe("transform", () => {
|
||||||
|
|
||||||
|
it('should return null if the value is null',
|
||||||
|
() => { expect(pipe.transform(null, [4, 2])).toBe(null); });
|
||||||
|
|
||||||
it('should return all items after START index when START is positive and END is omitted',
|
it('should return all items after START index when START is positive and END is omitted',
|
||||||
() => {
|
() => {
|
||||||
expect(pipe.transform(list, 3)).toEqual([4, 5]);
|
expect(pipe.transform(list, 3)).toEqual([4, 5]);
|
||||||
|
|
Loading…
Reference in New Issue