immutable-object-methods
Advanced tools
Comparing version 3.0.2 to 3.0.3
import { Merge } from 'type-fest'; | ||
export declare const set: <T extends Record<string | number | symbol | K, any>, K extends string | number | symbol, V>(input: Readonly<T>, key: K, value: V) => Merge<T, { [key in K]: V; }>; | ||
export declare function set<T>(input: readonly T[], key: number, value: T): readonly T[]; | ||
export declare function set<T extends Record<keyof any | K, any>, K extends Readonly<keyof any>, V>(input: Readonly<T>, key: K, value: V): Merge<T, { | ||
[key in K]: V; | ||
}>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.set = function (input, key, value) { | ||
function set(input, key, value) { | ||
if (input[key] === value) { | ||
@@ -13,3 +13,5 @@ return input; | ||
return result; | ||
}; | ||
} | ||
exports.set = set; | ||
; | ||
//# sourceMappingURL=set.js.map |
import { Merge } from 'type-fest'; | ||
export const set = < | ||
export function set<T>(input: readonly T[], key: number, value: T): readonly T[] | ||
export function set < | ||
T extends Record<keyof any | K, any>, | ||
@@ -11,3 +12,12 @@ K extends Readonly<keyof any>, | ||
value: V, | ||
): Merge<T, { [key in K]: V }> => { | ||
): Merge<T, { [key in K]: V }> | ||
export function set < | ||
T extends Record<keyof any | K, any>, | ||
K extends Readonly<keyof any>, | ||
V | ||
>( | ||
input: Readonly<T>, | ||
key: K, | ||
value: V, | ||
): Merge<T, { [key in K]: V }> { | ||
if (input[key] === value) { | ||
@@ -14,0 +24,0 @@ return input; |
{ | ||
"name": "immutable-object-methods", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Update normal plain javascript object, immutable style. Simlar to how immutable.js, seamless-immutable etc does it but a lot smaller and simpler.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
16
test.ts
@@ -21,2 +21,18 @@ import test from 'ava'; | ||
test('set with array', (t) => { | ||
const input = Object.freeze([] as (string|number)[]); | ||
const actual = set(input, 0, 'hello'); | ||
const expected = ['hello']; | ||
t.true(Array.isArray(input)) | ||
t.true(Array.isArray(actual)) | ||
t.deepEqual(actual, expected); | ||
}) | ||
test('set with unchanged array', (t) => { | ||
const input = Object.freeze(['hello'] as (string|number)[]); | ||
const actual = set(input, 0, 'hello'); | ||
const expected = input | ||
t.is(actual, expected); | ||
}) | ||
test('setIn', (t) => { | ||
@@ -23,0 +39,0 @@ const input = Object.freeze({}); |
Sorry, the diff of this file is not supported yet
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
30135
690