@naturalcycles/js-lib
Advanced tools
Comparing version 1.0.15 to 1.0.16
@@ -29,3 +29,3 @@ { | ||
}, | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"description": "", | ||
@@ -32,0 +32,0 @@ "author": "Natural Cycles Team", |
@@ -1,2 +0,2 @@ | ||
import { deepFreeze, silentConsole, silentConsoleIfRunAll } from './test.shared.util' | ||
import { deepFreeze, runAllTests, silentConsole, silentConsoleIfRunAll } from './test.shared.util' | ||
@@ -17,2 +17,14 @@ test('deepFreeze', () => { | ||
silentConsoleIfRunAll() | ||
console.log() | ||
console.debug() | ||
console.info() | ||
console.warn() | ||
console.error() | ||
}) | ||
test('runAllTests', () => { | ||
runAllTests() | ||
process.argv = [] | ||
expect(runAllTests()).toBe(false) | ||
}) |
@@ -0,1 +1,2 @@ | ||
import { deepFreeze } from '../testing/test.shared.util' | ||
import { objectUtil } from './object.util' | ||
@@ -114,2 +115,21 @@ | ||
test('filterUndefinedValues', () => { | ||
const o = { | ||
a: 1, | ||
b: 0, | ||
c: undefined, | ||
d: null, | ||
e: '', | ||
f: 'wer', | ||
} | ||
deepFreeze(o) | ||
expect(objectUtil.filterUndefinedValues(o)).toEqual({ | ||
a: 1, | ||
b: 0, | ||
e: '', | ||
f: 'wer', | ||
}) | ||
}) | ||
test('filterValues', () => { | ||
@@ -220,2 +240,26 @@ const f = objectUtil.filterValues.bind(objectUtil) | ||
test('isEmptyObject', () => { | ||
const a = [1, 0, -1, undefined, null, 'wer', 'a', '', {}, { a: 'b' }] | ||
const empty = a.filter(i => objectUtil.isEmptyObject(i)) | ||
expect(empty).toEqual([{}]) | ||
}) | ||
test('mergeDeep', () => { | ||
const a1 = { | ||
b: { | ||
c: 'c1', | ||
}, | ||
e: 'e1', | ||
} | ||
const a2 = { | ||
b: { | ||
c2: 'c2', | ||
}, | ||
d: 'd2', | ||
} | ||
expect(objectUtil.mergeDeep(a1, a2)).toMatchSnapshot() | ||
}) | ||
test('mask', () => { | ||
@@ -326,2 +370,4 @@ const o = { | ||
test('by', () => { | ||
expect(objectUtil.by(undefined, 'a')).toEqual({}) | ||
const a = [{ a: 'aa' }, { a: 'ab' }, { b: 'bb' }] | ||
@@ -328,0 +374,0 @@ const r = objectUtil.by(a, 'a') |
@@ -85,3 +85,3 @@ import { StringMap } from '../types' | ||
isEmpty (obj: any): boolean { | ||
isEmptyObject (obj: any): boolean { | ||
return obj && obj.constructor === Object && Object.keys(obj).length === 0 | ||
@@ -122,3 +122,3 @@ } | ||
changeKey (o: { [key: string]: any }, mapFn: (key: string) => string) { | ||
changeKey (o: StringMap<any>, mapFn: (key: string) => string) { | ||
return Object.keys(o).reduce( | ||
@@ -129,3 +129,3 @@ (prev, key) => { | ||
}, | ||
{} as { [key: string]: any }, | ||
{} as StringMap<any>, | ||
) | ||
@@ -146,10 +146,2 @@ } | ||
sortObject<T> (o: T): T { | ||
if (typeof o !== 'object') return o | ||
return Object.keys(o) | ||
.sort() | ||
.reduce((r: any, k: any) => ((r[k] = (o as any)[k]), r), {} as any) | ||
} | ||
private defaultSortFn (a: any, b: any): number { | ||
@@ -156,0 +148,0 @@ return a.localeCompare(b) |
@@ -7,4 +7,8 @@ import { stringSharedUtil } from './string.shared.util' | ||
test('lowercaseFirstLetter', () => { | ||
expect(stringSharedUtil.lowercaseFirstLetter('Abc')).toBe('abc') | ||
}) | ||
test('removeWhitespace', () => { | ||
expect(stringSharedUtil.removeWhitespace(' 1 * A ')).toBe('1*A') | ||
}) |
Sorry, the diff of this file is not supported yet
23917
19
808