Add settings page for managing forecasting API key and URL via UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 14:37:36 +00:00
parent cae411eae7
commit 1c411e402e
19809 changed files with 1962608 additions and 97 deletions

View file

@ -0,0 +1,34 @@
import { isEqual } from "./isEqual.mjs";
import { isArrayBuffer } from "./isArrayBuffer.mjs";
import { isBlob } from "./isBlob.mjs";
import { isBoolean } from "./isBoolean.mjs";
import { isBrowser } from "./isBrowser.mjs";
import { isBuffer } from "./isBuffer.mjs";
import { isDate } from "./isDate.mjs";
import { isEmptyObject } from "./isEmptyObject.mjs";
import { isEqualWith } from "./isEqualWith.mjs";
import { isError } from "./isError.mjs";
import { isFile } from "./isFile.mjs";
import { isFunction } from "./isFunction.mjs";
import { isIterable } from "./isIterable.mjs";
import { isJSON } from "./isJSON.mjs";
import { isJSONArray, isJSONObject, isJSONValue } from "./isJSONValue.mjs";
import { isLength } from "./isLength.mjs";
import { isMap } from "./isMap.mjs";
import { isNil } from "./isNil.mjs";
import { isNode } from "./isNode.mjs";
import { isNotNil } from "./isNotNil.mjs";
import { isNull } from "./isNull.mjs";
import { isNumber } from "./isNumber.mjs";
import { isPlainObject } from "./isPlainObject.mjs";
import { isPrimitive } from "./isPrimitive.mjs";
import { isPromise } from "./isPromise.mjs";
import { isRegExp } from "./isRegExp.mjs";
import { isSet } from "./isSet.mjs";
import { isString } from "./isString.mjs";
import { isSymbol } from "./isSymbol.mjs";
import { isTypedArray } from "./isTypedArray.mjs";
import { isUndefined } from "./isUndefined.mjs";
import { isWeakMap } from "./isWeakMap.mjs";
import { isWeakSet } from "./isWeakSet.mjs";
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };

View file

@ -0,0 +1,34 @@
import { isEqual } from "./isEqual.js";
import { isArrayBuffer } from "./isArrayBuffer.js";
import { isBlob } from "./isBlob.js";
import { isBoolean } from "./isBoolean.js";
import { isBrowser } from "./isBrowser.js";
import { isBuffer } from "./isBuffer.js";
import { isDate } from "./isDate.js";
import { isEmptyObject } from "./isEmptyObject.js";
import { isEqualWith } from "./isEqualWith.js";
import { isError } from "./isError.js";
import { isFile } from "./isFile.js";
import { isFunction } from "./isFunction.js";
import { isIterable } from "./isIterable.js";
import { isJSON } from "./isJSON.js";
import { isJSONArray, isJSONObject, isJSONValue } from "./isJSONValue.js";
import { isLength } from "./isLength.js";
import { isMap } from "./isMap.js";
import { isNil } from "./isNil.js";
import { isNode } from "./isNode.js";
import { isNotNil } from "./isNotNil.js";
import { isNull } from "./isNull.js";
import { isNumber } from "./isNumber.js";
import { isPlainObject } from "./isPlainObject.js";
import { isPrimitive } from "./isPrimitive.js";
import { isPromise } from "./isPromise.js";
import { isRegExp } from "./isRegExp.js";
import { isSet } from "./isSet.js";
import { isString } from "./isString.js";
import { isSymbol } from "./isSymbol.js";
import { isTypedArray } from "./isTypedArray.js";
import { isUndefined } from "./isUndefined.js";
import { isWeakMap } from "./isWeakMap.js";
import { isWeakSet } from "./isWeakSet.js";
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };

View file

@ -0,0 +1,69 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_isPrimitive = require("./isPrimitive.js");
const require_isTypedArray = require("./isTypedArray.js");
const require_isBuffer = require("./isBuffer.js");
const require_isPlainObject = require("./isPlainObject.js");
const require_isArrayBuffer = require("./isArrayBuffer.js");
const require_isBlob = require("./isBlob.js");
const require_isBoolean = require("./isBoolean.js");
const require_isBrowser = require("./isBrowser.js");
const require_isDate = require("./isDate.js");
const require_isEmptyObject = require("./isEmptyObject.js");
const require_isEqualWith = require("./isEqualWith.js");
const require_isEqual = require("./isEqual.js");
const require_isError = require("./isError.js");
const require_isFile = require("./isFile.js");
const require_isFunction = require("./isFunction.js");
const require_isIterable = require("./isIterable.js");
const require_isJSON = require("./isJSON.js");
const require_isJSONValue = require("./isJSONValue.js");
const require_isLength = require("./isLength.js");
const require_isMap = require("./isMap.js");
const require_isNil = require("./isNil.js");
const require_isNode = require("./isNode.js");
const require_isNotNil = require("./isNotNil.js");
const require_isNull = require("./isNull.js");
const require_isNumber = require("./isNumber.js");
const require_isPromise = require("./isPromise.js");
const require_isRegExp = require("./isRegExp.js");
const require_isSet = require("./isSet.js");
const require_isString = require("./isString.js");
const require_isSymbol = require("./isSymbol.js");
const require_isUndefined = require("./isUndefined.js");
const require_isWeakMap = require("./isWeakMap.js");
const require_isWeakSet = require("./isWeakSet.js");
exports.isArrayBuffer = require_isArrayBuffer.isArrayBuffer;
exports.isBlob = require_isBlob.isBlob;
exports.isBoolean = require_isBoolean.isBoolean;
exports.isBrowser = require_isBrowser.isBrowser;
exports.isBuffer = require_isBuffer.isBuffer;
exports.isDate = require_isDate.isDate;
exports.isEmptyObject = require_isEmptyObject.isEmptyObject;
exports.isEqual = require_isEqual.isEqual;
exports.isEqualWith = require_isEqualWith.isEqualWith;
exports.isError = require_isError.isError;
exports.isFile = require_isFile.isFile;
exports.isFunction = require_isFunction.isFunction;
exports.isIterable = require_isIterable.isIterable;
exports.isJSON = require_isJSON.isJSON;
exports.isJSONArray = require_isJSONValue.isJSONArray;
exports.isJSONObject = require_isJSONValue.isJSONObject;
exports.isJSONValue = require_isJSONValue.isJSONValue;
exports.isLength = require_isLength.isLength;
exports.isMap = require_isMap.isMap;
exports.isNil = require_isNil.isNil;
exports.isNode = require_isNode.isNode;
exports.isNotNil = require_isNotNil.isNotNil;
exports.isNull = require_isNull.isNull;
exports.isNumber = require_isNumber.isNumber;
exports.isPlainObject = require_isPlainObject.isPlainObject;
exports.isPrimitive = require_isPrimitive.isPrimitive;
exports.isPromise = require_isPromise.isPromise;
exports.isRegExp = require_isRegExp.isRegExp;
exports.isSet = require_isSet.isSet;
exports.isString = require_isString.isString;
exports.isSymbol = require_isSymbol.isSymbol;
exports.isTypedArray = require_isTypedArray.isTypedArray;
exports.isUndefined = require_isUndefined.isUndefined;
exports.isWeakMap = require_isWeakMap.isWeakMap;
exports.isWeakSet = require_isWeakSet.isWeakSet;

View file

@ -0,0 +1,34 @@
import { isPrimitive } from "./isPrimitive.mjs";
import { isTypedArray } from "./isTypedArray.mjs";
import { isBuffer } from "./isBuffer.mjs";
import { isPlainObject } from "./isPlainObject.mjs";
import { isArrayBuffer } from "./isArrayBuffer.mjs";
import { isBlob } from "./isBlob.mjs";
import { isBoolean } from "./isBoolean.mjs";
import { isBrowser } from "./isBrowser.mjs";
import { isDate } from "./isDate.mjs";
import { isEmptyObject } from "./isEmptyObject.mjs";
import { isEqualWith } from "./isEqualWith.mjs";
import { isEqual } from "./isEqual.mjs";
import { isError } from "./isError.mjs";
import { isFile } from "./isFile.mjs";
import { isFunction } from "./isFunction.mjs";
import { isIterable } from "./isIterable.mjs";
import { isJSON } from "./isJSON.mjs";
import { isJSONArray, isJSONObject, isJSONValue } from "./isJSONValue.mjs";
import { isLength } from "./isLength.mjs";
import { isMap } from "./isMap.mjs";
import { isNil } from "./isNil.mjs";
import { isNode } from "./isNode.mjs";
import { isNotNil } from "./isNotNil.mjs";
import { isNull } from "./isNull.mjs";
import { isNumber } from "./isNumber.mjs";
import { isPromise } from "./isPromise.mjs";
import { isRegExp } from "./isRegExp.mjs";
import { isSet } from "./isSet.mjs";
import { isString } from "./isString.mjs";
import { isSymbol } from "./isSymbol.mjs";
import { isUndefined } from "./isUndefined.mjs";
import { isWeakMap } from "./isWeakMap.mjs";
import { isWeakSet } from "./isWeakSet.mjs";
export { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet };

View file

@ -0,0 +1,21 @@
//#region src/predicate/isArrayBuffer.d.ts
/**
* Checks if a given value is `ArrayBuffer`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `ArrayBuffer`.
*
* @param value The value to check if it is a `ArrayBuffer`.
* @returns Returns `true` if `value` is a `ArrayBuffer`, else `false`.
*
* @example
* const value1 = new ArrayBuffer();
* const value2 = new Array();
* const value3 = new Map();
*
* console.log(isArrayBuffer(value1)); // true
* console.log(isArrayBuffer(value2)); // false
* console.log(isArrayBuffer(value3)); // false
*/
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
//#endregion
export { isArrayBuffer };

View file

@ -0,0 +1,21 @@
//#region src/predicate/isArrayBuffer.d.ts
/**
* Checks if a given value is `ArrayBuffer`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `ArrayBuffer`.
*
* @param value The value to check if it is a `ArrayBuffer`.
* @returns Returns `true` if `value` is a `ArrayBuffer`, else `false`.
*
* @example
* const value1 = new ArrayBuffer();
* const value2 = new Array();
* const value3 = new Map();
*
* console.log(isArrayBuffer(value1)); // true
* console.log(isArrayBuffer(value2)); // false
* console.log(isArrayBuffer(value3)); // false
*/
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
//#endregion
export { isArrayBuffer };

View file

@ -0,0 +1,23 @@
//#region src/predicate/isArrayBuffer.ts
/**
* Checks if a given value is `ArrayBuffer`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `ArrayBuffer`.
*
* @param value The value to check if it is a `ArrayBuffer`.
* @returns Returns `true` if `value` is a `ArrayBuffer`, else `false`.
*
* @example
* const value1 = new ArrayBuffer();
* const value2 = new Array();
* const value3 = new Map();
*
* console.log(isArrayBuffer(value1)); // true
* console.log(isArrayBuffer(value2)); // false
* console.log(isArrayBuffer(value3)); // false
*/
function isArrayBuffer(value) {
return value instanceof ArrayBuffer;
}
//#endregion
exports.isArrayBuffer = isArrayBuffer;

View file

