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

schemaglobin

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schemaglobin - npm Package Compare versions

Comparing version 5.12.1 to 5.13.0

68

dist/helpers/array.d.ts

@@ -7,32 +7,45 @@ import type { ReadonlyObject, ResolvableArray } from "../types";

* Break an array into equal sized chunks (last chunk might be smaller).
* @return New array with one or more sub-arrays.
*
* @return New array with one or more sub-arrays for each chunk.
* - The last chunk might not contain a full set of items.
*/
export declare const arrayChunk: <T extends unknown>(arr: T[], size: number) => T[][];
/**
* Toggle an item in and out of an array.
* @return New array with or without the specified item.
*/
export declare const toggleItem: <T>(arr: readonly T[], value: T) => readonly T[];
/**
* Add an item to an array.
* If the item already exists in the array (using `indexOf()`) then the item won't be added again and the exact same input array will be returned.
* - Returns an array that definitely contains the specified item.
*
* @return New array with the specified item.
* - If the item already exists in the array (using `indexOf()`) then the item won't be added again and the exact same input array will be returned.
*/
export declare const addItem: <T>(arr: readonly T[], value: T) => readonly T[];
export declare const withItem: <T>(arr: readonly T[], item: T) => readonly T[];
/**
* Remove an item from an array.
* If the item does not already exist in the array (using `indexOf()`) then the exact same input array will be returned.
* - Finds all instances of the item from the array and returns an array that definitely does not contain it.
*
* @return New array without the specified item.
* - If the item does not already exist in the array (using `indexOf()`) then the exact same input array will be returned.
*/
export declare const removeItem: <T>(arr: readonly T[], value: T) => readonly T[];
export declare const withoutItem: <T>(arr: readonly T[], item: T) => readonly T[];
/**
* Remove an item from an array.
* Toggle an item in and out of an array.
*
* @return New array with or without the specified item.
*/
export declare const replaceItem: <T>(arr: readonly T[], oldValue: T, newValue: T) => readonly T[];
/** Get the next array item in a list. */
export declare const toggleItem: <T>(arr: readonly T[], item: T) => readonly T[];
/**
* Replace all instances of an item from an array.
*
* @return New array with or without the specified item.
* - If the item does not already exist in the array (using `indexOf()`) then the exact same input array will be returned.
*/
export declare const replaceItem: <T>(arr: readonly T[], oldItem: T, newItem: T) => readonly T[];
/**
* Get the next array item in a list.
* @return The item after the specified one, or `undefined` if the specified item does not exist in the array.
*/
export declare const nextItem: <T>(arr: readonly T[], value: T) => T | undefined;
/** Get the previous array item in a list. */
/**
* Get the previous array item in a list.
* @return The item before the specified one, or `undefined` if the specified item does not exist in the array.
*/
export declare const prevItem: <T>(arr: readonly T[], value: T) => T | undefined;

