Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1 to 3.0.2

12

dist/map.d.ts

@@ -1,8 +0,4 @@

declare class Wrapper {
static map<T extends ReadonlyArray<any>, K extends number, U>(input: T, fn: (obj: Readonly<T[K]>, key: number) => U): Array<U>;
static map<T extends Readonly<any>, K extends keyof T, U>(input: T, fn: (obj: Readonly<T[K]>, key: string) => U): {
[key in K]: U;
};
}
export declare const map: typeof Wrapper.map;
export {};
export declare function map<T extends ReadonlyArray<any>, K extends number, U>(input: T, fn: (obj: Readonly<T[K]>, key: number) => U): Array<U>;
export declare function map<T extends Readonly<any>, K extends keyof T, U>(input: T, fn: (obj: Readonly<T[K]>, key: string) => U): {
[key in K]: U;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var set_1 = require("./set");
var Wrapper = /** @class */ (function () {
function Wrapper() {
function map(input, fn) {
var result = input;
for (var key in input) {
result = set_1.set(result, key, fn(input[key], key));
}
Wrapper.map = function (input, fn) {
var result = input;
for (var key in input) {
result = set_1.set(result, key, fn(input[key], key));
}
return result;
};
return Wrapper;
}());
exports.map = Wrapper.map;
return result;
}
exports.map = map;
//# sourceMappingURL=map.js.map

@@ -1,1 +0,2 @@

export declare const mergeDeep: (input: any, changes: any) => any;
import { Merge } from 'type-fest';
export declare function mergeDeep<InputType, ChangesType>(input: InputType, changes: ChangesType): Merge<InputType, ChangesType>;

@@ -7,3 +7,3 @@ "use strict";

};
exports.mergeDeep = function (input, changes) {
function mergeDeep(input, changes) {
var result = input;

@@ -13,3 +13,3 @@ for (var key in changes) {

var newChild = isObject(childChange)
? exports.mergeDeep(input[key] || {}, childChange)
? mergeDeep(input[key] || {}, childChange)
: childChange;

@@ -19,3 +19,5 @@ result = set_1.set(result, key, newChild);

return result;
};
}
exports.mergeDeep = mergeDeep;
;
//# sourceMappingURL=merge-deep.js.map
import { Merge } from 'type-fest';
declare type ArgType = Record<keyof any, any>;
declare type _Merge<T, U> = T extends Merge<T, U> ? T : Merge<T, U>;
declare class Wrapper {
static merge<T>(input: Readonly<T>): T;
static merge<T, U extends ArgType>(input: Readonly<T>, arg: Readonly<U>): _Merge<T, U>;
static merge<T, U extends ArgType, V extends ArgType>(input: Readonly<T>, args1: Readonly<U>, args2: Readonly<V>): _Merge<_Merge<T, U>, V>;
static merge<T, U extends ArgType, V extends ArgType, W extends ArgType>(input: Readonly<T>, args1: Readonly<U>, args2: Readonly<V>, args3: Readonly<W>): _Merge<_Merge<_Merge<T, U>, V>, W>;
static merge(input: any, ...args: any[]): any;
}
export declare const merge: typeof Wrapper.merge;
export declare function merge<T>(input: Readonly<T>): T;
export declare function merge<T, U extends ArgType>(input: Readonly<T>, arg: Readonly<U>): _Merge<T, U>;
export declare function merge<T, U extends ArgType, V extends ArgType>(input: Readonly<T>, args1: Readonly<U>, args2: Readonly<V>): _Merge<_Merge<T, U>, V>;
export declare function merge<T, U extends ArgType, V extends ArgType, W extends ArgType>(input: Readonly<T>, args1: Readonly<U>, args2: Readonly<V>, args3: Readonly<W>): _Merge<_Merge<_Merge<T, U>, V>, W>;
export declare function merge(input: any, ...args: any[]): any;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var set_1 = require("./set");
var Wrapper = /** @class */ (function () {
function Wrapper() {
function merge(input) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
Wrapper.merge = function (input) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
var changes = {};
args.forEach(function (obj) {
for (var key in obj) {
changes[key] = obj[key];
}
var changes = {};
args.forEach(function (obj) {
for (var key in obj) {
changes[key] = obj[key];
}
});
var result = input;
for (var key in changes) {
result = set_1.set(result, key, changes[key]);
}
return result;
};
return Wrapper;
}());
exports.merge = Wrapper.merge;
});
var result = input;
for (var key in changes) {
result = set_1.set(result, key, changes[key]);
}
return result;
}
exports.merge = merge;
//# sourceMappingURL=merge.js.map
import { set } from './set';
class Wrapper {
static map<T extends ReadonlyArray<any>, K extends number, U>(
input: T,
fn: (obj: Readonly<T[K]>, key: number) => U,
): Array<U>;
static map<T extends Readonly<any>, K extends keyof T, U>(
input: T,
fn: (obj: Readonly<T[K]>, key: string) => U,
): { [key in K]: U };
static map(input: any, fn: any) {
let result: any = input;
for (const key in input) {
result = set(result, key, fn(input[key], key));
}
return result;
export function map<T extends ReadonlyArray<any>, K extends number, U>(
input: T,
fn: (obj: Readonly<T[K]>, key: number) => U,
): Array<U>;
export function map<T extends Readonly<any>, K extends keyof T, U>(
input: T,
fn: (obj: Readonly<T[K]>, key: string) => U,
): { [key in K]: U };
export function map(input: any, fn: any) {
let result: any = input;
for (const key in input) {
result = set(result, key, fn(input[key], key));
}
return result;
}
export const map = Wrapper.map;
import { set } from './set';
import { Merge } from 'type-fest';

@@ -6,3 +7,9 @@ const isObject = (obj: unknown) =>

export const mergeDeep = (input: any, changes: any): any => {
export function mergeDeep <InputType, ChangesType>(
input: InputType,
changes: ChangesType,
): Merge<InputType, ChangesType>
export function mergeDeep(input: any, changes: any) {
let result = input;

@@ -9,0 +16,0 @@

@@ -9,38 +9,39 @@ import { Merge } from 'type-fest';

class Wrapper {
static merge<T>(input: Readonly<T>): T;
static merge<T, U extends ArgType>(
input: Readonly<T>,
arg: Readonly<U>,
): _Merge<T, U>;
static merge<T, U extends ArgType, V extends ArgType>(
input: Readonly<T>,
args1: Readonly<U>,
args2: Readonly<V>,
): _Merge<_Merge<T, U>, V>;
static merge<T, U extends ArgType, V extends ArgType, W extends ArgType>(
input: Readonly<T>,
args1: Readonly<U>,
args2: Readonly<V>,
args3: Readonly<W>,
): _Merge<_Merge<_Merge<T, U>, V>, W>;
static merge(input: any, ...args: any[]): any;
static merge(input: any, ...args: any[]) {
const changes: any = {};
args.forEach((obj) => {
for (const key in obj) {
changes[key] = obj[key];
}
});
export function merge<T>(input: Readonly<T>): T;
export function merge<T, U extends ArgType>(
input: Readonly<T>,
arg: Readonly<U>,
): _Merge<T, U>;
export function merge<T, U extends ArgType, V extends ArgType>(
input: Readonly<T>,
args1: Readonly<U>,
args2: Readonly<V>,
): _Merge<_Merge<T, U>, V>;
export function merge<
T,
U extends ArgType,
V extends ArgType,
W extends ArgType
>(
input: Readonly<T>,
args1: Readonly<U>,
args2: Readonly<V>,
args3: Readonly<W>,
): _Merge<_Merge<_Merge<T, U>, V>, W>;
export function merge(input: any, ...args: any[]): any;
export function merge(input: any, ...args: any[]) {
const changes: any = {};
args.forEach((obj) => {
for (const key in obj) {
changes[key] = obj[key];
}
});
let result: any = input;
let result: any = input;
for (const key in changes) {
result = set(result, key, changes[key]);
}
for (const key in changes) {
result = set(result, key, changes[key]);
}
return result;
}
return result;
}
export const { merge } = Wrapper;

@@ -18,3 +18,3 @@ import { Merge } from 'type-fest';

Object.keys(input).forEach((inputKey) => {
Object.keys(input).forEach((inputKey) => {
result[inputKey] = inputKey === key ? value : input[inputKey];

@@ -21,0 +21,0 @@ });

{
"name": "immutable-object-methods",
"version": "3.0.1",
"version": "3.0.2",
"description": "Update normal plain javascript object, immutable style. Simlar to how immutable.js, seamless-immutable etc does it but a lot smaller and simpler.",

@@ -16,3 +16,3 @@ "main": "dist/index.js",

},
"author": "mic.com",
"author": "pizza-skull",
"license": "MIT",

@@ -24,12 +24,11 @@ "bugs": {

"devDependencies": {
"ava": "^1.4.1",
"ava": "^3.7.1",
"package-json-to-readme": "^2.1.1",
"prettier": "^1.17.0",
"prettier": "^2.0.4",
"ts-node": "^8.1.0",
"type-fest": "^0.4.1",
"typescript": "^3.4.5"
"type-fest": "^0.13.1",
"typescript": "^3.8.3"
},
"dependencies": {},
"ava": {
"compileEnhancements": false,
"extensions": [

@@ -36,0 +35,0 @@ "ts"

@@ -105,5 +105,5 @@ import test from 'ava';

test('merge w array', (t) => {
const input = [0,,,4];
const input = [0, , , 4];
const actual = merge(input, [1, 2, 3]);
const expected = [1, 2, 3,4];
const expected = [1, 2, 3, 4];
t.deepEqual(actual, expected);

@@ -251,2 +251,3 @@ t.true(Array.isArray(actual));

const actual = mergeDeep(input, changes);
const expected = {

@@ -365,6 +366,6 @@ a: {

test('map array', (t) => {
const input = [1,2,3,4]
const actual = map(input, num => num % 2);
const expected = [1,0,1,0];
t.deepEqual(actual, expected)
})
const input = [1, 2, 3, 4];
const actual = map(input, (num) => num % 2);
const expected = [1, 0, 1, 0];
t.deepEqual(actual, expected);
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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