@ -0,0 +1,23 @@
//#region src/predicate/isArrayBuffer.ts
/**
* Checks if a given value is `ArrayBuffer`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `ArrayBuffer`.
*
* @param value The value to check if it is a `ArrayBuffer`.
* @returns Returns `true` if `value` is a `ArrayBuffer`, else `false`.
*
* @example
* const value1 = new ArrayBuffer();
* const value2 = new Array();
* const value3 = new Map();
*
* console.log(isArrayBuffer(value1)); // true
* console.log(isArrayBuffer(value2)); // false
* console.log(isArrayBuffer(value3)); // false
*/
function isArrayBuffer(value) {
return value instanceof ArrayBuffer;
}
//#endregion
export { isArrayBuffer };

View file

@ -0,0 +1,20 @@
//#region src/predicate/isBlob.d.ts
/**
* Checks if the given value is a Blob.
*
* This function tests whether the provided value is an instance of `Blob`.
* It returns `true` if the value is an instance of `Blob`, and `false` otherwise.
*
* @param x - The value to test if it is a Blob.
* @returns True if the value is a Blob, false otherwise.
*
* @example
* const value1 = new Blob();
* const value2 = {};
*
* console.log(isBlob(value1)); // true
* console.log(isBlob(value2)); // false
*/
declare function isBlob(x: unknown): x is Blob;
//#endregion
export { isBlob };

View file

@ -0,0 +1,20 @@
//#region src/predicate/isBlob.d.ts
/**
* Checks if the given value is a Blob.
*
* This function tests whether the provided value is an instance of `Blob`.
* It returns `true` if the value is an instance of `Blob`, and `false` otherwise.
*
* @param x - The value to test if it is a Blob.
* @returns True if the value is a Blob, false otherwise.
*
* @example
* const value1 = new Blob();
* const value2 = {};
*
* console.log(isBlob(value1)); // true
* console.log(isBlob(value2)); // false
*/
declare function isBlob(x: unknown): x is Blob;
//#endregion
export { isBlob };

View file

@ -0,0 +1,23 @@
//#region src/predicate/isBlob.ts
/**
* Checks if the given value is a Blob.
*
* This function tests whether the provided value is an instance of `Blob`.
* It returns `true` if the value is an instance of `Blob`, and `false` otherwise.
*
* @param x - The value to test if it is a Blob.
* @returns True if the value is a Blob, false otherwise.
*
* @example
* const value1 = new Blob();
* const value2 = {};
*
* console.log(isBlob(value1)); // true
* console.log(isBlob(value2)); // false
*/
function isBlob(x) {
if (typeof Blob === "undefined") return false;
return x instanceof Blob;
}
//#endregion
exports.isBlob = isBlob;

View file

@ -0,0 +1,23 @@
//#region src/predicate/isBlob.ts
/**
* Checks if the given value is a Blob.
*
* This function tests whether the provided value is an instance of `Blob`.
* It returns `true` if the value is an instance of `Blob`, and `false` otherwise.
*
* @param x - The value to test if it is a Blob.
* @returns True if the value is a Blob, false otherwise.
*
* @example
* const value1 = new Blob();
* const value2 = {};
*
* console.log(isBlob(value1)); // true
* console.log(isBlob(value2)); // false
*/
function isBlob(x) {
if (typeof Blob === "undefined") return false;
return x instanceof Blob;
}
//#endregion
export { isBlob };

View file

@ -0,0 +1,26 @@
//#region src/predicate/isBoolean.d.ts
/**
* Checks if the given value is boolean.
*
* This function tests whether the provided value is strictly `boolean`.
* It returns `true` if the value is `boolean`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
*
* @param x - The Value to test if it is boolean.
* @returns True if the value is boolean, false otherwise.
*
* @example
*
* const value1 = true;
* const value2 = 0;
* const value3 = 'abc';
*
* console.log(isBoolean(value1)); // true
* console.log(isBoolean(value2)); // false
* console.log(isBoolean(value3)); // false
*
*/
declare function isBoolean(x: unknown): x is boolean;
//#endregion
export { isBoolean };

View file

@ -0,0 +1,26 @@
//#region src/predicate/isBoolean.d.ts
/**
* Checks if the given value is boolean.
*
* This function tests whether the provided value is strictly `boolean`.
* It returns `true` if the value is `boolean`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
*
* @param x - The Value to test if it is boolean.
* @returns True if the value is boolean, false otherwise.
*
* @example
*
* const value1 = true;
* const value2 = 0;
* const value3 = 'abc';
*
* console.log(isBoolean(value1)); // true
* console.log(isBoolean(value2)); // false
* console.log(isBoolean(value3)); // false
*
*/
declare function isBoolean(x: unknown): x is boolean;
//#endregion
export { isBoolean };

View file

@ -0,0 +1,28 @@
//#region src/predicate/isBoolean.ts
/**
* Checks if the given value is boolean.
*
* This function tests whether the provided value is strictly `boolean`.
* It returns `true` if the value is `boolean`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
*
* @param x - The Value to test if it is boolean.
* @returns True if the value is boolean, false otherwise.
*
* @example
*
* const value1 = true;
* const value2 = 0;
* const value3 = 'abc';
*
* console.log(isBoolean(value1)); // true
* console.log(isBoolean(value2)); // false
* console.log(isBoolean(value3)); // false
*
*/
function isBoolean(x) {
return typeof x === "boolean";
}
//#endregion
exports.isBoolean = isBoolean;

View file

@ -0,0 +1,28 @@
//#region src/predicate/isBoolean.ts
/**
* Checks if the given value is boolean.
*
* This function tests whether the provided value is strictly `boolean`.
* It returns `true` if the value is `boolean`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
*
* @param x - The Value to test if it is boolean.
* @returns True if the value is boolean, false otherwise.
*
* @example
*
* const value1 = true;
* const value2 = 0;
* const value3 = 'abc';
*
* console.log(isBoolean(value1)); // true
* console.log(isBoolean(value2)); // false
* console.log(isBoolean(value3)); // false
*
*/
function isBoolean(x) {
return typeof x === "boolean";
}
//#endregion
export { isBoolean };

View file

@ -0,0 +1,18 @@
//#region src/predicate/isBrowser.d.ts
/**
* Checks if the current environment is a browser.
*
* This function checks for the existence of the `window.document` property,
* which only exists in browser environments.
*
* @returns `true` if the current environment is a browser, otherwise `false`.
*
* @example
* if (isBrowser()) {
* console.log("This is running in a browser");
* document.getElementById('app').innerHTML = 'Hello World';
* }
*/
declare function isBrowser(): boolean;
//#endregion
export { isBrowser };

View file

@ -0,0 +1,18 @@
//#region src/predicate/isBrowser.d.ts
/**
* Checks if the current environment is a browser.
*
* This function checks for the existence of the `window.document` property,
* which only exists in browser environments.
*
* @returns `true` if the current environment is a browser, otherwise `false`.
*
* @example
* if (isBrowser()) {
* console.log("This is running in a browser");
* document.getElementById('app').innerHTML = 'Hello World';
* }
*/
declare function isBrowser(): boolean;
//#endregion
export { isBrowser };

View file

@ -0,0 +1,20 @@
//#region src/predicate/isBrowser.ts
/**
* Checks if the current environment is a browser.
*
* This function checks for the existence of the `window.document` property,
* which only exists in browser environments.
*
* @returns `true` if the current environment is a browser, otherwise `false`.
*
* @example
* if (isBrowser()) {
* console.log("This is running in a browser");
* document.getElementById('app').innerHTML = 'Hello World';
* }
*/
function isBrowser() {
return typeof window !== "undefined" && window?.document != null;
}
//#endregion
exports.isBrowser = isBrowser;

View file

@ -0,0 +1,20 @@
//#region src/predicate/isBrowser.ts
/**
* Checks if the current environment is a browser.
*
* This function checks for the existence of the `window.document` property,
* which only exists in browser environments.
*
* @returns `true` if the current environment is a browser, otherwise `false`.
*
* @example
* if (isBrowser()) {
* console.log("This is running in a browser");
* document.getElementById('app').innerHTML = 'Hello World';
* }
*/
function isBrowser() {
return typeof window !== "undefined" && window?.document != null;
}
//#endregion
export { isBrowser };

View file

@ -0,0 +1,22 @@
//#region src/predicate/isBuffer.d.ts
/**
* Checks if the given value is a Buffer instance.
*
* This function tests whether the provided value is an instance of Buffer.
* It returns `true` if the value is a Buffer, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
*
* @param x - The value to check if it is a Buffer.
* @returns Returns `true` if `x` is a Buffer, else `false`.
*
* @example
* const buffer = Buffer.from("test");
* console.log(isBuffer(buffer)); // true
*
* const notBuffer = "not a buffer";
* console.log(isBuffer(notBuffer)); // false
*/
declare function isBuffer(x: unknown): boolean;
//#endregion
export { isBuffer };

View file

@ -0,0 +1,22 @@
//#region src/predicate/isBuffer.d.ts
/**
* Checks if the given value is a Buffer instance.
*
* This function tests whether the provided value is an instance of Buffer.
* It returns `true` if the value is a Buffer, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
*
* @param x - The value to check if it is a Buffer.
* @returns Returns `true` if `x` is a Buffer, else `false`.
*
* @example
* const buffer = Buffer.from("test");
* console.log(isBuffer(buffer)); // true
*
* const notBuffer = "not a buffer";
* console.log(isBuffer(notBuffer)); // false
*/
declare function isBuffer(x: unknown): boolean;
//#endregion
export { isBuffer };

View file

@ -0,0 +1,25 @@
const require_globalThis = require("../_internal/globalThis.js");
//#region src/predicate/isBuffer.ts
/**
* Checks if the given value is a Buffer instance.
*
* This function tests whether the provided value is an instance of Buffer.
* It returns `true` if the value is a Buffer, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
*
* @param x - The value to check if it is a Buffer.
* @returns Returns `true` if `x` is a Buffer, else `false`.
*
* @example
* const buffer = Buffer.from("test");
* console.log(isBuffer(buffer)); // true
*
* const notBuffer = "not a buffer";
* console.log(isBuffer(notBuffer)); // false
*/
function isBuffer(x) {
return typeof require_globalThis.globalThis_.Buffer !== "undefined" && require_globalThis.globalThis_.Buffer.isBuffer(x);
}
//#endregion
exports.isBuffer = isBuffer;

View file

@ -0,0 +1,25 @@
import { globalThis_ } from "../_internal/globalThis.mjs";
//#region src/predicate/isBuffer.ts
/**
* Checks if the given value is a Buffer instance.
*
* This function tests whether the provided value is an instance of Buffer.
* It returns `true` if the value is a Buffer, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
*
* @param x - The value to check if it is a Buffer.
* @returns Returns `true` if `x` is a Buffer, else `false`.
*
* @example
* const buffer = Buffer.from("test");
* console.log(isBuffer(buffer)); // true
*
* const notBuffer = "not a buffer";
* console.log(isBuffer(notBuffer)); // false
*/
function isBuffer(x) {
return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
}
//#endregion
export { isBuffer };

View file

@ -0,0 +1,17 @@
//#region src/predicate/isDate.d.ts
/**
* Checks if `value` is a Date object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a Date object, `false` otherwise.
*
* @example
* const value1 = new Date();
* const value2 = '2024-01-01';
*
* console.log(isDate(value1)); // true
* console.log(isDate(value2)); // false
*/
declare function isDate(value: unknown): value is Date;
//#endregion
export { isDate };

View file

