Browse Source

feat: add pushValueTo array util to core

pull/4377/head
Arman Ozak 6 years ago
parent
commit
117b47bba6
  1. 17
      npm/ng-packs/packages/core/src/lib/tests/array-utils.spec.ts
  2. 6
      npm/ng-packs/packages/core/src/lib/utils/array-utils.ts
  3. 1
      npm/ng-packs/packages/core/src/lib/utils/index.ts

17
npm/ng-packs/packages/core/src/lib/tests/array-utils.spec.ts

@ -0,0 +1,17 @@
import { pushValueTo } from '../utils/array-utils';
describe('Array Utils', () => {
describe('#pushValueTo', () => {
test.each`
source | target | expected
${[]} | ${[0, 1, 2, 3]} | ${[0, 1, 2, 3]}
${[3]} | ${[0, 1, 2]} | ${[0, 1, 2, 3]}
${[2, 3]} | ${[0, 1]} | ${[0, 1, 2, 3]}
${[1, 2, 3]} | ${[0]} | ${[0, 1, 2, 3]}
${[0, 1, 2, 3]} | ${[]} | ${[0, 1, 2, 3]}
`('should push $source to $target when called in forEach', ({ source, target, expected }) => {
source.forEach(pushValueTo(target));
expect(target).toEqual(expected);
});
});
});

6
npm/ng-packs/packages/core/src/lib/utils/array-utils.ts

@ -0,0 +1,6 @@
export function pushValueTo<T extends any>(array: T[]) {
return (element: T) => {
array.push(element);
return array;
};
}

1
npm/ng-packs/packages/core/src/lib/utils/index.ts

@ -1,3 +1,4 @@
export * from './array-utils';
export * from './common-utils';
export * from './factory-utils';
export * from './form-utils';

Loading…
Cancel
Save