@@ -42,9 +55,10 @@ /**

* - Uses Fisher Yates algorithm.
*
* @returns Copy of the input array in a random order.
*/
export declare const shuffle: <T>(input: readonly T[]) => readonly T[];
export declare const shuffle: <T>(arr: readonly T[]) => readonly T[];
/**
* Map the items in an array.
*
* @param input The input array or object to map (if an object, `Object.entries()` will be performed automatically and the second argument to `mapper()` will be the string key).
* @param arr The input array or object to map (if an object, `Object.entries()` will be performed automatically and the second argument to `mapper()` will be the string key).
*

@@ -60,12 +74,12 @@ * @param mapper Mapping function that receives the value and key and returns the corresponding value.

*/
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyArray<I>, //
export declare function mapArray<I extends unknown, O extends unknown>(arr: ReadonlyArray<I>, //
mapper: (value: I, key: number) => Promise<typeof SKIP | O>): Promise<ReadonlyArray<O>>;
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyArray<I>, //
export declare function mapArray<I extends unknown, O extends unknown>(arr: ReadonlyArray<I>, //
mapper: ((value: I, key: number) => typeof SKIP | O) | O): ReadonlyArray<O>;
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyObject<I>, mapper: (value: I, key: string) => Promise<typeof SKIP | O>): Promise<ReadonlyArray<O>>;
export declare function mapArray<I extends unknown, O extends unknown>(input: ReadonlyObject<I>, mapper: ((value: I, key: string) => typeof SKIP | O) | O): ReadonlyArray<O>;
export declare function mapArray<I extends unknown, O extends unknown>(arr: ReadonlyObject<I>, mapper: (value: I, key: string) => Promise<typeof SKIP | O>): Promise<ReadonlyArray<O>>;
export declare function mapArray<I extends unknown, O extends unknown>(arr: ReadonlyObject<I>, mapper: ((value: I, key: string) => typeof SKIP | O) | O): ReadonlyArray<O>;
/**
* Resolve the items in an array.
*
* @param input The input array.
* @param arr The input array.
* - Any values that are `Promise` instances will be awaited.

@@ -76,2 +90,12 @@ * - Any values that are the `SKIP` symbol will not be included in the output array.

*/
export declare const resolveArray: <V>(input: readonly (typeof SKIP | V | Promise<typeof SKIP | V>)[]) => Promise<V[]>;
export declare const resolveArray: <V>(arr: readonly (typeof SKIP | V | Promise<typeof SKIP | V>)[]) => Promise<V[]>;
/**
* Adds an item to an array by reference.
* - If the item already exists in the array (using `indexOf()`) then it won't be added again.
*/
export declare const addItem: <T>(arr: T[], item: T) => void;
/**
* Delete an item from an array by reference.
* - Deletes all instances of an item from an array by reference, and returns void.
*/
export declare const deleteItem: <T>(arr: T[], value: T) => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveArray = exports.mapArray = exports.shuffle = exports.prevItem = exports.nextItem = exports.replaceItem = exports.removeItem = exports.addItem = exports.toggleItem = exports.arrayChunk = exports.isArray = void 0;
exports.deleteItem = exports.addItem = exports.resolveArray = exports.mapArray = exports.shuffle = exports.prevItem = exports.nextItem = exports.replaceItem = exports.toggleItem = exports.withoutItem = exports.withItem = exports.arrayChunk = exports.isArray = void 0;
const constants_1 = require("../constants");

@@ -10,3 +10,5 @@ /** Is a value an array? */

* Break an array into equal sized chunks (last chunk might be smaller).
* @return New array with one or more sub-arrays.
*
* @return New array with one or more sub-arrays for each chunk.
* - The last chunk might not contain a full set of items.
*/