@ -0,0 +1,17 @@
//#region src/predicate/isDate.d.ts
/**
* Checks if `value` is a Date object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a Date object, `false` otherwise.
*
* @example
* const value1 = new Date();
* const value2 = '2024-01-01';
*
* console.log(isDate(value1)); // true
* console.log(isDate(value2)); // false
*/
declare function isDate(value: unknown): value is Date;
//#endregion
export { isDate };

View file

@ -0,0 +1,19 @@
//#region src/predicate/isDate.ts
/**
* Checks if `value` is a Date object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a Date object, `false` otherwise.
*
* @example
* const value1 = new Date();
* const value2 = '2024-01-01';
*
* console.log(isDate(value1)); // true
* console.log(isDate(value2)); // false
*/
function isDate(value) {
return value instanceof Date;
}
//#endregion
exports.isDate = isDate;

View file

@ -0,0 +1,19 @@
//#region src/predicate/isDate.ts
/**
* Checks if `value` is a Date object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a Date object, `false` otherwise.
*
* @example
* const value1 = new Date();
* const value2 = '2024-01-01';
*
* console.log(isDate(value1)); // true
* console.log(isDate(value2)); // false
*/
function isDate(value) {
return value instanceof Date;
}
//#endregion
export { isDate };

View file

@ -0,0 +1,16 @@
//#region src/predicate/isEmptyObject.d.ts
/**
* Checks if a value is an empty plain object.
*
* @param value - The value to check.
* @returns True if the value is an empty plain object, otherwise false.
*
* @example
* isEmptyObject({}); // true
* isEmptyObject({ a: 1 }); // false
* isEmptyObject([]); // false
* isEmptyObject(null); // false
*/
declare function isEmptyObject(value: unknown): value is Record<PropertyKey, never>;
//#endregion
export { isEmptyObject };

View file

@ -0,0 +1,16 @@
//#region src/predicate/isEmptyObject.d.ts
/**
* Checks if a value is an empty plain object.
*
* @param value - The value to check.
* @returns True if the value is an empty plain object, otherwise false.
*
* @example
* isEmptyObject({}); // true
* isEmptyObject({ a: 1 }); // false
* isEmptyObject([]); // false
* isEmptyObject(null); // false
*/
declare function isEmptyObject(value: unknown): value is Record<PropertyKey, never>;
//#endregion
export { isEmptyObject };

View file

@ -0,0 +1,19 @@
const require_isPlainObject = require("./isPlainObject.js");
//#region src/predicate/isEmptyObject.ts
/**
* Checks if a value is an empty plain object.
*
* @param value - The value to check.
* @returns True if the value is an empty plain object, otherwise false.
*
* @example
* isEmptyObject({}); // true
* isEmptyObject({ a: 1 }); // false
* isEmptyObject([]); // false
* isEmptyObject(null); // false
*/
function isEmptyObject(value) {
return require_isPlainObject.isPlainObject(value) && Object.keys(value).length === 0;
}
//#endregion
exports.isEmptyObject = isEmptyObject;

View file

@ -0,0 +1,19 @@
import { isPlainObject } from "./isPlainObject.mjs";
//#region src/predicate/isEmptyObject.ts
/**
* Checks if a value is an empty plain object.
*
* @param value - The value to check.
* @returns True if the value is an empty plain object, otherwise false.
*
* @example
* isEmptyObject({}); // true
* isEmptyObject({ a: 1 }); // false
* isEmptyObject([]); // false
* isEmptyObject(null); // false
*/
function isEmptyObject(value) {
return isPlainObject(value) && Object.keys(value).length === 0;
}
//#endregion
export { isEmptyObject };

View file

@ -0,0 +1,18 @@
//#region src/predicate/isEqual.d.ts
/**
* Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @returns `true` if the values are equal, otherwise `false`.
*
* @example
* isEqual(1, 1); // true
* isEqual({ a: 1 }, { a: 1 }); // true
* isEqual(/abc/g, /abc/g); // true
* isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
* isEqual([1, 2, 3], [1, 2, 3]); // true
*/
declare function isEqual(a: any, b: any): boolean;
//#endregion
export { isEqual };

View file

@ -0,0 +1,18 @@
//#region src/predicate/isEqual.d.ts
/**
* Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @returns `true` if the values are equal, otherwise `false`.
*
* @example
* isEqual(1, 1); // true
* isEqual({ a: 1 }, { a: 1 }); // true
* isEqual(/abc/g, /abc/g); // true
* isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
* isEqual([1, 2, 3], [1, 2, 3]); // true
*/
declare function isEqual(a: any, b: any): boolean;
//#endregion
export { isEqual };

View file

@ -0,0 +1,22 @@
const require_noop = require("../function/noop.js");
const require_isEqualWith = require("./isEqualWith.js");
//#region src/predicate/isEqual.ts
/**
* Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @returns `true` if the values are equal, otherwise `false`.
*
* @example
* isEqual(1, 1); // true
* isEqual({ a: 1 }, { a: 1 }); // true
* isEqual(/abc/g, /abc/g); // true
* isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
* isEqual([1, 2, 3], [1, 2, 3]); // true
*/
function isEqual(a, b) {
return require_isEqualWith.isEqualWith(a, b, require_noop.noop);
}
//#endregion
exports.isEqual = isEqual;

View file

@ -0,0 +1,22 @@
import { noop } from "../function/noop.mjs";
import { isEqualWith } from "./isEqualWith.mjs";
//#region src/predicate/isEqual.ts
/**
* Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @returns `true` if the values are equal, otherwise `false`.
*
* @example
* isEqual(1, 1); // true
* isEqual({ a: 1 }, { a: 1 }); // true
* isEqual(/abc/g, /abc/g); // true
* isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
* isEqual([1, 2, 3], [1, 2, 3]); // true
*/
function isEqual(a, b) {
return isEqualWith(a, b, noop);
}
//#endregion
export { isEqual };

View file

@ -0,0 +1,39 @@
//#region src/predicate/isEqualWith.d.ts
/**
* Compares two values for equality using a custom comparison function.
*
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
*
* This function also uses the custom equality function to compare values inside objects,
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
*
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
*
* The custom comparison function can take up to six parameters:
* - `x`: The value from the first object `a`.
* - `y`: The value from the second object `b`.
* - `property`: The property key used to get `x` and `y`.
* - `xParent`: The parent of the first value `x`.
* - `yParent`: The parent of the second value `y`.
* - `stack`: An internal stack (Map) to handle circular references.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @param areValuesEqual - A function to customize the comparison.
* If it returns a boolean, that result will be used. If it returns undefined,
* the default equality comparison will be used.
* @returns `true` if the values are equal according to the customizer, otherwise `false`.
*
* @example
* const customizer = (a, b) => {
* if (typeof a === 'string' && typeof b === 'string') {
* return a.toLowerCase() === b.toLowerCase();
* }
* };
* isEqualWith('Hello', 'hello', customizer); // true
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
*/
declare function isEqualWith(a: any, b: any, areValuesEqual: (x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
//#endregion
export { isEqualWith };

View file

@ -0,0 +1,39 @@
//#region src/predicate/isEqualWith.d.ts
/**
* Compares two values for equality using a custom comparison function.
*
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
*
* This function also uses the custom equality function to compare values inside objects,
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
*
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
*
* The custom comparison function can take up to six parameters:
* - `x`: The value from the first object `a`.
* - `y`: The value from the second object `b`.
* - `property`: The property key used to get `x` and `y`.
* - `xParent`: The parent of the first value `x`.
* - `yParent`: The parent of the second value `y`.
* - `stack`: An internal stack (Map) to handle circular references.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @param areValuesEqual - A function to customize the comparison.
* If it returns a boolean, that result will be used. If it returns undefined,
* the default equality comparison will be used.
* @returns `true` if the values are equal according to the customizer, otherwise `false`.
*
* @example
* const customizer = (a, b) => {
* if (typeof a === 'string' && typeof b === 'string') {
* return a.toLowerCase() === b.toLowerCase();
* }
* };
* isEqualWith('Hello', 'hello', customizer); // true
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
*/
declare function isEqualWith(a: any, b: any, areValuesEqual: (x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
//#endregion
export { isEqualWith };

View file

@ -0,0 +1,153 @@
const require_getSymbols = require("../compat/_internal/getSymbols.js");
const require_getTag = require("../compat/_internal/getTag.js");
const require_tags = require("../compat/_internal/tags.js");
const require_isBuffer = require("./isBuffer.js");
const require_isPlainObject = require("./isPlainObject.js");
const require_isEqualsSameValueZero = require("../_internal/isEqualsSameValueZero.js");
require("../compat/util/eq.js");
//#region src/predicate/isEqualWith.ts
/**
* Compares two values for equality using a custom comparison function.
*
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
*
* This function also uses the custom equality function to compare values inside objects,
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
*
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
*
* The custom comparison function can take up to six parameters:
* - `x`: The value from the first object `a`.
* - `y`: The value from the second object `b`.
* - `property`: The property key used to get `x` and `y`.
* - `xParent`: The parent of the first value `x`.
* - `yParent`: The parent of the second value `y`.
* - `stack`: An internal stack (Map) to handle circular references.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @param areValuesEqual - A function to customize the comparison.
* If it returns a boolean, that result will be used. If it returns undefined,
* the default equality comparison will be used.
* @returns `true` if the values are equal according to the customizer, otherwise `false`.
*
* @example
* const customizer = (a, b) => {
* if (typeof a === 'string' && typeof b === 'string') {
* return a.toLowerCase() === b.toLowerCase();
* }
* };
* isEqualWith('Hello', 'hello', customizer); // true
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
*/
function isEqualWith(a, b, areValuesEqual) {
return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
}
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
if (result !== void 0) return result;
if (typeof a === typeof b) switch (typeof a) {
case "bigint":
case "string":
case "boolean":
case "symbol":
case "undefined": return a === b;
case "number": return a === b || Object.is(a, b);
case "function": return a === b;
case "object": return areObjectsEqual(a, b, stack, areValuesEqual);
}
return areObjectsEqual(a, b, stack, areValuesEqual);
}
function areObjectsEqual(a, b, stack, areValuesEqual) {
if (Object.is(a, b)) return true;
let aTag = require_getTag.getTag(a);
let bTag = require_getTag.getTag(b);
if (aTag === "[object Arguments]") aTag = require_tags.objectTag;
if (bTag === "[object Arguments]") bTag = require_tags.objectTag;
if (aTag !== bTag) return false;
switch (aTag) {
case require_tags.stringTag: return a.toString() === b.toString();
case require_tags.numberTag: {
const x = a.valueOf();
const y = b.valueOf();
return require_isEqualsSameValueZero.isEqualsSameValueZero(x, y);
}
case require_tags.booleanTag:
case require_tags.dateTag:
case require_tags.symbolTag: return Object.is(a.valueOf(), b.valueOf());
case require_tags.regexpTag: return a.source === b.source && a.flags === b.flags;
case require_tags.functionTag: return a === b;
}
stack = stack ?? /* @__PURE__ */ new Map();
const aStack = stack.get(a);
const bStack = stack.get(b);
if (aStack != null && bStack != null) return aStack === b;
stack.set(a, b);
stack.set(b, a);
try {
switch (aTag) {
case require_tags.mapTag:
if (a.size !== b.size) return false;
for (const [key, value] of a.entries()) if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) return false;
return true;
case require_tags.setTag: {
if (a.size !== b.size) return false;
const aValues = Array.from(a.values());
const bValues = Array.from(b.values());
for (let i = 0; i < aValues.length; i++) {
const aValue = aValues[i];
const index = bValues.findIndex((bValue) => {
return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
});
if (index === -1) return false;
bValues.splice(index, 1);
}
return true;
}
case require_tags.arrayTag:
case require_tags.uint8ArrayTag:
case require_tags.uint8ClampedArrayTag:
case require_tags.uint16ArrayTag:
case require_tags.uint32ArrayTag:
case require_tags.bigUint64ArrayTag:
case require_tags.int8ArrayTag:
case require_tags.int16ArrayTag:
case require_tags.int32ArrayTag:
case require_tags.bigInt64ArrayTag:
case require_tags.float32ArrayTag:
case require_tags.float64ArrayTag:
if (require_isBuffer.isBuffer(a) !== require_isBuffer.isBuffer(b)) return false;
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) return false;
return true;
case require_tags.arrayBufferTag:
if (a.byteLength !== b.byteLength) return false;
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
case require_tags.dataViewTag:
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) return false;
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
case require_tags.errorTag: return a.name === b.name && a.message === b.message;
case require_tags.objectTag: {
if (!(areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || require_isPlainObject.isPlainObject(a) && require_isPlainObject.isPlainObject(b))) return false;
const aKeys = [...Object.keys(a), ...require_getSymbols.getSymbols(a)];
const bKeys = [...Object.keys(b), ...require_getSymbols.getSymbols(b)];
if (aKeys.length !== bKeys.length) return false;
for (let i = 0; i < aKeys.length; i++) {
const propKey = aKeys[i];
const aProp = a[propKey];
if (!Object.hasOwn(b, propKey)) return false;
const bProp = b[propKey];
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) return false;
}
return true;
}
default: return false;
}
} finally {
stack.delete(a);
stack.delete(b);
}
}
//#endregion
exports.isEqualWith = isEqualWith;

