* @ngdoc filter * @name limitTo * @kind function * * @description * Creates a new array or string containing only a specified number of elements. The elements * are taken from either the beginning or the end of the source array, string or number, as specified by * the value and sign (positive
()
| 19189 | </example> |
| 19190 | */ |
| 19191 | function limitToFilter() { |
| 19192 | return function(input, limit, begin) { |
| 19193 | if (Math.abs(Number(limit)) === Infinity) { |
| 19194 | limit = Number(limit); |
| 19195 | } else { |
| 19196 | limit = toInt(limit); |
| 19197 | } |
| 19198 | if (isNaN(limit)) return input; |
| 19199 | |
| 19200 | if (isNumber(input)) input = input.toString(); |
| 19201 | if (!isArray(input) && !isString(input)) return input; |
| 19202 | |
| 19203 | begin = (!begin || isNaN(begin)) ? 0 : toInt(begin); |
| 19204 | begin = (begin < 0 && begin >= -input.length) ? input.length + begin : begin; |
| 19205 | |
| 19206 | if (limit >= 0) { |
| 19207 | return input.slice(begin, begin + limit); |
| 19208 | } else { |
| 19209 | if (begin === 0) { |
| 19210 | return input.slice(limit, input.length); |
| 19211 | } else { |
| 19212 | return input.slice(Math.max(0, begin + limit), begin); |
| 19213 | } |
| 19214 | } |
| 19215 | }; |
| 19216 | } |
| 19217 | |
| 19218 | /** |
| 19219 | * @ngdoc filter |