@dhmk/utils
Advanced tools
Comparing version 4.1.2 to 4.2.0
@@ -1,4 +0,4 @@ | ||
import { ValueOrFunction } from "./types"; | ||
export declare type PropType<T, Path extends string[]> = Path extends [infer K] ? K extends keyof T ? T[K] : T extends ReadonlyArray<any> ? K extends `${number}` ? T[number] : unknown : unknown : Path extends [infer K, ...infer R] ? R extends string[] ? K extends keyof T ? PropType<T[K], R> : T extends ReadonlyArray<any> ? K extends `${number}` ? PropType<T[number], R> : unknown : unknown : unknown : unknown; | ||
export declare const getIn: <T, P extends string[]>(x: T, path: [...P]) => PropType<T, P>; | ||
export declare const setIn: <T, P extends string[]>(x: T, path: [...P], v: ValueOrFunction<PropType<T, P>>) => T; | ||
export declare const getIn: <T, P extends string[]>(x: T, path: readonly [...P]) => PropType<T, P>; | ||
export declare const updateIn: <T, P extends string[]>(x: T, path: readonly [...P], updater: (value: PropType<T, P>) => PropType<T, P>) => T; | ||
export declare const setIn: <T, P extends string[]>(x: T, path: readonly [...P], v: PropType<T, P>) => T; |
@@ -13,8 +13,8 @@ var __assign = (this && this.__assign) || function () { | ||
export var getIn = function (x, path) { return path.reduce(function (src, k) { return src[k]; }, x); }; | ||
export var setIn = function (x, path, v) { | ||
export var updateIn = function (x, path, updater) { | ||
if (path.length === 0) { | ||
return typeof v === "function" ? v(x) : v; | ||
return updater(x); | ||
} | ||
var k = path[0], rest = path.slice(1); | ||
var value = setIn(x[k], rest, v); | ||
var value = updateIn(x[k], rest, updater); | ||
return Array.isArray(x) | ||
@@ -24,2 +24,3 @@ ? arraySet(x, Number(k), value) | ||
}; | ||
export var setIn = function (x, path, v) { return updateIn(x, path, function () { return v; }); }; | ||
var arraySet = function (x, k, v) { return x.map(function (_v, i) { return (i === k ? v : _v); }); }; | ||
@@ -26,0 +27,0 @@ var objectSet = function (x, k, v) { |
@@ -1,4 +0,4 @@ | ||
import { ValueOrFunction } from "./types"; | ||
export declare type PropType<T, Path extends string[]> = Path extends [infer K] ? K extends keyof T ? T[K] : T extends ReadonlyArray<any> ? K extends `${number}` ? T[number] : unknown : unknown : Path extends [infer K, ...infer R] ? R extends string[] ? K extends keyof T ? PropType<T[K], R> : T extends ReadonlyArray<any> ? K extends `${number}` ? PropType<T[number], R> : unknown : unknown : unknown : unknown; | ||
export declare const getIn: <T, P extends string[]>(x: T, path: [...P]) => PropType<T, P>; | ||
export declare const setIn: <T, P extends string[]>(x: T, path: [...P], v: ValueOrFunction<PropType<T, P>>) => T; | ||
export declare const getIn: <T, P extends string[]>(x: T, path: readonly [...P]) => PropType<T, P>; | ||
export declare const updateIn: <T, P extends string[]>(x: T, path: readonly [...P], updater: (value: PropType<T, P>) => PropType<T, P>) => T; | ||
export declare const setIn: <T, P extends string[]>(x: T, path: readonly [...P], v: PropType<T, P>) => T; |
@@ -14,11 +14,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setIn = exports.getIn = void 0; | ||
exports.setIn = exports.updateIn = exports.getIn = void 0; | ||
var getIn = function (x, path) { return path.reduce(function (src, k) { return src[k]; }, x); }; | ||
exports.getIn = getIn; | ||
var setIn = function (x, path, v) { | ||
var updateIn = function (x, path, updater) { | ||
if (path.length === 0) { | ||
return typeof v === "function" ? v(x) : v; | ||
return updater(x); | ||
} | ||
var k = path[0], rest = path.slice(1); | ||
var value = (0, exports.setIn)(x[k], rest, v); | ||
var value = (0, exports.updateIn)(x[k], rest, updater); | ||
return Array.isArray(x) | ||
@@ -28,2 +28,4 @@ ? arraySet(x, Number(k), value) | ||
}; | ||
exports.updateIn = updateIn; | ||
var setIn = function (x, path, v) { return (0, exports.updateIn)(x, path, function () { return v; }); }; | ||
exports.setIn = setIn; | ||
@@ -30,0 +32,0 @@ var arraySet = function (x, k, v) { return x.map(function (_v, i) { return (i === k ? v : _v); }); }; |
{ | ||
"name": "@dhmk/utils", | ||
"version": "4.1.2", | ||
"version": "4.2.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
120580
2781