MCPcopy Create free account
hub / github.com/choosehappy/QuickAnnotator / limitToFilter

Function limitToFilter

static/js/angular.js:23224–23249  ·  view source on GitHub ↗

* @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

()

Source from the content-addressed store, hash-verified

23222 </example>
23223*/
23224function limitToFilter() {
23225 return function(input, limit, begin) {
23226 if (Math.abs(Number(limit)) === Infinity) {
23227 limit = Number(limit);
23228 } else {
23229 limit = toInt(limit);
23230 }
23231 if (isNumberNaN(limit)) return input;
23232
23233 if (isNumber(input)) input = input.toString();
23234 if (!isArrayLike(input)) return input;
23235
23236 begin = (!begin || isNaN(begin)) ? 0 : toInt(begin);
23237 begin = (begin < 0) ? Math.max(0, input.length + begin) : begin;
23238
23239 if (limit >= 0) {
23240 return sliceFn(input, begin, begin + limit);
23241 } else {
23242 if (begin === 0) {
23243 return sliceFn(input, limit, input.length);
23244 } else {
23245 return sliceFn(input, Math.max(0, begin + limit), begin);
23246 }
23247 }
23248 };
23249}
23250
23251function sliceFn(input, begin, end) {
23252 if (isString(input)) return input.slice(begin, end);

Callers

nothing calls this directly

Calls 4

toIntFunction · 0.85
isNumberFunction · 0.85
sliceFnFunction · 0.85
isArrayLikeFunction · 0.70

Tested by

no test coverage detected