@@ -21,42 +23,64 @@ const arrayChunk = (arr, size) => {

/**
* Toggle an item in and out of an array.
* @return New array with or without the specified item.
*/
const toggleItem = (arr, value) => {
const i = arr.indexOf(value);
return i >= 0 ? [...arr.slice(0, i), ...arr.slice(i + 1)] : [...arr, value];
};
exports.toggleItem = toggleItem;
/**
* Add an item to an array.
* If the item already exists in the array (using `indexOf()`) then the item won't be added again and the exact same input array will be returned.
* - Returns an array that definitely contains the specified item.
*
* @return New array with the specified item.
* - If the item already exists in the array (using `indexOf()`) then the item won't be added again and the exact same input array will be returned.
*/
const addItem = (arr, value) => {
const i = arr.indexOf(value);
return i >= 0 ? arr : [...arr, value];
const withItem = (arr, item) => {
const i = arr.indexOf(item);
return i >= 0 ? arr : [...arr, item];
};
exports.addItem = addItem;
exports.withItem = withItem;
/**
* Remove an item from an array.
* If the item does not already exist in the array (using `indexOf()`) then the exact same input array will be returned.
* - Finds all instances of the item from the array and returns an array that definitely does not contain it.
*
* @return New array without the specified item.
* - If the item does not already exist in the array (using `indexOf()`) then the exact same input array will be returned.
*/
const removeItem = (arr, value) => {
const i = arr.indexOf(value);
return i >= 0 ? [...arr.slice(0, i), ...arr.slice(i + 1)] : arr;
const withoutItem = (arr, item) => {
let i = arr.indexOf(item);
if (i < 0)
return arr;
const output = arr.slice();
while (i >= 0) {
output.splice(i, 1);
i = output.indexOf(item, i);
}
return output;
};
exports.removeItem = removeItem;
exports.withoutItem = withoutItem;
/**
* Remove an item from an array.
* Toggle an item in and out of an array.
*
* @return New array with or without the specified item.
*/
const replaceItem = (arr, oldValue, newValue) => {
const i = arr.indexOf(oldValue);
return i >= 0 ? [...arr.slice(0, i), newValue, ...arr.slice(i + 1)] : arr;
const toggleItem = (arr, item) => {
const i = arr.indexOf(item);
return i >= 0 ? exports.withoutItem(arr, item) : [...arr, item];
};
exports.toggleItem = toggleItem;
/**
* Replace all instances of an item from an array.
*
* @return New array with or without the specified item.
* - If the item does not already exist in the array (using `indexOf()`) then the exact same input array will be returned.
*/
const replaceItem = (arr, oldItem, newItem) => {
let i = arr.indexOf(oldItem);
if (i < 0)
return arr;
const output = arr.slice();
while (i >= 0) {
output[i] = newItem;
i = output.indexOf(newItem, i + 1);
}
return output;
};
exports.replaceItem = replaceItem;
/** Get the next array item in a list. */
/**
* Get the next array item in a list.
* @return The item after the specified one, or `undefined` if the specified item does not exist in the array.
*/
const nextItem = (arr, value) => {

@@ -69,3 +93,6 @@ const i = arr.indexOf(value);

exports.nextItem = nextItem;
/** Get the previous array item in a list. */
/**
* Get the previous array item in a list.
* @return The item before the specified one, or `undefined` if the specified item does not exist in the array.
*/
const prevItem = (arr, value) => {

@@ -81,18 +108,19 @@ const i = arr.indexOf(value);

* - Uses Fisher Yates algorithm.
*
* @returns Copy of the input array in a random order.
*/
const shuffle = (input) => {
const r = input.slice();
for (let i = r.length - 1; i > 0; i--) {
const shuffle = (arr) => {
const shuffled = arr.slice();
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[r[i], r[j]] = [r[j], r[i]];
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return r;
return shuffled;
};
exports.shuffle = shuffle;
function mapArray(input, mapper) {
function mapArray(arr, mapper) {
let promises = false;
let changed = !(input instanceof Array);
let changed = !(arr instanceof Array);
const output = [];
for (const [key, current] of Object.entries(input)) {
for (const [key, current] of Object.entries(arr)) {
const next = mapper instanceof Function ? mapper(current, key) : mapper;

@@ -106,3 +134,3 @@ if (next instanceof Promise)

}
return promises ? exports.resolveArray(output) : changed ? output : input;
return promises ? exports.resolveArray(output) : changed ? output : arr;
}

@@ -113,3 +141,3 @@ exports.mapArray = mapArray;

*
* @param input The input array.
* @param arr The input array.
* - Any values that are `Promise` instances will be awaited.

@@ -120,11 +148,34 @@ * - Any values that are the `SKIP` symbol will not be included in the output array.

*/
const resolveArray = async (input) => {
const output = [];
await Promise.all(input.map(async (current) => {
const resolveArray = async (arr) => {
const resolved = [];
await Promise.all(arr.map(async (current) => {
const next = await current;
if (next !== constants_1.SKIP)
output.push(next);
resolved.push(next);
}));
return output;
return resolved;
};
exports.resolveArray = resolveArray;
/**
* Adds an item to an array by reference.
* - If the item already exists in the array (using `indexOf()`) then it won't be added again.
*/
const addItem = (arr, item) => {
if (arr.indexOf(item) < 0)
arr.push(item);
};
exports.addItem = addItem;
/**
* Delete an item from an array by reference.
* - Deletes all instances of an item from an array by reference, and returns void.
*/
const deleteItem = (arr, value) => {
let i = arr.indexOf(value);
if (i < 0)
return;
while (i >= 0) {
arr.splice(i, 1);
i = arr.indexOf(value, i);
}
};
exports.deleteItem = deleteItem;

@@ -90,14 +90,22 @@ import type { Entry, MutableObject, ReadonlyEntries, ReadonlyObject, ResolvableEntries, ResolvableObject, UnknownObject } from "../types";

/**
* Return a new object where a named property has been removed.
* If `key` doesn't exist in `obj` then the exact same input object will be returned (the types won't allow this to happen on explicitly propped objects).
* Add a property to an object.
* - Different from `updateProp()` because it will create the property if it doesn't exist.
*
* @return New object with the specified prop.
* - If `key` already exists in `obj` and is exactly the same (using `===`) then the exact same input object will be returned.
*/
export declare const deleteProp: <O extends UnknownObject, K extends keyof O>(obj: O, key: K) => Pick<O, Exclude<keyof O, K>>;
export declare const withProp: <O extends UnknownObject, K extends string | keyof O, V>(obj: O, key: K, value: V) => O & { [X in K]: V; };
/**
* Return a new object where a named property has been set.
* - If `key` already exists in `obj` and is exactly the same (using `===`) the the exact same input object will be returned.
* Remove a property from an object.
*
* @return New object without the specified prop.
* - If `key` doesn't already exist in `obj` then the exact same input object will be returned.
*/
export declare const setProp: <O extends UnknownObject, K extends string | keyof O, V>(obj: O, key: K, value: V) => O & { [X in K]: V; };
export declare const withoutProp: <O extends UnknownObject, K extends keyof O>(obj: O, key: K) => Pick<O, Exclude<keyof O, K>>;
/**
* Return a new object where a named property has been updated.
* 0 If `key` in `obj` and is exactly the same (using `===`) the the exact same input object will be returned.
* - Different from `withProp()` because it won't create the property if it doesn't exist.
*
* @return New object with the specified prop value.
* - If value is exactly the same (using `===`) then the exact same input object will be returned.
*/

@@ -104,0 +112,0 @@ export declare const updateProp: <O extends UnknownObject, K extends keyof O>(obj: O, key: K, value: O[K]) => O;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProp = exports.updateProp = exports.setProp = exports.deleteProp = exports.resolveObject = exports.objectFromKeys = exports.mapObject = exports.mapObjectKeys = exports.getEntryName = exports.getEntryTitle = exports.getEntryOrder = exports.getEntryDate = exports.getEntryValue = exports.getEntryKey = exports.objectFromEntries = exports.isObject = void 0;
exports.getProp = exports.updateProp = exports.withoutProp = exports.withProp = exports.resolveObject = exports.objectFromKeys = exports.mapObject = exports.mapObjectKeys = exports.getEntryName = exports.getEntryTitle = exports.getEntryOrder = exports.getEntryDate = exports.getEntryValue = exports.getEntryKey = exports.objectFromEntries = exports.isObject = void 0;
const constants_1 = require("../constants");

@@ -121,25 +121,33 @@ /** Is a value an unknown object? (is a TypeScript assertion object that asserts various things). */

/**
* Return a new object where a named property has been removed.
* If `key` doesn't exist in `obj` then the exact same input object will be returned (the types won't allow this to happen on explicitly propped objects).
* Add a property to an object.
* - Different from `updateProp()` because it will create the property if it doesn't exist.
*
* @return New object with the specified prop.
* - If `key` already exists in `obj` and is exactly the same (using `===`) then the exact same input object will be returned.
*/
const deleteProp = (obj, key) => {
if (!(key in obj))
const withProp = (obj, key, value) => {
if (key in obj && obj[key] === value)
return obj;
const { [key]: gone, ...returned } = obj; // eslint-disable-line @typescript-eslint/no-unused-vars
return returned;
return { ...obj, [key]: value };
};
exports.deleteProp = deleteProp;
exports.withProp = withProp;
/**
* Return a new object where a named property has been set.
* - If `key` already exists in `obj` and is exactly the same (using `===`) the the exact same input object will be returned.
* Remove a property from an object.
*
* @return New object without the specified prop.
* - If `key` doesn't already exist in `obj` then the exact same input object will be returned.
*/
const setProp = (obj, key, value) => {
if (key in obj && obj[key] === value)
const withoutProp = (obj, key) => {
if (!(key in obj))
return obj;
return { ...obj, [key]: value };
const { [key]: gone, ...returned } = obj; // eslint-disable-line @typescript-eslint/no-unused-vars
return returned;
};
exports.setProp = setProp;
exports.withoutProp = withoutProp;
/**
* Return a new object where a named property has been updated.
* 0 If `key` in `obj` and is exactly the same (using `===`) the the exact same input object will be returned.
* - Different from `withProp()` because it won't create the property if it doesn't exist.
*
* @return New object with the specified prop value.
* - If value is exactly the same (using `===`) then the exact same input object will be returned.
*/

@@ -146,0 +154,0 @@ const updateProp = (obj, key, value) => {

{
"name": "schemaglobin",
"description": "Validate user-entered data.",
"version": "5.12.1",
"version": "5.13.0",
"repository": "https://github.com/dhoulb/schemaglobin",

@@ -34,3 +34,3 @@ "author": "Dave Houlbrooke <dave@shax.com>",

"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-import": "^2.22.1",

@@ -37,0 +37,0 @@ "eslint-plugin-prettier": "^3.1.4",

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