@dhmk/utils
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -88,5 +88,3 @@ var __assign = (this && this.__assign) || function () { | ||
var _a; | ||
return Object.assign({}, obj, (_a = {}, | ||
_a[key] = typeof what === "function" ? what(obj[key], key) : what, | ||
_a)); | ||
return __assign(__assign({}, obj), (_a = {}, _a[key] = typeof what === "function" ? what(obj[key], key) : what, _a)); | ||
}, | ||
@@ -93,0 +91,0 @@ delete: function (obj, key) { |
@@ -10,1 +10,3 @@ export * from "./error"; | ||
export * from "./redux"; | ||
export * from "./data-adapter"; | ||
export * from "./lens"; |
@@ -10,1 +10,3 @@ export * from "./error"; | ||
export * from "./redux"; | ||
export * from "./data-adapter"; | ||
export * from "./lens"; |
@@ -1,2 +0,2 @@ | ||
import { StrKeyOf, DeepReadonly } from "./types"; | ||
import { StrKeyOf, DeepReadonly, DeepPartial } from "./types"; | ||
export declare const noop: () => void; | ||
@@ -6,2 +6,3 @@ export declare const id: <T>(x: T) => T; | ||
export declare const arraysEqual: <T>(a: readonly T[], b: readonly T[]) => boolean; | ||
export declare const shallowEqual: (a: object, b: object) => boolean; | ||
export declare function objectFrom<V, K extends keyof any = keyof any>(entries: Iterable<[K, V]>): Record<K, V>; | ||
@@ -26,5 +27,12 @@ declare type ValueMapper<T, R = any> = (v: T[StrKeyOf<T>], k: StrKeyOf<T>, src: T) => R; | ||
export declare const merge: Merge; | ||
declare type MergeDeep = { | ||
<T>(a: T, b: DeepPartial<T>): T; | ||
<T, P = DeepPartial<T>>(b: P): (a: T) => T; | ||
}; | ||
export declare const mergeDeep: MergeDeep; | ||
export declare const join: <A extends string, B extends string, S extends string>(a: A, sep: S, b: B) => `${A}${S}${B}`; | ||
export declare const namespace: <S extends string>(s: S) => <SS extends string>(suffix: SS) => `${S}/${SS}`; | ||
export declare function assert(condition: any, msg?: string): asserts condition; | ||
export declare const isPlainObject: (x: any) => x is object; | ||
export declare function flatMap<T, R>(src: ReadonlyArray<T>, fn: (item: T, index: number) => ReadonlyArray<R>): R[]; | ||
export {}; |
@@ -30,2 +30,7 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
export var shallowEqual = function (a, b) { | ||
var ka = Object.keys(a); | ||
var kb = Object.keys(b); | ||
return ka.length === kb.length && ka.every(function (k) { return a[k] === b[k]; }); | ||
}; | ||
export function objectFrom(entries) { | ||
@@ -86,2 +91,15 @@ return Array.from(entries).reduce(function (res, _a) { | ||
}; | ||
var mergeDeepRec = function (a, b) { | ||
if (!isPlainObject(a)) | ||
return b; | ||
var res = __assign({}, a); | ||
for (var k in b) { | ||
var v = b[k]; | ||
res[k] = mergeDeepRec(a[k], v); | ||
} | ||
return res; | ||
}; | ||
export var mergeDeep = function (a, b) { | ||
return b ? mergeDeepRec(a, b) : function (b) { return mergeDeepRec(b, a); }; | ||
}; | ||
export var join = function (a, sep, b) { return (a + sep + b); }; | ||
@@ -98,1 +116,9 @@ export var namespace = function (s) { | ||
} | ||
export var isPlainObject = function (x) { | ||
return !!x && typeof x === "object" && Object.getPrototypeOf(x) === Object.prototype; | ||
}; | ||
export function flatMap(src, fn) { | ||
var res = []; | ||
src.forEach(function (x, i) { return res.push.apply(res, fn(x, i)); }); | ||
return res; | ||
} |
@@ -9,6 +9,8 @@ export declare class Tag<T> { | ||
export declare type Initializer1<A, T = A> = T extends Function ? never : T | ((arg: A) => T); | ||
export declare type ValueOrFunction<T> = T extends Function ? (value: T) => T : T | ((value: T) => T); | ||
export declare type PromiseType<T> = T | PromiseLike<T>; | ||
export declare type UnwrapPromise<T> = T extends PromiseLike<infer R> ? UnwrapPromise<R> : T; | ||
export declare type Overwrite<A, B> = Omit<A, keyof B> & B; | ||
declare type Primitive = undefined | null | boolean | string | number | Function; | ||
declare type Primitive = undefined | null | boolean | string | number | Function | Date | RegExp; | ||
declare type NotPlainObject = Primitive | ReadonlyArray<any> | ReadonlySet<any> | ReadonlyMap<any, any>; | ||
export declare type DeepReadonly<T> = T extends Primitive ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer T> ? ReadonlySet<DeepReadonly<T>> : { | ||
@@ -18,2 +20,5 @@ readonly [P in keyof T]: DeepReadonly<T[P]>; | ||
export declare type ArrayItem<T> = T extends ReadonlyArray<infer U> ? U : never; | ||
export declare type DeepPartial<T> = T extends NotPlainObject ? T : { | ||
[P in keyof T]?: T[P] extends NotPlainObject ? T[P] : DeepPartial<T[P]>; | ||
}; | ||
export {}; |
@@ -91,5 +91,3 @@ "use strict"; | ||
var _a; | ||
return Object.assign({}, obj, (_a = {}, | ||
_a[key] = typeof what === "function" ? what(obj[key], key) : what, | ||
_a)); | ||
return __assign(__assign({}, obj), (_a = {}, _a[key] = typeof what === "function" ? what(obj[key], key) : what, _a)); | ||
}, | ||
@@ -96,0 +94,0 @@ delete: function (obj, key) { |
@@ -10,1 +10,3 @@ export * from "./error"; | ||
export * from "./redux"; | ||
export * from "./data-adapter"; | ||
export * from "./lens"; |
@@ -22,1 +22,3 @@ "use strict"; | ||
__exportStar(require("./redux"), exports); | ||
__exportStar(require("./data-adapter"), exports); | ||
__exportStar(require("./lens"), exports); |
@@ -1,2 +0,2 @@ | ||
import { StrKeyOf, DeepReadonly } from "./types"; | ||
import { StrKeyOf, DeepReadonly, DeepPartial } from "./types"; | ||
export declare const noop: () => void; | ||
@@ -6,2 +6,3 @@ export declare const id: <T>(x: T) => T; | ||
export declare const arraysEqual: <T>(a: readonly T[], b: readonly T[]) => boolean; | ||
export declare const shallowEqual: (a: object, b: object) => boolean; | ||
export declare function objectFrom<V, K extends keyof any = keyof any>(entries: Iterable<[K, V]>): Record<K, V>; | ||
@@ -26,5 +27,12 @@ declare type ValueMapper<T, R = any> = (v: T[StrKeyOf<T>], k: StrKeyOf<T>, src: T) => R; | ||
export declare const merge: Merge; | ||
declare type MergeDeep = { | ||
<T>(a: T, b: DeepPartial<T>): T; | ||
<T, P = DeepPartial<T>>(b: P): (a: T) => T; | ||
}; | ||
export declare const mergeDeep: MergeDeep; | ||
export declare const join: <A extends string, B extends string, S extends string>(a: A, sep: S, b: B) => `${A}${S}${B}`; | ||
export declare const namespace: <S extends string>(s: S) => <SS extends string>(suffix: SS) => `${S}/${SS}`; | ||
export declare function assert(condition: any, msg?: string): asserts condition; | ||
export declare const isPlainObject: (x: any) => x is object; | ||
export declare function flatMap<T, R>(src: ReadonlyArray<T>, fn: (item: T, index: number) => ReadonlyArray<R>): R[]; | ||
export {}; |
@@ -23,3 +23,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assert = exports.namespace = exports.join = exports.merge = exports.deepReadonly = exports.call = exports.createFactoryAs = exports.createFactory = exports.getter = exports.objectTransform = exports.objectMap = exports.objectFrom = exports.arraysEqual = exports.range = exports.id = exports.noop = void 0; | ||
exports.flatMap = exports.isPlainObject = exports.assert = exports.namespace = exports.join = exports.mergeDeep = exports.merge = exports.deepReadonly = exports.call = exports.createFactoryAs = exports.createFactory = exports.getter = exports.objectTransform = exports.objectMap = exports.objectFrom = exports.shallowEqual = exports.arraysEqual = exports.range = exports.id = exports.noop = void 0; | ||
var noop = function () { }; | ||
@@ -38,2 +38,8 @@ exports.noop = noop; | ||
exports.arraysEqual = arraysEqual; | ||
var shallowEqual = function (a, b) { | ||
var ka = Object.keys(a); | ||
var kb = Object.keys(b); | ||
return ka.length === kb.length && ka.every(function (k) { return a[k] === b[k]; }); | ||
}; | ||
exports.shallowEqual = shallowEqual; | ||
function objectFrom(entries) { | ||
@@ -103,2 +109,16 @@ return Array.from(entries).reduce(function (res, _a) { | ||
exports.merge = merge; | ||
var mergeDeepRec = function (a, b) { | ||
if (!(0, exports.isPlainObject)(a)) | ||
return b; | ||
var res = __assign({}, a); | ||
for (var k in b) { | ||
var v = b[k]; | ||
res[k] = mergeDeepRec(a[k], v); | ||
} | ||
return res; | ||
}; | ||
var mergeDeep = function (a, b) { | ||
return b ? mergeDeepRec(a, b) : function (b) { return mergeDeepRec(b, a); }; | ||
}; | ||
exports.mergeDeep = mergeDeep; | ||
var join = function (a, sep, b) { return (a + sep + b); }; | ||
@@ -118,1 +138,11 @@ exports.join = join; | ||
exports.assert = assert; | ||
var isPlainObject = function (x) { | ||
return !!x && typeof x === "object" && Object.getPrototypeOf(x) === Object.prototype; | ||
}; | ||
exports.isPlainObject = isPlainObject; | ||
function flatMap(src, fn) { | ||
var res = []; | ||
src.forEach(function (x, i) { return res.push.apply(res, fn(x, i)); }); | ||
return res; | ||
} | ||
exports.flatMap = flatMap; |
@@ -9,6 +9,8 @@ export declare class Tag<T> { | ||
export declare type Initializer1<A, T = A> = T extends Function ? never : T | ((arg: A) => T); | ||
export declare type ValueOrFunction<T> = T extends Function ? (value: T) => T : T | ((value: T) => T); | ||
export declare type PromiseType<T> = T | PromiseLike<T>; | ||
export declare type UnwrapPromise<T> = T extends PromiseLike<infer R> ? UnwrapPromise<R> : T; | ||
export declare type Overwrite<A, B> = Omit<A, keyof B> & B; | ||
declare type Primitive = undefined | null | boolean | string | number | Function; | ||
declare type Primitive = undefined | null | boolean | string | number | Function | Date | RegExp; | ||
declare type NotPlainObject = Primitive | ReadonlyArray<any> | ReadonlySet<any> | ReadonlyMap<any, any>; | ||
export declare type DeepReadonly<T> = T extends Primitive ? T : T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer T> ? ReadonlySet<DeepReadonly<T>> : { | ||
@@ -18,2 +20,5 @@ readonly [P in keyof T]: DeepReadonly<T[P]>; | ||
export declare type ArrayItem<T> = T extends ReadonlyArray<infer U> ? U : never; | ||
export declare type DeepPartial<T> = T extends NotPlainObject ? T : { | ||
[P in keyof T]?: T[P] extends NotPlainObject ? T[P] : DeepPartial<T[P]>; | ||
}; | ||
export {}; |
{ | ||
"name": "@dhmk/utils", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A collection of frequently used functions and primitives", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104445
58
2410