UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

85 lines (84 loc) 3.52 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { isBlank, isString, isArray, StringWrapper } from 'angular2/src/facade/lang'; import { ListWrapper } from 'angular2/src/facade/collection'; import { Injectable, Pipe } from 'angular2/core'; import { InvalidPipeArgumentException } from './invalid_pipe_argument_exception'; /** * Creates a new List or String containing only a subset (slice) of the * elements. * * The starting index of the subset to return is specified by the `start` parameter. * * The ending index of the subset to return is specified by the optional `end` parameter. * * ### Usage * * expression | slice:start[:end] * * All behavior is based on the expected behavior of the JavaScript API * Array.prototype.slice() and String.prototype.slice() * * Where the input expression is a [List] or [String], and `start` is: * * - **a positive integer**: return the item at _start_ index and all items after * in the list or string expression. * - **a negative integer**: return the item at _start_ index from the end and all items after * in the list or string expression. * - **`|start|` greater than the size of the expression**: return an empty list or string. * - **`|start|` negative greater than the size of the expression**: return entire list or * string expression. * * and where `end` is: * * - **omitted**: return all items until the end of the input * - **a positive integer**: return all items before _end_ index of the list or string * expression. * - **a negative integer**: return all items before _end_ index from the end of the list * or string expression. * * When operating on a [List], the returned list is always a copy even when all * the elements are being returned. * * ## List Example * * This `ngFor` example: * * {@example core/pipes/ts/slice_pipe/slice_pipe_example.ts region='SlicePipe_list'} * * produces the following: * * <li>b</li> * <li>c</li> * * ## String Examples * * {@example core/pipes/ts/slice_pipe/slice_pipe_example.ts region='SlicePipe_string'} */ let SlicePipe_1; export let SlicePipe = SlicePipe_1 = class SlicePipe { transform(value, start, end = null) { if (!this.supports(value)) { throw new InvalidPipeArgumentException(SlicePipe_1, value); } if (isBlank(value)) return value; if (isString(value)) { return StringWrapper.slice(value, start, end); } return ListWrapper.slice(value, start, end); } supports(obj) { return isString(obj) || isArray(obj); } }; SlicePipe = SlicePipe_1 = __decorate([ Pipe({ name: 'slice', pure: false }), Injectable(), __metadata('design:paramtypes', []) ], SlicePipe);