View file

@ -0,0 +1,149 @@
import { getSymbols } from "../compat/_internal/getSymbols.mjs";
import { getTag } from "../compat/_internal/getTag.mjs";
import { arrayBufferTag, arrayTag, bigInt64ArrayTag, bigUint64ArrayTag, booleanTag, dataViewTag, dateTag, errorTag, float32ArrayTag, float64ArrayTag, functionTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag } from "../compat/_internal/tags.mjs";
import { isBuffer } from "./isBuffer.mjs";
import { isPlainObject } from "./isPlainObject.mjs";
import { isEqualsSameValueZero } from "../_internal/isEqualsSameValueZero.mjs";
import "../compat/util/eq.mjs";
//#region src/predicate/isEqualWith.ts
/**
* Compares two values for equality using a custom comparison function.
*
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
*
* This function also uses the custom equality function to compare values inside objects,
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
*
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
*
* The custom comparison function can take up to six parameters:
* - `x`: The value from the first object `a`.
* - `y`: The value from the second object `b`.
* - `property`: The property key used to get `x` and `y`.
* - `xParent`: The parent of the first value `x`.
* - `yParent`: The parent of the second value `y`.
* - `stack`: An internal stack (Map) to handle circular references.
*
* @param a - The first value to compare.
* @param b - The second value to compare.
* @param areValuesEqual - A function to customize the comparison.
* If it returns a boolean, that result will be used. If it returns undefined,
* the default equality comparison will be used.
* @returns `true` if the values are equal according to the customizer, otherwise `false`.
*
* @example
* const customizer = (a, b) => {
* if (typeof a === 'string' && typeof b === 'string') {
* return a.toLowerCase() === b.toLowerCase();
* }
* };
* isEqualWith('Hello', 'hello', customizer); // true
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
*/
function isEqualWith(a, b, areValuesEqual) {
return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
}
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
if (result !== void 0) return result;
if (typeof a === typeof b) switch (typeof a) {
case "bigint":
case "string":
case "boolean":
case "symbol":
case "undefined": return a === b;
case "number": return a === b || Object.is(a, b);
case "function": return a === b;
case "object": return areObjectsEqual(a, b, stack, areValuesEqual);
}
return areObjectsEqual(a, b, stack, areValuesEqual);
}
function areObjectsEqual(a, b, stack, areValuesEqual) {
if (Object.is(a, b)) return true;
let aTag = getTag(a);
let bTag = getTag(b);
if (aTag === "[object Arguments]") aTag = objectTag;
if (bTag === "[object Arguments]") bTag = objectTag;
if (aTag !== bTag) return false;
switch (aTag) {
case stringTag: return a.toString() === b.toString();
case numberTag: return isEqualsSameValueZero(a.valueOf(), b.valueOf());
case booleanTag:
case dateTag:
case symbolTag: return Object.is(a.valueOf(), b.valueOf());
case regexpTag: return a.source === b.source && a.flags === b.flags;
case functionTag: return a === b;
}
stack = stack ?? /* @__PURE__ */ new Map();
const aStack = stack.get(a);
const bStack = stack.get(b);
if (aStack != null && bStack != null) return aStack === b;
stack.set(a, b);
stack.set(b, a);
try {
switch (aTag) {
case mapTag:
if (a.size !== b.size) return false;
for (const [key, value] of a.entries()) if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) return false;
return true;
case setTag: {
if (a.size !== b.size) return false;
const aValues = Array.from(a.values());
const bValues = Array.from(b.values());
for (let i = 0; i < aValues.length; i++) {
const aValue = aValues[i];
const index = bValues.findIndex((bValue) => {
return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
});
if (index === -1) return false;
bValues.splice(index, 1);
}
return true;
}
case arrayTag:
case uint8ArrayTag:
case uint8ClampedArrayTag:
case uint16ArrayTag:
case uint32ArrayTag:
case bigUint64ArrayTag:
case int8ArrayTag:
case int16ArrayTag:
case int32ArrayTag:
case bigInt64ArrayTag:
case float32ArrayTag:
case float64ArrayTag:
if (isBuffer(a) !== isBuffer(b)) return false;
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) return false;
return true;
case arrayBufferTag:
if (a.byteLength !== b.byteLength) return false;
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
case dataViewTag:
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) return false;
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
case errorTag: return a.name === b.name && a.message === b.message;
case objectTag: {
if (!(areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || isPlainObject(a) && isPlainObject(b))) return false;
const aKeys = [...Object.keys(a), ...getSymbols(a)];
const bKeys = [...Object.keys(b), ...getSymbols(b)];
if (aKeys.length !== bKeys.length) return false;
for (let i = 0; i < aKeys.length; i++) {
const propKey = aKeys[i];
const aProp = a[propKey];
if (!Object.hasOwn(b, propKey)) return false;
const bProp = b[propKey];
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) return false;
}
return true;
}
default: return false;
}
} finally {
stack.delete(a);
stack.delete(b);
}
}
//#endregion
export { isEqualWith };

View file

@ -0,0 +1,17 @@
//#region src/predicate/isError.d.ts
/**
* Checks if `value` is an Error object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is an Error object, `false` otherwise.
*
* @example
* ```typescript
* console.log(isError(new Error())); // true
* console.log(isError('Error')); // false
* console.log(isError({ name: 'Error', message: '' })); // false
* ```
*/
declare function isError(value: unknown): value is Error;
//#endregion
export { isError };

View file

@ -0,0 +1,17 @@
//#region src/predicate/isError.d.ts
/**
* Checks if `value` is an Error object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is an Error object, `false` otherwise.
*
* @example
* ```typescript
* console.log(isError(new Error())); // true
* console.log(isError('Error')); // false
* console.log(isError({ name: 'Error', message: '' })); // false
* ```
*/
declare function isError(value: unknown): value is Error;
//#endregion
export { isError };

View file

@ -0,0 +1,19 @@
//#region src/predicate/isError.ts
/**
* Checks if `value` is an Error object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is an Error object, `false` otherwise.
*
* @example
* ```typescript
* console.log(isError(new Error())); // true
* console.log(isError('Error')); // false
* console.log(isError({ name: 'Error', message: '' })); // false
* ```
*/
function isError(value) {
return value instanceof Error;
}
//#endregion
exports.isError = isError;

View file

@ -0,0 +1,19 @@
//#region src/predicate/isError.ts
/**
* Checks if `value` is an Error object.
*
* @param value The value to check.
* @returns Returns `true` if `value` is an Error object, `false` otherwise.
*
* @example
* ```typescript
* console.log(isError(new Error())); // true
* console.log(isError('Error')); // false
* console.log(isError({ name: 'Error', message: '' })); // false
* ```
*/
function isError(value) {
return value instanceof Error;
}
//#endregion
export { isError };

View file

@ -0,0 +1,22 @@
//#region src/predicate/isFile.d.ts
/**
* Checks if the given value is a File.
*
* This function tests whether the provided value is an instance of `File`.
* It returns `true` if the value is an instance of `File`, and `false` otherwise.
*
* @param x - The value to test if it is a File.
* @returns True if the value is a File, false otherwise.
*
* @example
* const value1 = new File(["content"], "example.txt");
* const value2 = {};
* const value3 = new Blob(["content"], { type: "text/plain" });
*
* console.log(isFile(value1)); // true
* console.log(isFile(value2)); // false
* console.log(isFile(value3)); // false
*/
declare function isFile(x: unknown): x is File;
//#endregion
export { isFile };

View file

@ -0,0 +1,22 @@
//#region src/predicate/isFile.d.ts
/**
* Checks if the given value is a File.
*
* This function tests whether the provided value is an instance of `File`.
* It returns `true` if the value is an instance of `File`, and `false` otherwise.
*
* @param x - The value to test if it is a File.
* @returns True if the value is a File, false otherwise.
*
* @example
* const value1 = new File(["content"], "example.txt");
* const value2 = {};
* const value3 = new Blob(["content"], { type: "text/plain" });
*
* console.log(isFile(value1)); // true
* console.log(isFile(value2)); // false
* console.log(isFile(value3)); // false
*/
declare function isFile(x: unknown): x is File;
//#endregion
export { isFile };

View file

@ -0,0 +1,26 @@
const require_isBlob = require("./isBlob.js");
//#region src/predicate/isFile.ts
/**
* Checks if the given value is a File.
*
* This function tests whether the provided value is an instance of `File`.
* It returns `true` if the value is an instance of `File`, and `false` otherwise.
*
* @param x - The value to test if it is a File.
* @returns True if the value is a File, false otherwise.
*
* @example
* const value1 = new File(["content"], "example.txt");
* const value2 = {};
* const value3 = new Blob(["content"], { type: "text/plain" });
*
* console.log(isFile(value1)); // true
* console.log(isFile(value2)); // false
* console.log(isFile(value3)); // false
*/
function isFile(x) {
if (typeof File === "undefined") return false;
return require_isBlob.isBlob(x) && x instanceof File;
}
//#endregion
exports.isFile = isFile;

View file

@ -0,0 +1,26 @@
import { isBlob } from "./isBlob.mjs";
//#region src/predicate/isFile.ts
/**
* Checks if the given value is a File.
*
* This function tests whether the provided value is an instance of `File`.
* It returns `true` if the value is an instance of `File`, and `false` otherwise.
*
* @param x - The value to test if it is a File.
* @returns True if the value is a File, false otherwise.
*
* @example
* const value1 = new File(["content"], "example.txt");
* const value2 = {};
* const value3 = new Blob(["content"], { type: "text/plain" });
*
* console.log(isFile(value1)); // true
* console.log(isFile(value2)); // false
* console.log(isFile(value3)); // false
*/
function isFile(x) {
if (typeof File === "undefined") return false;
return isBlob(x) && x instanceof File;
}
//#endregion
export { isFile };

View file

@ -0,0 +1,17 @@
//#region src/predicate/isFunction.d.ts
/**
* Checks if `value` is a function.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a function, else `false`.
*
* @example
* isFunction(Array.prototype.slice); // true
* isFunction(async function () {}); // true
* isFunction(function* () {}); // true
* isFunction(Proxy); // true
* isFunction(Int8Array); // true
*/
declare function isFunction(value: any): value is (...args: any[]) => any;
//#endregion
export { isFunction };

View file

@ -0,0 +1,17 @@
//#region src/predicate/isFunction.d.ts
/**
* Checks if `value` is a function.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a function, else `false`.
*
* @example
* isFunction(Array.prototype.slice); // true
* isFunction(async function () {}); // true
* isFunction(function* () {}); // true
* isFunction(Proxy); // true
* isFunction(Int8Array); // true
*/
declare function isFunction(value: any): value is (...args: any[]) => any;
//#endregion
export { isFunction };

View file

@ -0,0 +1,19 @@
//#region src/predicate/isFunction.ts
/**
* Checks if `value` is a function.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a function, else `false`.
*
* @example
* isFunction(Array.prototype.slice); // true
* isFunction(async function () {}); // true
* isFunction(function* () {}); // true
* isFunction(Proxy); // true
* isFunction(Int8Array); // true
*/
function isFunction(value) {
return typeof value === "function";
}
//#endregion
exports.isFunction = isFunction;

View file

@ -0,0 +1,19 @@
//#region src/predicate/isFunction.ts
/**
* Checks if `value` is a function.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a function, else `false`.
*
* @example
* isFunction(Array.prototype.slice); // true
* isFunction(async function () {}); // true
* isFunction(function* () {}); // true
* isFunction(Proxy); // true
* isFunction(Int8Array); // true
*/
function isFunction(value) {
return typeof value === "function";
}
//#endregion
export { isFunction };

View file

@ -0,0 +1,26 @@
//#region src/predicate/isIterable.d.ts
/**
* Checks if a value is iterable, i.e. it implements the iterable protocol by
* providing a `Symbol.iterator` method.
*
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
* plain objects, `null`, and `undefined` are not.
*
* This function can be used as a TypeScript type predicate to narrow the type of
* `value` to `Iterable<unknown>`.
*
* @param value - The value to check.
* @returns `true` if `value` is iterable, `false` otherwise.
*
* @example
* isIterable([1, 2, 3]); // true
* isIterable('abc'); // true
* isIterable(new Set([1, 2, 3])); // true
* isIterable(new Map()); // true
* isIterable({ a: 1 }); // false
* isIterable(123); // false
* isIterable(null); // false
*/
declare function isIterable(value: unknown): value is Iterable<unknown>;
//#endregion
export { isIterable };

View file

@ -0,0 +1,26 @@
//#region src/predicate/isIterable.d.ts
/**
* Checks if a value is iterable, i.e. it implements the iterable protocol by
* providing a `Symbol.iterator` method.
*
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
* plain objects, `null`, and `undefined` are not.
*
* This function can be used as a TypeScript type predicate to narrow the type of
* `value` to `Iterable<unknown>`.
*
* @param value - The value to check.
* @returns `true` if `value` is iterable, `false` otherwise.
*
* @example
* isIterable([1, 2, 3]); // true
* isIterable('abc'); // true
* isIterable(new Set([1, 2, 3])); // true
* isIterable(new Map()); // true
* isIterable({ a: 1 }); // false
* isIterable(123); // false
* isIterable(null); // false
*/
declare function isIterable(value: unknown): value is Iterable<unknown>;
//#endregion
export { isIterable };

View file

@ -0,0 +1,28 @@
//#region src/predicate/isIterable.ts
/**
* Checks if a value is iterable, i.e. it implements the iterable protocol by
* providing a `Symbol.iterator` method.
*
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
* plain objects, `null`, and `undefined` are not.
*
* This function can be used as a TypeScript type predicate to narrow the type of
* `value` to `Iterable<unknown>`.
*
* @param value - The value to check.
* @returns `true` if `value` is iterable, `false` otherwise.
*
* @example
* isIterable([1, 2, 3]); // true
* isIterable('abc'); // true
* isIterable(new Set([1, 2, 3])); // true
* isIterable(new Map()); // true
* isIterable({ a: 1 }); // false
* isIterable(123); // false
* isIterable(null); // false
*/
function isIterable(value) {
return value != null && typeof value[Symbol.iterator] === "function";
}
//#endregion
exports.isIterable = isIterable;

View file

@ -0,0 +1,28 @@
//#region src/predicate/isIterable.ts
/**
* Checks if a value is iterable, i.e. it implements the iterable protocol by
* providing a `Symbol.iterator` method.
*
* Arrays, strings, `Set`, `Map`, typed arrays, and generators are iterable;
* plain objects, `null`, and `undefined` are not.
*
* This function can be used as a TypeScript type predicate to narrow the type of
* `value` to `Iterable<unknown>`.
*
* @param value - The value to check.
* @returns `true` if `value` is iterable, `false` otherwise.
*
* @example
* isIterable([1, 2, 3]); // true
* isIterable('abc'); // true
* isIterable(new Set([1, 2, 3])); // true
* isIterable(new Map()); // true
* isIterable({ a: 1 }); // false
* isIterable(123); // false
* isIterable(null); // false
*/
function isIterable(value) {
return value != null && typeof value[Symbol.iterator] === "function";
}
//#endregion
export { isIterable };

View file

@ -0,0 +1,32 @@
//#region src/predicate/isJSON.d.ts
/**
* Checks if a given value is a valid JSON string.
*
* A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON
* specifications, valid JSON can represent:
* - Objects (with string keys and valid JSON values)
* - Arrays (containing valid JSON values)
* - Strings
* - Numbers
* - Booleans
* - null
*
* String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered
* valid JSON and will return true.
*
* This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid JSON string, else `false`.
*
* @example
* isJSON('{"name":"John","age":30}'); // true
* isJSON('[1,2,3]'); // true
* isJSON('true'); // true
* isJSON('invalid json'); // false
* isJSON({ name: 'John' }); // false (not a string)
* isJSON(null); // false (not a string)
*/
declare function isJSON(value: unknown): value is string;
//#endregion
export { isJSON };

View file

@ -0,0 +1,32 @@
//#region src/predicate/isJSON.d.ts
/**
* Checks if a given value is a valid JSON string.
*
* A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON
* specifications, valid JSON can represent:
* - Objects (with string keys and valid JSON values)
* - Arrays (containing valid JSON values)
* - Strings
* - Numbers
* - Booleans
* - null
*
* String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered
* valid JSON and will return true.
*
* This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid JSON string, else `false`.
*
* @example
* isJSON('{"name":"John","age":30}'); // true
* isJSON('[1,2,3]'); // true
* isJSON('true'); // true
* isJSON('invalid json'); // false
* isJSON({ name: 'John' }); // false (not a string)
* isJSON(null); // false (not a string)
*/
declare function isJSON(value: unknown): value is string;
//#endregion
export { isJSON };

View file

@ -0,0 +1,40 @@
//#region src/predicate/isJSON.ts
/**
* Checks if a given value is a valid JSON string.
*
* A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON
* specifications, valid JSON can represent:
* - Objects (with string keys and valid JSON values)
* - Arrays (containing valid JSON values)
* - Strings
* - Numbers
* - Booleans
* - null
*
* String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered
* valid JSON and will return true.
*
* This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid JSON string, else `false`.
*
* @example
* isJSON('{"name":"John","age":30}'); // true
* isJSON('[1,2,3]'); // true
* isJSON('true'); // true
* isJSON('invalid json'); // false
* isJSON({ name: 'John' }); // false (not a string)
* isJSON(null); // false (not a string)
*/
function isJSON(value) {
if (typeof value !== "string") return false;
try {
JSON.parse(value);
return true;
} catch {
return false;
}
}
//#endregion
exports.isJSON = isJSON;

View file

@ -0,0 +1,40 @@
//#region src/predicate/isJSON.ts
/**
* Checks if a given value is a valid JSON string.
*
* A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON
* specifications, valid JSON can represent:
* - Objects (with string keys and valid JSON values)
* - Arrays (containing valid JSON values)
* - Strings
* - Numbers
* - Booleans
* - null
*
* String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered
* valid JSON and will return true.
*
* This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid JSON string, else `false`.
*
* @example
* isJSON('{"name":"John","age":30}'); // true
* isJSON('[1,2,3]'); // true
* isJSON('true'); // true
* isJSON('invalid json'); // false
* isJSON({ name: 'John' }); // false (not a string)
* isJSON(null); // false (not a string)
*/
function isJSON(value) {
if (typeof value !== "string") return false;
try {
JSON.parse(value);
return true;
} catch {
return false;
}
}
//#endregion
export { isJSON };

View file

@ -0,0 +1,57 @@
//#region src/predicate/isJSONValue.d.ts
/**
* Checks if a given value is a valid JSON value.
*
* A valid JSON value can be:
* - null
* - a JSON object (an object with string keys and valid JSON values)
* - a JSON array (an array of valid JSON values)
* - a string
* - a number
* - a boolean
*
* @param value - The value to check.
* @returns True if the value is a valid JSON value, otherwise false.
*
* @example
* console.log(isJSONValue(null)); // true
* console.log(isJSONValue({ key: "value" })); // true
* console.log(isJSONValue([1, 2, 3])); // true
* console.log(isJSONValue("Hello")); // true
* console.log(isJSONValue(42)); // true
* console.log(isJSONValue(true)); // true
* console.log(isJSONValue(undefined)); // false
* console.log(isJSONValue(() => {})); // false
*/
declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
/**
* Checks if a given value is a valid JSON array.
*
* A valid JSON array is defined as an array where all items are valid JSON values.
*
* @param value - The value to check.
* @returns True if the value is a valid JSON array, otherwise false.
*
* @example
* console.log(isJSONArray([1, 2, 3])); // true
* console.log(isJSONArray(["string", null, true])); // true
* console.log(isJSONArray([1, 2, () => {}])); // false
* console.log(isJSONArray("not an array")); // false
*/
declare function isJSONArray(value: unknown): value is any[];
/**
* Checks if a value is a JSON object.
*
* A valid JSON object is defined as an object with string keys and valid JSON values.
*
* @param obj The value to check.
* @returns True if `obj` is a JSON object, false otherwise.
*
* @example
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
* isJSONObject({ regexp: /test/ }); // false
* isJSONObject(123); // false
*/
declare function isJSONObject(obj: unknown): obj is Record<string, any>;
//#endregion
export { isJSONArray, isJSONObject, isJSONValue };

View file

@ -0,0 +1,57 @@
//#region src/predicate/isJSONValue.d.ts
/**
* Checks if a given value is a valid JSON value.
*
* A valid JSON value can be:
* - null
* - a JSON object (an object with string keys and valid JSON values)
* - a JSON array (an array of valid JSON values)
* - a string
* - a number
* - a boolean
*
* @param value - The value to check.
* @returns True if the value is a valid JSON value, otherwise false.
*
* @example
* console.log(isJSONValue(null)); // true
* console.log(isJSONValue({ key: "value" })); // true
* console.log(isJSONValue([1, 2, 3])); // true
* console.log(isJSONValue("Hello")); // true
* console.log(isJSONValue(42)); // true
* console.log(isJSONValue(true)); // true
* console.log(isJSONValue(undefined)); // false
* console.log(isJSONValue(() => {})); // false
*/
declare function isJSONValue(value: unknown): value is Record<string, any> | any[] | string | number | boolean | null;
/**
* Checks if a given value is a valid JSON array.
*
* A valid JSON array is defined as an array where all items are valid JSON values.
*
* @param value - The value to check.
* @returns True if the value is a valid JSON array, otherwise false.
*
* @example
* console.log(isJSONArray([1, 2, 3])); // true
* console.log(isJSONArray(["string", null, true])); // true
* console.log(isJSONArray([1, 2, () => {}])); // false
* console.log(isJSONArray("not an array")); // false
*/
declare function isJSONArray(value: unknown): value is any[];
/**
* Checks if a value is a JSON object.
*
* A valid JSON object is defined as an object with string keys and valid JSON values.
*
* @param obj The value to check.
* @returns True if `obj` is a JSON object, false otherwise.
*
* @example
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
* isJSONObject({ regexp: /test/ }); // false
* isJSONObject(123); // false
*/
declare function isJSONObject(obj: unknown): obj is Record<string, any>;
//#endregion
export { isJSONArray, isJSONObject, isJSONValue };

View file

@ -0,0 +1,85 @@
const require_isPlainObject = require("./isPlainObject.js");
//#region src/predicate/isJSONValue.ts
/**
* The functions isJSONValue, isJSONArray, and isJSONObject are grouped in this file
* to prevent any circular dependency issues.
*/
/**
* Checks if a given value is a valid JSON value.
*
* A valid JSON value can be:
* - null
* - a JSON object (an object with string keys and valid JSON values)
* - a JSON array (an array of valid JSON values)
* - a string
* - a number
* - a boolean
*
* @param value - The value to check.
* @returns True if the value is a valid JSON value, otherwise false.
*
* @example
* console.log(isJSONValue(null)); // true
* console.log(isJSONValue({ key: "value" })); // true
* console.log(isJSONValue([1, 2, 3])); // true
* console.log(isJSONValue("Hello")); // true
* console.log(isJSONValue(42)); // true
* console.log(isJSONValue(true)); // true
* console.log(isJSONValue(undefined)); // false
* console.log(isJSONValue(() => {})); // false
*/
function isJSONValue(value) {
switch (typeof value) {
case "object": return value === null || isJSONArray(value) || isJSONObject(value);
case "string":
case "number":
case "boolean": return true;
default: return false;
}
}
/**
* Checks if a given value is a valid JSON array.
*
* A valid JSON array is defined as an array where all items are valid JSON values.
*
* @param value - The value to check.
* @returns True if the value is a valid JSON array, otherwise false.
*
* @example
* console.log(isJSONArray([1, 2, 3])); // true
* console.log(isJSONArray(["string", null, true])); // true
* console.log(isJSONArray([1, 2, () => {}])); // false
* console.log(isJSONArray("not an array")); // false
*/
function isJSONArray(value) {
if (!Array.isArray(value)) return false;
return value.every((item) => isJSONValue(item));
}
/**
* Checks if a value is a JSON object.
*
* A valid JSON object is defined as an object with string keys and valid JSON values.
*
* @param obj The value to check.
* @returns True if `obj` is a JSON object, false otherwise.
*
* @example
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
* isJSONObject({ regexp: /test/ }); // false
* isJSONObject(123); // false
*/
function isJSONObject(obj) {
if (!require_isPlainObject.isPlainObject(obj)) return false;
const keys = Reflect.ownKeys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = obj[key];
if (typeof key !== "string") return false;
if (!isJSONValue(value)) return false;
}
return true;
}
//#endregion
exports.isJSONArray = isJSONArray;
exports.isJSONObject = isJSONObject;
exports.isJSONValue = isJSONValue;

View file

@ -0,0 +1,83 @@
import { isPlainObject } from "./isPlainObject.mjs";
//#region src/predicate/isJSONValue.ts
/**
* The functions isJSONValue, isJSONArray, and isJSONObject are grouped in this file
* to prevent any circular dependency issues.
*/
/**
* Checks if a given value is a valid JSON value.
*
* A valid JSON value can be:
* - null
* - a JSON object (an object with string keys and valid JSON values)
* - a JSON array (an array of valid JSON values)
* - a string
* - a number
* - a boolean
*
* @param value - The value to check.
* @returns True if the value is a valid JSON value, otherwise false.
*
* @example
* console.log(isJSONValue(null)); // true
* console.log(isJSONValue({ key: "value" })); // true
* console.log(isJSONValue([1, 2, 3])); // true
* console.log(isJSONValue("Hello")); // true
* console.log(isJSONValue(42)); // true
* console.log(isJSONValue(true)); // true
* console.log(isJSONValue(undefined)); // false
* console.log(isJSONValue(() => {})); // false
*/
function isJSONValue(value) {
switch (typeof value) {
case "object": return value === null || isJSONArray(value) || isJSONObject(value);
case "string":
case "number":
case "boolean": return true;
default: return false;
}
}
/**
* Checks if a given value is a valid JSON array.
*
* A valid JSON array is defined as an array where all items are valid JSON values.
*
* @param value - The value to check.
* @returns True if the value is a valid JSON array, otherwise false.
*
* @example
* console.log(isJSONArray([1, 2, 3])); // true
* console.log(isJSONArray(["string", null, true])); // true
* console.log(isJSONArray([1, 2, () => {}])); // false
* console.log(isJSONArray("not an array")); // false
*/
function isJSONArray(value) {
if (!Array.isArray(value)) return false;
return value.every((item) => isJSONValue(item));
}
/**
* Checks if a value is a JSON object.
*
* A valid JSON object is defined as an object with string keys and valid JSON values.
*
* @param obj The value to check.
* @returns True if `obj` is a JSON object, false otherwise.
*
* @example
* isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', null: null } }); // true
* isJSONObject({ regexp: /test/ }); // false
* isJSONObject(123); // false
*/
function isJSONObject(obj) {
if (!isPlainObject(obj)) return false;
const keys = Reflect.ownKeys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = obj[key];
if (typeof key !== "string") return false;
if (!isJSONValue(value)) return false;
}
return true;
}
//#endregion
export { isJSONArray, isJSONObject, isJSONValue };

View file

@ -0,0 +1,25 @@
//#region src/predicate/isLength.d.ts
/**
* Checks if a given value is a valid length.
*
* A valid length is of type `number`, is a non-negative integer, and is less than or equal to
* JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`).
* It returns `true` if the value is a valid length, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the
* argument to a valid length (`number`).
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid length, else `false`.
*
* @example
* isLength(0); // true
* isLength(42); // true
* isLength(-1); // false
* isLength(1.5); // false
* isLength(Number.MAX_SAFE_INTEGER); // true
* isLength(Number.MAX_SAFE_INTEGER + 1); // false
*/
declare function isLength(value?: any): boolean;
//#endregion
export { isLength };

View file

@ -0,0 +1,25 @@
//#region src/predicate/isLength.d.ts
/**
* Checks if a given value is a valid length.
*
* A valid length is of type `number`, is a non-negative integer, and is less than or equal to
* JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`).
* It returns `true` if the value is a valid length, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the
* argument to a valid length (`number`).
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid length, else `false`.
*
* @example
* isLength(0); // true
* isLength(42); // true
* isLength(-1); // false
* isLength(1.5); // false
* isLength(Number.MAX_SAFE_INTEGER); // true
* isLength(Number.MAX_SAFE_INTEGER + 1); // false
*/
declare function isLength(value?: any): boolean;
//#endregion
export { isLength };

View file

@ -0,0 +1,27 @@
//#region src/predicate/isLength.ts
/**
* Checks if a given value is a valid length.
*
* A valid length is of type `number`, is a non-negative integer, and is less than or equal to
* JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`).
* It returns `true` if the value is a valid length, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the
* argument to a valid length (`number`).
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid length, else `false`.
*
* @example
* isLength(0); // true
* isLength(42); // true
* isLength(-1); // false
* isLength(1.5); // false
* isLength(Number.MAX_SAFE_INTEGER); // true
* isLength(Number.MAX_SAFE_INTEGER + 1); // false
*/
function isLength(value) {
return Number.isSafeInteger(value) && value >= 0;
}
//#endregion
exports.isLength = isLength;

View file

@ -0,0 +1,27 @@
//#region src/predicate/isLength.ts
/**
* Checks if a given value is a valid length.
*
* A valid length is of type `number`, is a non-negative integer, and is less than or equal to
* JavaScript's maximum safe integer (`Number.MAX_SAFE_INTEGER`).
* It returns `true` if the value is a valid length, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the
* argument to a valid length (`number`).
*
* @param value The value to check.
* @returns Returns `true` if `value` is a valid length, else `false`.
*
* @example
* isLength(0); // true
* isLength(42); // true
* isLength(-1); // false
* isLength(1.5); // false
* isLength(Number.MAX_SAFE_INTEGER); // true
* isLength(Number.MAX_SAFE_INTEGER + 1); // false
*/
function isLength(value) {
return Number.isSafeInteger(value) && value >= 0;
}
//#endregion
export { isLength };

View file

@ -0,0 +1,21 @@
//#region src/predicate/isMap.d.ts
/**
* Checks if a given value is `Map`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`.
*
* @param value The value to check if it is a `Map`.
* @returns Returns `true` if `value` is a `Map`, else `false`.
*
* @example
* const value1 = new Map();
* const value2 = new Set();
* const value3 = new WeakMap();
*
* console.log(isMap(value1)); // true
* console.log(isMap(value2)); // false
* console.log(isMap(value3)); // false
*/
declare function isMap(value: unknown): value is Map<any, any>;
//#endregion
export { isMap };

View file

@ -0,0 +1,21 @@
//#region src/predicate/isMap.d.ts
/**
* Checks if a given value is `Map`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`.
*
* @param value The value to check if it is a `Map`.
* @returns Returns `true` if `value` is a `Map`, else `false`.
*
* @example
* const value1 = new Map();
* const value2 = new Set();
* const value3 = new WeakMap();
*
* console.log(isMap(value1)); // true
* console.log(isMap(value2)); // false
* console.log(isMap(value3)); // false
*/
declare function isMap(value: unknown): value is Map<any, any>;
//#endregion
export { isMap };

View file

@ -0,0 +1,23 @@
//#region src/predicate/isMap.ts
/**
* Checks if a given value is `Map`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`.
*
* @param value The value to check if it is a `Map`.
* @returns Returns `true` if `value` is a `Map`, else `false`.
*
* @example
* const value1 = new Map();
* const value2 = new Set();
* const value3 = new WeakMap();
*
* console.log(isMap(value1)); // true
* console.log(isMap(value2)); // false
* console.log(isMap(value3)); // false
*/
function isMap(value) {
return value instanceof Map;
}
//#endregion
exports.isMap = isMap;

View file

@ -0,0 +1,23 @@
//#region src/predicate/isMap.ts
/**
* Checks if a given value is `Map`.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`.
*
* @param value The value to check if it is a `Map`.
* @returns Returns `true` if `value` is a `Map`, else `false`.
*
* @example
* const value1 = new Map();
* const value2 = new Set();
* const value3 = new WeakMap();
*
* console.log(isMap(value1)); // true
* console.log(isMap(value2)); // false
* console.log(isMap(value3)); // false
*/
function isMap(value) {
return value instanceof Map;
}
//#endregion
export { isMap };

View file

@ -0,0 +1,23 @@
//#region src/predicate/isNil.d.ts
/**
* Checks if a given value is null or undefined.
*
* This function tests whether the provided value is either `null` or `undefined`.
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
*
* @param x - The value to test for null or undefined.
* @returns `true` if the value is null or undefined, `false` otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
* const result1 = isNil(value1); // true
* const result2 = isNil(value2); // true
* const result3 = isNil(value3); // false
*/
declare function isNil(x: unknown): x is null | undefined;
//#endregion
export { isNil };

View file

@ -0,0 +1,23 @@
//#region src/predicate/isNil.d.ts
/**
* Checks if a given value is null or undefined.
*
* This function tests whether the provided value is either `null` or `undefined`.
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
*
* @param x - The value to test for null or undefined.
* @returns `true` if the value is null or undefined, `false` otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
* const result1 = isNil(value1); // true
* const result2 = isNil(value2); // true
* const result3 = isNil(value3); // false
*/
declare function isNil(x: unknown): x is null | undefined;
//#endregion
export { isNil };

View file

@ -0,0 +1,25 @@
//#region src/predicate/isNil.ts
/**
* Checks if a given value is null or undefined.
*
* This function tests whether the provided value is either `null` or `undefined`.
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
*
* @param x - The value to test for null or undefined.
* @returns `true` if the value is null or undefined, `false` otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
* const result1 = isNil(value1); // true
* const result2 = isNil(value2); // true
* const result3 = isNil(value3); // false
*/
function isNil(x) {
return x == null;
}
//#endregion
exports.isNil = isNil;

View file

@ -0,0 +1,25 @@
//#region src/predicate/isNil.ts
/**
* Checks if a given value is null or undefined.
*
* This function tests whether the provided value is either `null` or `undefined`.
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
*
* @param x - The value to test for null or undefined.
* @returns `true` if the value is null or undefined, `false` otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
* const result1 = isNil(value1); // true
* const result2 = isNil(value2); // true
* const result3 = isNil(value3); // false
*/
function isNil(x) {
return x == null;
}
//#endregion
export { isNil };

View file

@ -0,0 +1,18 @@
//#region src/predicate/isNode.d.ts
/**
* Checks if the current environment is Node.js.
*
* This function checks for the existence of the `process.versions.node` property,
* which only exists in Node.js environments.
*
* @returns `true` if the current environment is Node.js, otherwise `false`.
*
* @example
* if (isNode()) {
* console.log('This is running in Node.js');
* const fs = import('node:fs');
* }
*/
declare function isNode(): boolean;
//#endregion
export { isNode };

View file

@ -0,0 +1,18 @@
//#region src/predicate/isNode.d.ts
/**
* Checks if the current environment is Node.js.
*
* This function checks for the existence of the `process.versions.node` property,
* which only exists in Node.js environments.
*
* @returns `true` if the current environment is Node.js, otherwise `false`.
*
* @example
* if (isNode()) {
* console.log('This is running in Node.js');
* const fs = import('node:fs');
* }
*/
declare function isNode(): boolean;
//#endregion
export { isNode };

View file

@ -0,0 +1,20 @@
//#region src/predicate/isNode.ts
/**
* Checks if the current environment is Node.js.
*
* This function checks for the existence of the `process.versions.node` property,
* which only exists in Node.js environments.
*
* @returns `true` if the current environment is Node.js, otherwise `false`.
*
* @example
* if (isNode()) {
* console.log('This is running in Node.js');
* const fs = import('node:fs');
* }
*/
function isNode() {
return typeof process !== "undefined" && process?.versions?.node != null;
}
//#endregion
exports.isNode = isNode;

View file

@ -0,0 +1,20 @@
//#region src/predicate/isNode.ts
/**
* Checks if the current environment is Node.js.
*
* This function checks for the existence of the `process.versions.node` property,
* which only exists in Node.js environments.
*
* @returns `true` if the current environment is Node.js, otherwise `false`.
*
* @example
* if (isNode()) {
* console.log('This is running in Node.js');
* const fs = import('node:fs');
* }
*/
function isNode() {
return typeof process !== "undefined" && process?.versions?.node != null;
}
//#endregion
export { isNode };

View file

@ -0,0 +1,20 @@
//#region src/predicate/isNotNil.d.ts
/**
* Checks if the given value is not null nor undefined.
*
* The main use of this function is to be used with TypeScript as a type predicate.
*
* @template T - The type of value.
* @param x - The value to test if it is not null nor undefined.
* @returns True if the value is not null nor undefined, false otherwise.
*
* @example
* // Here the type of `arr` is (number | undefined)[]
* const arr = [1, undefined, 3];
* // Here the type of `result` is number[]
* const result = arr.filter(isNotNil);
* // result will be [1, 3]
*/
declare function isNotNil<T>(x: T | null | undefined): x is T;
//#endregion
export { isNotNil };

View file

@ -0,0 +1,20 @@
//#region src/predicate/isNotNil.d.ts
/**
* Checks if the given value is not null nor undefined.
*
* The main use of this function is to be used with TypeScript as a type predicate.
*
* @template T - The type of value.
* @param x - The value to test if it is not null nor undefined.
* @returns True if the value is not null nor undefined, false otherwise.
*
* @example
* // Here the type of `arr` is (number | undefined)[]
* const arr = [1, undefined, 3];
* // Here the type of `result` is number[]
* const result = arr.filter(isNotNil);
* // result will be [1, 3]
*/
declare function isNotNil<T>(x: T | null | undefined): x is T;
//#endregion
export { isNotNil };

View file

@ -0,0 +1,22 @@
//#region src/predicate/isNotNil.ts
/**
* Checks if the given value is not null nor undefined.
*
* The main use of this function is to be used with TypeScript as a type predicate.
*
* @template T - The type of value.
* @param x - The value to test if it is not null nor undefined.
* @returns True if the value is not null nor undefined, false otherwise.
*
* @example
* // Here the type of `arr` is (number | undefined)[]
* const arr = [1, undefined, 3];
* // Here the type of `result` is number[]
* const result = arr.filter(isNotNil);
* // result will be [1, 3]
*/
function isNotNil(x) {
return x != null;
}
//#endregion
exports.isNotNil = isNotNil;

View file

@ -0,0 +1,22 @@
//#region src/predicate/isNotNil.ts
/**
* Checks if the given value is not null nor undefined.
*
* The main use of this function is to be used with TypeScript as a type predicate.
*
* @template T - The type of value.
* @param x - The value to test if it is not null nor undefined.
* @returns True if the value is not null nor undefined, false otherwise.
*
* @example
* // Here the type of `arr` is (number | undefined)[]
* const arr = [1, undefined, 3];
* // Here the type of `result` is number[]
* const result = arr.filter(isNotNil);
* // result will be [1, 3]
*/
function isNotNil(x) {
return x != null;
}
//#endregion
export { isNotNil };

View file

@ -0,0 +1,24 @@
//#region src/predicate/isNull.d.ts
/**
* Checks if the given value is null.
*
* This function tests whether the provided value is strictly equal to `null`.
* It returns `true` if the value is `null`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
*
* @param x - The value to test if it is null.
* @returns True if the value is null, false otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
*
* console.log(isNull(value1)); // true
* console.log(isNull(value2)); // false
* console.log(isNull(value3)); // false
*/
declare function isNull(x: unknown): x is null;
//#endregion
export { isNull };

View file

@ -0,0 +1,24 @@
//#region src/predicate/isNull.d.ts
/**
* Checks if the given value is null.
*
* This function tests whether the provided value is strictly equal to `null`.
* It returns `true` if the value is `null`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
*
* @param x - The value to test if it is null.
* @returns True if the value is null, false otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
*
* console.log(isNull(value1)); // true
* console.log(isNull(value2)); // false
* console.log(isNull(value3)); // false
*/
declare function isNull(x: unknown): x is null;
//#endregion
export { isNull };

View file

@ -0,0 +1,26 @@
//#region src/predicate/isNull.ts
/**
* Checks if the given value is null.
*
* This function tests whether the provided value is strictly equal to `null`.
* It returns `true` if the value is `null`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
*
* @param x - The value to test if it is null.
* @returns True if the value is null, false otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
*
* console.log(isNull(value1)); // true
* console.log(isNull(value2)); // false
* console.log(isNull(value3)); // false
*/
function isNull(x) {
return x === null;
}
//#endregion
exports.isNull = isNull;

View file

@ -0,0 +1,26 @@
//#region src/predicate/isNull.ts
/**
* Checks if the given value is null.
*
* This function tests whether the provided value is strictly equal to `null`.
* It returns `true` if the value is `null`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
*
* @param x - The value to test if it is null.
* @returns True if the value is null, false otherwise.
*
* @example
* const value1 = null;
* const value2 = undefined;
* const value3 = 42;
*
* console.log(isNull(value1)); // true
* console.log(isNull(value2)); // false
* console.log(isNull(value3)); // false
*/
function isNull(x) {
return x === null;
}
//#endregion
export { isNull };

View file

@ -0,0 +1,28 @@
//#region src/predicate/isNumber.d.ts
/**
* Checks if the given value is a number.
*
* This function tests whether the provided value is strictly a `number`.
* It returns `true` if the value is a `number`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
*
* @param x - The value to test if it is a number.
* @returns True if the value is a number, false otherwise.
*
* @example
*
* const value1 = 123;
* const value2 = 'abc';
* const value3 = true;
* const value4 = new Number(42);
*
* console.log(isNumber(value1)); // true
* console.log(isNumber(value2)); // false
* console.log(isNumber(value3)); // false
* console.log(isNumber(value4)); // false
*
*/
declare function isNumber(x: unknown): x is number;
//#endregion
export { isNumber };

View file

@ -0,0 +1,28 @@
//#region src/predicate/isNumber.d.ts
/**
* Checks if the given value is a number.
*
* This function tests whether the provided value is strictly a `number`.
* It returns `true` if the value is a `number`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
*
* @param x - The value to test if it is a number.
* @returns True if the value is a number, false otherwise.
*
* @example
*
* const value1 = 123;
* const value2 = 'abc';
* const value3 = true;
* const value4 = new Number(42);
*
* console.log(isNumber(value1)); // true
* console.log(isNumber(value2)); // false
* console.log(isNumber(value3)); // false
* console.log(isNumber(value4)); // false
*
*/
declare function isNumber(x: unknown): x is number;
//#endregion
export { isNumber };

View file

