@angular-ru/cdk/object

  • sortByAsc

const objectList: A[] = [{a: 1}, {a: 3}, {a: 2}, {a: -1}, {a: 0}];

expect(objectList.slice().sort((a, b) => sortByAsc('a', a, b))).toEqual([{a: -1}, {a: 0}, {a: 1}, {a: 2}, {a: 3}]);
  • sortByDesc

const objectList: A[] = [{a: 1}, {a: 3}, {a: 2}, {a: -1}, {a: 0}];

expect(objectList.slice().sort((a, b) => sortByDesc('a', a, b))).toEqual([{a: 3}, {a: 2}, {a: 1}, {a: 0}, {a: -1}]);
  • isObject - check inheritance of object

import {isObject} from '@angular-ru/cdk/object';

class A {}

expect(isObject(NaN)).toBe(false);
expect(isObject(null)).toBe(false);
expect(isObject(undefined)).toBe(false);
expect(isObject(1)).toBe(false);
expect(isObject(Infinity)).toBe(false);
expect(isObject('')).toBe(false);
// non primitive
expect(isObject([])).toBe(true);
expect(isObject({})).toBe(true);
expect(isObject(new A())).toBe(true);
expect(isObject(new Date())).toBe(true);
expect(isObject(new Map())).toBe(true);
expect(isObject(() => {})).toBe(true);
expect(isObject(new Number(6))).toBe(true);
expect(isObject(Math)).toBe(true);
expect(isObject(Object.create(null))).toBe(true);
expect(isObject(document.createElement('div'))).toBe(true);
expect(isObject(new (function Foo() {})())).toBe(true);
expect(isObject(window)).toBe(true);
  • isPlainObject - check only literal object (non instance object)

  • isSimpleObject - check only instance object or literal (non complex structure - Array, DOM, Set, Map, Date, other structure)

  • isGetter

  • isIterable

  • deepClone

  • deepFreeze

  • replaceWithNull

  • clean

  • getValueByPath

  • checkIsShallowEmpty

  • equals, objectToString, flatten, strictEquals, shallowTrimProperties

  • shallowMapObject

Last updated