Socket
Socket
Sign inDemoInstall

immutable-object-methods

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-object-methods - npm Package Compare versions

Comparing version 3.0.2 to 3.0.3

5

dist/set.d.ts
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;
}>;

6

dist/set.js
"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",

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc