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

@canvas-js/utils

Package Overview
Dependencies
Maintainers
0
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@canvas-js/utils - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

lib/filterMapEntries.d.ts

1

lib/index.d.ts

@@ -6,2 +6,3 @@ export * from "./assert.js";

export * from "./mapEntries.js";
export * from "./filterMapEntries.js";
export * from "./mapKeys.js";

@@ -8,0 +9,0 @@ export * from "./mapValues.js";

@@ -6,2 +6,3 @@ export * from "./assert.js";

export * from "./mapEntries.js";
export * from "./filterMapEntries.js";
export * from "./mapKeys.js";

@@ -8,0 +9,0 @@ export * from "./mapValues.js";

2

lib/mapValuesAsync.d.ts

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

export declare const mapValuesAsync: <K extends string, S, T>(object: Record<K, S>, map: (value: S) => Promise<T>) => Promise<any>;
export declare const mapValuesAsync: <K extends string, S, T>(object: Record<K, S>, map: (value: S) => Promise<T>) => Promise<Record<string, T>>;
import { zip } from "./zip.js";
export const mapValuesAsync = async (object, map) => {
const values = await Promise.all(Object.values(object).map((value) => map(value)));
return Object.fromEntries(zip(Object.keys(object), values));
const result = {};
for (const [k, v] of zip(Object.keys(object), values)) {
result[k] = v;
}
return result;
};

@@ -0,1 +1,7 @@

export type JSONValue = null | boolean | number | string | JSONArray | JSONObject;
export interface JSONArray extends Array<JSONValue> {
}
export interface JSONObject {
[key: string]: JSONValue;
}
export type JSValue = null | boolean | number | string | Uint8Array | JSArray | JSObject;

@@ -10,1 +16,4 @@ export interface JSArray extends Array<JSValue> {

export declare function typeOf(value: JSValue): "null" | "boolean" | "number" | "string" | "Uint8Array" | "Array" | "Object";
export declare function isObject(value: JSValue): value is JSObject;
export declare function merge(from: JSValue | undefined, into: JSValue | undefined): JSValue | undefined;
export declare function update(from: JSValue | undefined, into: JSValue | undefined): JSValue | undefined;

@@ -26,1 +26,99 @@ // Values

}
export function isObject(value) {
return typeOf(value) === "Object";
}
export function merge(from, into) {
if (from === null) {
return from;
}
else if (from === undefined) {
return into;
}
else if (typeof from === "boolean") {
return from;
}
else if (typeof from === "number") {
return from;
}
else if (typeof from === "string") {
return from;
}
else if (from instanceof Uint8Array) {
return from;
}
else if (Array.isArray(from)) {
return from;
}
else {
// only merge objects
if (into === undefined)
return from;
if (!isObject(from))
return from;
if (!isObject(into))
return from;
const mergedKeys = Array.from(new Set([...Object.keys(from), ...Object.keys(into)]));
const result = {};
for (const key of mergedKeys) {
if (from[key] === undefined) {
result[key] = into[key];
}
else if (into[key] === undefined) {
result[key] = from[key];
}
else {
const merged = merge(from[key], into[key]);
if (merged === undefined) {
continue;
}
result[key] = merged;
}
}
return result;
}
}
export function update(from, into) {
if (from === null) {
return from;
}
else if (from === undefined) {
return into;
}
else if (typeof from === "boolean") {
return from;
}
else if (typeof from === "number") {
return from;
}
else if (typeof from === "string") {
return from;
}
else if (from instanceof Uint8Array) {
return from;
}
else if (Array.isArray(from)) {
return from;
}
else {
// update fields without recursive merging
if (into === undefined)
return from;
if (!isObject(from))
return from;
if (!isObject(into))
return from;
const result = { ...into };
for (const key of Object.keys(from)) {
if (from[key] === undefined) {
result[key] = into[key];
}
else if (into[key] === undefined) {
result[key] = from[key];
}
else {
result[key] = from[key];
}
}
return result;
}
}
{
"name": "@canvas-js/utils",
"version": "0.11.0",
"version": "0.12.0",
"author": "Canvas Technologies, Inc. (https://canvas.xyz)",

@@ -19,4 +19,4 @@ "type": "module",

"dependencies": {
"@canvas-js/interfaces": "0.11.0"
"@canvas-js/interfaces": "0.12.0"
}
}
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