@tsfun/object
Advanced tools
+31
-22
@@ -1,2 +0,3 @@ | ||
| import { SimpleDeepMerge } from './utils/types'; | ||
| import { DeepPartialNonArray as DeepPartial, SimpleDeepMerge as DeepMergeWithoutCollision } from './utils/types'; | ||
| export { DeepPartial, DeepMergeWithoutCollision }; | ||
| /** | ||
@@ -11,2 +12,31 @@ * Merge two objects of the same interface | ||
| /** | ||
| * Merge two objects of the same interface | ||
| * | ||
| * `left` is prioritized for overlapping non-object properties | ||
| * | ||
| * @param left Object or value to merge | ||
| * @param right Object or value to merge | ||
| * @returns Result of the merge | ||
| */ | ||
| export declare function deepMergeOverwrite<Value>(left: Value, right: Value): Value; | ||
| /** | ||
| * Merge an object and a partial object of the same interface | ||
| * @param left Object to merge | ||
| * @param right Partial object to merge | ||
| * @param resolveConflict Function that resolves property conflict | ||
| * @returns Result of the merge | ||
| */ | ||
| export declare function deepMergePartial<Object>(left: Object, right: DeepPartial<Object>, resolveConflict: PropertyConflictResolver): Object; | ||
| /** | ||
| * Merge two objects | ||
| * | ||
| * The two objects are expected to not have overlapping non-object properties | ||
| * | ||
| * @param left Object to merge | ||
| * @param right Object to merge | ||
| * @param onerror Function to handle should error occurs | ||
| * @returns A merged object of `a` and `b` | ||
| */ | ||
| export declare function deepMergeWithoutCollision<Left extends object, Right extends object>(left: Left, right: Right, onerror?: ErrorProcessor): DeepMergeWithoutCollision<Left, Right>; | ||
| /** | ||
| * Decides which property should make it to the merged object | ||
@@ -35,23 +65,2 @@ */ | ||
| /** | ||
| * Merge two objects of the same interface | ||
| * | ||
| * `left` is prioritized for overlapping non-object properties | ||
| * | ||
| * @param left Object or value to merge | ||
| * @param right Object or value to merge | ||
| * @returns Result of the merge | ||
| */ | ||
| export declare function deepMergeOverwrite<Value>(left: Value, right: Value): Value; | ||
| /** | ||
| * Merge two objects | ||
| * | ||
| * The two objects are expected to not have overlapping non-object properties | ||
| * | ||
| * @param left Object to merge | ||
| * @param right Object to merge | ||
| * @param onerror Function to handle should error occurs | ||
| * @returns A merged object of `a` and `b` | ||
| */ | ||
| export declare function deepMergeWithoutCollision<Left extends object, Right extends object>(left: Left, right: Right, onerror?: ErrorProcessor): SimpleDeepMerge<Left, Right>; | ||
| /** | ||
| * Process and transform errors of `deepMergeWithoutCollision` | ||
@@ -58,0 +67,0 @@ */ |
+29
-18
@@ -34,17 +34,2 @@ "use strict"; | ||
| /** | ||
| * Choice to be made | ||
| */ | ||
| var PropertyPreference; | ||
| (function (PropertyPreference) { | ||
| /** | ||
| * Choose the left value (`values[0]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Left"] = 0] = "Left"; | ||
| /** | ||
| * Choose the right value (`values[1]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Right"] = 1] = "Right"; | ||
| })(PropertyPreference = exports.PropertyPreference || (exports.PropertyPreference = {})); | ||
| const PREFER_RIGHT = () => 1 /* Right */; | ||
| /** | ||
| * Merge two objects of the same interface | ||
@@ -62,6 +47,15 @@ * | ||
| exports.deepMergeOverwrite = deepMergeOverwrite; | ||
| const DMWOC_DEF_ERR_HDLR = param => { | ||
| throw Object.assign(new TypeError(`Property collision`), param); | ||
| }; | ||
| const PREFER_RIGHT = () => 1 /* Right */; | ||
| /** | ||
| * Merge an object and a partial object of the same interface | ||
| * @param left Object to merge | ||
| * @param right Partial object to merge | ||
| * @param resolveConflict Function that resolves property conflict | ||
| * @returns Result of the merge | ||
| */ | ||
| function deepMergePartial(left, right, resolveConflict) { | ||
| return deepMergeWithPreference(left, right, values => values[1] === undefined ? 0 /* Left */ : resolveConflict(values)); | ||
| } | ||
| exports.deepMergePartial = deepMergePartial; | ||
| /** | ||
| * Merge two objects | ||
@@ -105,3 +99,20 @@ * | ||
| exports.deepMergeWithoutCollision = deepMergeWithoutCollision; | ||
| const DMWOC_DEF_ERR_HDLR = param => { | ||
| throw Object.assign(new TypeError(`Property collision`), param); | ||
| }; | ||
| /** | ||
| * Choice to be made | ||
| */ | ||
| var PropertyPreference; | ||
| (function (PropertyPreference) { | ||
| /** | ||
| * Choose the left value (`values[0]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Left"] = 0] = "Left"; | ||
| /** | ||
| * Choose the right value (`values[1]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Right"] = 1] = "Right"; | ||
| })(PropertyPreference = exports.PropertyPreference || (exports.PropertyPreference = {})); | ||
| /** | ||
| * Code of errors that `deepMergeWithoutCollision may cause | ||
@@ -108,0 +119,0 @@ */ |
+40
-26
@@ -35,23 +35,2 @@ const isObject = value => value && typeof value === 'object' && !Array.isArray(value); | ||
| /** | ||
| * Choice to be made | ||
| */ | ||
| export var PropertyPreference; | ||
| (function (PropertyPreference) { | ||
| /** | ||
| * Choose the left value (`values[0]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Left"] = 0] = "Left"; | ||
| /** | ||
| * Choose the right value (`values[1]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Right"] = 1] = "Right"; | ||
| })(PropertyPreference || (PropertyPreference = {})); | ||
| const PREFER_RIGHT = () => 1 | ||
| /* Right */ | ||
| ; | ||
| /** | ||
| * Merge two objects of the same interface | ||
@@ -66,3 +45,2 @@ * | ||
| export function deepMergeOverwrite(left, right) { | ||
@@ -72,6 +50,20 @@ return deepMergeWithPreference(left, right, PREFER_RIGHT); | ||
| const DMWOC_DEF_ERR_HDLR = param => { | ||
| throw Object.assign(new TypeError(`Property collision`), param); | ||
| }; | ||
| const PREFER_RIGHT = () => 1 | ||
| /* Right */ | ||
| ; | ||
| /** | ||
| * Merge an object and a partial object of the same interface | ||
| * @param left Object to merge | ||
| * @param right Partial object to merge | ||
| * @param resolveConflict Function that resolves property conflict | ||
| * @returns Result of the merge | ||
| */ | ||
| export function deepMergePartial(left, right, resolveConflict) { | ||
| return deepMergeWithPreference(left, right, values => values[1] === undefined ? 0 | ||
| /* Left */ | ||
| : resolveConflict(values)); | ||
| } | ||
| /** | ||
| * Merge two objects | ||
@@ -87,3 +79,2 @@ * | ||
| export function deepMergeWithoutCollision(left, right, onerror = DMWOC_DEF_ERR_HDLR) { | ||
@@ -120,6 +111,29 @@ const result = {}; | ||
| } | ||
| const DMWOC_DEF_ERR_HDLR = param => { | ||
| throw Object.assign(new TypeError(`Property collision`), param); | ||
| }; | ||
| /** | ||
| * Choice to be made | ||
| */ | ||
| export var PropertyPreference; | ||
| (function (PropertyPreference) { | ||
| /** | ||
| * Choose the left value (`values[0]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Left"] = 0] = "Left"; | ||
| /** | ||
| * Choose the right value (`values[1]`) | ||
| */ | ||
| PropertyPreference[PropertyPreference["Right"] = 1] = "Right"; | ||
| })(PropertyPreference || (PropertyPreference = {})); | ||
| /** | ||
| * Code of errors that `deepMergeWithoutCollision may cause | ||
| */ | ||
| export var ErrorType; | ||
@@ -126,0 +140,0 @@ |
+31
-22
@@ -1,2 +0,3 @@ | ||
| import { SimpleDeepMerge } from './utils/types'; | ||
| import { DeepPartialNonArray as DeepPartial, SimpleDeepMerge as DeepMergeWithoutCollision } from './utils/types'; | ||
| export { DeepPartial, DeepMergeWithoutCollision }; | ||
| /** | ||
@@ -11,2 +12,31 @@ * Merge two objects of the same interface | ||
| /** | ||
| * Merge two objects of the same interface | ||
| * | ||
| * `left` is prioritized for overlapping non-object properties | ||
| * | ||
| * @param left Object or value to merge | ||
| * @param right Object or value to merge | ||
| * @returns Result of the merge | ||
| */ | ||
| export declare function deepMergeOverwrite<Value>(left: Value, right: Value): Value; | ||
| /** | ||
| * Merge an object and a partial object of the same interface | ||
| * @param left Object to merge | ||
| * @param right Partial object to merge | ||
| * @param resolveConflict Function that resolves property conflict | ||
| * @returns Result of the merge | ||
| */ | ||
| export declare function deepMergePartial<Object>(left: Object, right: DeepPartial<Object>, resolveConflict: PropertyConflictResolver): Object; | ||
| /** | ||
| * Merge two objects | ||
| * | ||
| * The two objects are expected to not have overlapping non-object properties | ||
| * | ||
| * @param left Object to merge | ||
| * @param right Object to merge | ||
| * @param onerror Function to handle should error occurs | ||
| * @returns A merged object of `a` and `b` | ||
| */ | ||
| export declare function deepMergeWithoutCollision<Left extends object, Right extends object>(left: Left, right: Right, onerror?: ErrorProcessor): DeepMergeWithoutCollision<Left, Right>; | ||
| /** | ||
| * Decides which property should make it to the merged object | ||
@@ -35,23 +65,2 @@ */ | ||
| /** | ||
| * Merge two objects of the same interface | ||
| * | ||
| * `left` is prioritized for overlapping non-object properties | ||
| * | ||
| * @param left Object or value to merge | ||
| * @param right Object or value to merge | ||
| * @returns Result of the merge | ||
| */ | ||
| export declare function deepMergeOverwrite<Value>(left: Value, right: Value): Value; | ||
| /** | ||
| * Merge two objects | ||
| * | ||
| * The two objects are expected to not have overlapping non-object properties | ||
| * | ||
| * @param left Object to merge | ||
| * @param right Object to merge | ||
| * @param onerror Function to handle should error occurs | ||
| * @returns A merged object of `a` and `b` | ||
| */ | ||
| export declare function deepMergeWithoutCollision<Left extends object, Right extends object>(left: Left, right: Right, onerror?: ErrorProcessor): SimpleDeepMerge<Left, Right>; | ||
| /** | ||
| * Process and transform errors of `deepMergeWithoutCollision` | ||
@@ -58,0 +67,0 @@ */ |
+1
-1
| { | ||
| "name": "@tsfun/object", | ||
| "version": "0.0.13", | ||
| "version": "0.0.14", | ||
| "description": "Utilities related to objects", | ||
@@ -5,0 +5,0 @@ "author": "Hoàng Văn Khải <hvksmr1996@gmail.com>", |
+6
-0
@@ -23,2 +23,8 @@ import { Assign } from 'utility-types'; | ||
| /** | ||
| * Make all properties in a dict optional | ||
| */ | ||
| export declare type DeepPartialNonArray<Object> = Object extends readonly any[] ? Object | undefined : Object extends object ? { | ||
| [Key in keyof Object]?: DeepPartialNonArray<Object[Key]>; | ||
| } : Object | undefined; | ||
| /** | ||
| * Return type of `objectExtends` | ||
@@ -25,0 +31,0 @@ */ |
@@ -23,2 +23,8 @@ import { Assign } from 'utility-types'; | ||
| /** | ||
| * Make all properties in a dict optional | ||
| */ | ||
| export declare type DeepPartialNonArray<Object> = Object extends readonly any[] ? Object | undefined : Object extends object ? { | ||
| [Key in keyof Object]?: DeepPartialNonArray<Object[Key]>; | ||
| } : Object | undefined; | ||
| /** | ||
| * Return type of `objectExtends` | ||
@@ -25,0 +31,0 @@ */ |
50354
5.12%1264
4.38%