@ -0,0 +1,30 @@
//#region src/predicate/isNumber.ts
/**
* Checks if the given value is a number.
*
* This function tests whether the provided value is strictly a `number`.
* It returns `true` if the value is a `number`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
*
* @param x - The value to test if it is a number.
* @returns True if the value is a number, false otherwise.
*
* @example
*
* const value1 = 123;
* const value2 = 'abc';
* const value3 = true;
* const value4 = new Number(42);
*
* console.log(isNumber(value1)); // true
* console.log(isNumber(value2)); // false
* console.log(isNumber(value3)); // false
* console.log(isNumber(value4)); // false
*
*/
function isNumber(x) {
return typeof x === "number";
}
//#endregion
exports.isNumber = isNumber;

View file

@ -0,0 +1,30 @@
//#region src/predicate/isNumber.ts
/**
* Checks if the given value is a number.
*
* This function tests whether the provided value is strictly a `number`.
* It returns `true` if the value is a `number`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
*
* @param x - The value to test if it is a number.
* @returns True if the value is a number, false otherwise.
*
* @example
*
* const value1 = 123;
* const value2 = 'abc';
* const value3 = true;
* const value4 = new Number(42);
*
* console.log(isNumber(value1)); // true
* console.log(isNumber(value2)); // false
* console.log(isNumber(value3)); // false
* console.log(isNumber(value4)); // false
*
*/
function isNumber(x) {
return typeof x === "number";
}
//#endregion
export { isNumber };

View file

@ -0,0 +1,46 @@
//#region src/predicate/isPlainObject.d.ts
/**
* Checks if a given value is a plain object.
*
* @param value - The value to check.
* @returns True if the value is a plain object, otherwise false.
*
* @example
* ```typescript
* // ✅👇 True
*
* isPlainObject({ }); // ✅
* isPlainObject({ key: 'value' }); // ✅
* isPlainObject({ key: new Date() }); // ✅
* isPlainObject(new Object()); // ✅
* isPlainObject(Object.create(null)); // ✅
* isPlainObject({ nested: { key: true} }); // ✅
* isPlainObject(new Proxy({}, {})); // ✅
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
*
* // ✅👇 (cross-realms, node context, workers, ...)
* const runInNewContext = await import('node:vm').then(
* (mod) => mod.runInNewContext
* );
* isPlainObject(runInNewContext('({})')); // ✅
*
* // ❌👇 False
*
* class Test { };
* isPlainObject(new Test()) // ❌
* isPlainObject(10); // ❌
* isPlainObject(null); // ❌
* isPlainObject('hello'); // ❌
* isPlainObject([]); // ❌
* isPlainObject(new Date()); // ❌
* isPlainObject(new Uint8Array([1])); // ❌
* isPlainObject(Buffer.from('ABC')); // ❌
* isPlainObject(Promise.resolve({})); // ❌
* isPlainObject(Object.create({})); // ❌
* isPlainObject(new (class Cls {})); // ❌
* isPlainObject(globalThis); // ❌,
* ```
*/
declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
//#endregion
export { isPlainObject };

View file

@ -0,0 +1,46 @@
//#region src/predicate/isPlainObject.d.ts
/**
* Checks if a given value is a plain object.
*
* @param value - The value to check.
* @returns True if the value is a plain object, otherwise false.
*
* @example
* ```typescript
* // ✅👇 True
*
* isPlainObject({ }); // ✅
* isPlainObject({ key: 'value' }); // ✅
* isPlainObject({ key: new Date() }); // ✅
* isPlainObject(new Object()); // ✅
* isPlainObject(Object.create(null)); // ✅
* isPlainObject({ nested: { key: true} }); // ✅
* isPlainObject(new Proxy({}, {})); // ✅
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
*
* // ✅👇 (cross-realms, node context, workers, ...)
* const runInNewContext = await import('node:vm').then(
* (mod) => mod.runInNewContext
* );
* isPlainObject(runInNewContext('({})')); // ✅
*
* // ❌👇 False
*
* class Test { };
* isPlainObject(new Test()) // ❌
* isPlainObject(10); // ❌
* isPlainObject(null); // ❌
* isPlainObject('hello'); // ❌
* isPlainObject([]); // ❌
* isPlainObject(new Date()); // ❌
* isPlainObject(new Uint8Array([1])); // ❌
* isPlainObject(Buffer.from('ABC')); // ❌
* isPlainObject(Promise.resolve({})); // ❌
* isPlainObject(Object.create({})); // ❌
* isPlainObject(new (class Cls {})); // ❌
* isPlainObject(globalThis); // ❌,
* ```
*/
declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
//#endregion
export { isPlainObject };

View file

@ -0,0 +1,51 @@
//#region src/predicate/isPlainObject.ts
/**
* Checks if a given value is a plain object.
*
* @param value - The value to check.
* @returns True if the value is a plain object, otherwise false.
*
* @example
* ```typescript
* // ✅👇 True
*
* isPlainObject({ }); // ✅
* isPlainObject({ key: 'value' }); // ✅
* isPlainObject({ key: new Date() }); // ✅
* isPlainObject(new Object()); // ✅
* isPlainObject(Object.create(null)); // ✅
* isPlainObject({ nested: { key: true} }); // ✅
* isPlainObject(new Proxy({}, {})); // ✅
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
*
* // ✅👇 (cross-realms, node context, workers, ...)
* const runInNewContext = await import('node:vm').then(
* (mod) => mod.runInNewContext
* );
* isPlainObject(runInNewContext('({})')); // ✅
*
* // ❌👇 False
*
* class Test { };
* isPlainObject(new Test()) // ❌
* isPlainObject(10); // ❌
* isPlainObject(null); // ❌
* isPlainObject('hello'); // ❌
* isPlainObject([]); // ❌
* isPlainObject(new Date()); // ❌
* isPlainObject(new Uint8Array([1])); // ❌
* isPlainObject(Buffer.from('ABC')); // ❌
* isPlainObject(Promise.resolve({})); // ❌
* isPlainObject(Object.create({})); // ❌
* isPlainObject(new (class Cls {})); // ❌
* isPlainObject(globalThis); // ❌,
* ```
*/
function isPlainObject(value) {
if (!value || typeof value !== "object") return false;
const proto = Object.getPrototypeOf(value);
if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
return Object.prototype.toString.call(value) === "[object Object]";
}
//#endregion
exports.isPlainObject = isPlainObject;

View file

@ -0,0 +1,51 @@
//#region src/predicate/isPlainObject.ts
/**
* Checks if a given value is a plain object.
*
* @param value - The value to check.
* @returns True if the value is a plain object, otherwise false.
*
* @example
* ```typescript
* // ✅👇 True
*
* isPlainObject({ }); // ✅
* isPlainObject({ key: 'value' }); // ✅
* isPlainObject({ key: new Date() }); // ✅
* isPlainObject(new Object()); // ✅
* isPlainObject(Object.create(null)); // ✅
* isPlainObject({ nested: { key: true} }); // ✅
* isPlainObject(new Proxy({}, {})); // ✅
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
*
* // ✅👇 (cross-realms, node context, workers, ...)
* const runInNewContext = await import('node:vm').then(
* (mod) => mod.runInNewContext
* );
* isPlainObject(runInNewContext('({})')); // ✅
*
* // ❌👇 False
*
* class Test { };
* isPlainObject(new Test()) // ❌
* isPlainObject(10); // ❌
* isPlainObject(null); // ❌
* isPlainObject('hello'); // ❌
* isPlainObject([]); // ❌
* isPlainObject(new Date()); // ❌
* isPlainObject(new Uint8Array([1])); // ❌
* isPlainObject(Buffer.from('ABC')); // ❌
* isPlainObject(Promise.resolve({})); // ❌
* isPlainObject(Object.create({})); // ❌
* isPlainObject(new (class Cls {})); // ❌
* isPlainObject(globalThis); // ❌,
* ```
*/
function isPlainObject(value) {
if (!value || typeof value !== "object") return false;
const proto = Object.getPrototypeOf(value);
if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
return Object.prototype.toString.call(value) === "[object Object]";
}
//#endregion
export { isPlainObject };

View file

@ -0,0 +1,25 @@
//#region src/predicate/isPrimitive.d.ts
/**
* Checks whether a value is a JavaScript primitive.
* JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
*
* @param value The value to check.
* @returns Returns true if `value` is a primitive, false otherwise.
*
* @example
* isPrimitive(null); // true
* isPrimitive(undefined); // true
* isPrimitive('123'); // true
* isPrimitive(false); // true
* isPrimitive(true); // true
* isPrimitive(Symbol('a')); // true
* isPrimitive(123n); // true
* isPrimitive({}); // false
* isPrimitive(new Date()); // false
* isPrimitive(new Map()); // false
* isPrimitive(new Set()); // false
* isPrimitive([1, 2, 3]); // false
*/
declare function isPrimitive(value: unknown): value is null | undefined | string | number | boolean | symbol | bigint;
//#endregion
export { isPrimitive };

View file

@ -0,0 +1,25 @@
//#region src/predicate/isPrimitive.d.ts
/**
* Checks whether a value is a JavaScript primitive.
* JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
*
* @param value The value to check.
* @returns Returns true if `value` is a primitive, false otherwise.
*
* @example
* isPrimitive(null); // true
* isPrimitive(undefined); // true
* isPrimitive('123'); // true
* isPrimitive(false); // true
* isPrimitive(true); // true
* isPrimitive(Symbol('a')); // true
* isPrimitive(123n); // true
* isPrimitive({}); // false
* isPrimitive(new Date()); // false
* isPrimitive(new Map()); // false
* isPrimitive(new Set()); // false
* isPrimitive([1, 2, 3]); // false
*/
declare function isPrimitive(value: unknown): value is null | undefined | string | number | boolean | symbol | bigint;
//#endregion
export { isPrimitive };

View file

@ -0,0 +1,27 @@
//#region src/predicate/isPrimitive.ts
/**
* Checks whether a value is a JavaScript primitive.
* JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
*
* @param value The value to check.
* @returns Returns true if `value` is a primitive, false otherwise.
*
* @example
* isPrimitive(null); // true
* isPrimitive(undefined); // true
* isPrimitive('123'); // true
* isPrimitive(false); // true
* isPrimitive(true); // true
* isPrimitive(Symbol('a')); // true
* isPrimitive(123n); // true
* isPrimitive({}); // false
* isPrimitive(new Date()); // false
* isPrimitive(new Map()); // false
* isPrimitive(new Set()); // false
* isPrimitive([1, 2, 3]); // false
*/
function isPrimitive(value) {
return value == null || typeof value !== "object" && typeof value !== "function";
}
//#endregion
exports.isPrimitive = isPrimitive;

View file

@ -0,0 +1,27 @@
//#region src/predicate/isPrimitive.ts
/**
* Checks whether a value is a JavaScript primitive.
* JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
*
* @param value The value to check.
* @returns Returns true if `value` is a primitive, false otherwise.
*
* @example
* isPrimitive(null); // true
* isPrimitive(undefined); // true
* isPrimitive('123'); // true
* isPrimitive(false); // true
* isPrimitive(true); // true
* isPrimitive(Symbol('a')); // true
* isPrimitive(123n); // true
* isPrimitive({}); // false
* isPrimitive(new Date()); // false
* isPrimitive(new Map()); // false
* isPrimitive(new Set()); // false
* isPrimitive([1, 2, 3]); // false
*/
function isPrimitive(value) {
return value == null || typeof value !== "object" && typeof value !== "function";
}
//#endregion
export { isPrimitive };

Some files were not shown because too many files have changed in this diff Show more