mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 07:57:59 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name isArray
|
||||
* @summary Tests for a Array instance.
|
||||
*/
|
||||
export declare function isArray<T>(value?: unknown): value is T[];
|
||||
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isArray = isArray;
|
||||
/**
|
||||
* @name isArray
|
||||
* @summary Tests for a Array instance.
|
||||
*/
|
||||
function isArray(value) {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import type { U8aLike } from '../types.js';
|
||||
/**
|
||||
* @name isAscii
|
||||
* @summary Tests if the input is printable ASCII
|
||||
* @description
|
||||
* Checks to see if the input string or Uint8Array is printable ASCII, 32-127 + formatters
|
||||
*/
|
||||
export declare function isAscii(value?: U8aLike | null): boolean;
|
||||
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isAscii = isAscii;
|
||||
const toU8a_js_1 = require("../u8a/toU8a.js");
|
||||
const hex_js_1 = require("./hex.js");
|
||||
const string_js_1 = require("./string.js");
|
||||
/** @internal */
|
||||
function isAsciiStr(str) {
|
||||
for (let i = 0, count = str.length; i < count; i++) {
|
||||
const b = str.charCodeAt(i);
|
||||
// check is inlined here, it is faster than making a call
|
||||
if (b < 32 || b > 126) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/** @internal */
|
||||
function isAsciiBytes(u8a) {
|
||||
for (let i = 0, count = u8a.length; i < count; i++) {
|
||||
const b = u8a[i] | 0;
|
||||
// check is inlined here, it is faster than making a call
|
||||
if (b < 32 || b > 126) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @name isAscii
|
||||
* @summary Tests if the input is printable ASCII
|
||||
* @description
|
||||
* Checks to see if the input string or Uint8Array is printable ASCII, 32-127 + formatters
|
||||
*/
|
||||
function isAscii(value) {
|
||||
return (0, string_js_1.isString)(value)
|
||||
? (0, hex_js_1.isHex)(value)
|
||||
? isAsciiBytes((0, toU8a_js_1.u8aToU8a)(value))
|
||||
: isAsciiStr(value)
|
||||
: value
|
||||
? isAsciiBytes(value)
|
||||
: false;
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isBigInt
|
||||
* @summary Tests for a `BigInt` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BigInt`
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isBigInt } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isBigInt', isBigInt(123_456n)); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isBigInt(value: unknown): value is bigint;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isBigInt = isBigInt;
|
||||
/**
|
||||
* @name isBigInt
|
||||
* @summary Tests for a `BigInt` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BigInt`
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isBigInt } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isBigInt', isBigInt(123_456n)); // => true
|
||||
* ```
|
||||
*/
|
||||
function isBigInt(value) {
|
||||
return typeof value === 'bigint';
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import { BN } from '../bn/bn.js';
|
||||
/**
|
||||
* @name isBn
|
||||
* @summary Tests for a `BN` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BN` (bn.js).
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { isBn } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isBn', isBn(new BN(1))); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isBn(value: unknown): value is BN;
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isBn = isBn;
|
||||
const bn_js_1 = require("../bn/bn.js");
|
||||
/**
|
||||
* @name isBn
|
||||
* @summary Tests for a `BN` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BN` (bn.js).
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { isBn } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isBn', isBn(new BN(1))); // => true
|
||||
* ```
|
||||
*/
|
||||
function isBn(value) {
|
||||
return bn_js_1.BN.isBN(value);
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isBoolean
|
||||
* @summary Tests for a boolean value.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript boolean.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isBoolean } from '@pezkuwi/util';
|
||||
*
|
||||
* isBoolean(false); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isBoolean(value: unknown): value is boolean;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isBoolean = isBoolean;
|
||||
/**
|
||||
* @name isBoolean
|
||||
* @summary Tests for a boolean value.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript boolean.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isBoolean } from '@pezkuwi/util';
|
||||
*
|
||||
* isBoolean(false); // => true
|
||||
* ```
|
||||
*/
|
||||
function isBoolean(value) {
|
||||
return typeof value === 'boolean';
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
import type { BufferObject } from '../types.js';
|
||||
/**
|
||||
* @name isBuffer
|
||||
* @summary Tests for a `Buffer` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Buffer`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isBuffer } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isBuffer<T = BufferObject>(value: unknown): value is T;
|
||||
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isBuffer = isBuffer;
|
||||
const x_global_1 = require("@pezkuwi/x-global");
|
||||
const has_js_1 = require("../has.js");
|
||||
const function_js_1 = require("./function.js");
|
||||
/**
|
||||
* @name isBuffer
|
||||
* @summary Tests for a `Buffer` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Buffer`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isBuffer } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
|
||||
* ```
|
||||
*/
|
||||
function isBuffer(value) {
|
||||
// we do check a function first, since it is slightly faster than isBuffer itself
|
||||
return has_js_1.hasBuffer && !!value && (0, function_js_1.isFunction)(value.readDoubleLE) && x_global_1.xglobal.Buffer.isBuffer(value);
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import type { Class } from '../types.js';
|
||||
/**
|
||||
* @name isChildClass
|
||||
* @summary Tests if the child extends the parent Class
|
||||
* @description
|
||||
* Checks to see if the child Class extends the parent Class
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isChildClass } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isChildClass', isChildClass(BN, BN); // => true
|
||||
* console.log('isChildClass', isChildClass(BN, Uint8Array); // => false
|
||||
* ```
|
||||
*/
|
||||
export declare function isChildClass<P extends Class>(Parent: P, Child?: unknown): Child is P;
|
||||
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isChildClass = isChildClass;
|
||||
const class_js_1 = require("./class.js");
|
||||
/**
|
||||
* @name isChildClass
|
||||
* @summary Tests if the child extends the parent Class
|
||||
* @description
|
||||
* Checks to see if the child Class extends the parent Class
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isChildClass } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isChildClass', isChildClass(BN, BN); // => true
|
||||
* console.log('isChildClass', isChildClass(BN, Uint8Array); // => false
|
||||
* ```
|
||||
*/
|
||||
function isChildClass(Parent, Child) {
|
||||
// https://stackoverflow.com/questions/30993434/check-if-a-constructor-inherits-another-in-es6/30993664
|
||||
return (0, class_js_1.isClass)(Child) && (0, class_js_1.isClass)(Parent)
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
? Parent === Child || Parent.isPrototypeOf(Child)
|
||||
: false;
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import type { Class } from '../types.js';
|
||||
/**
|
||||
* @name isClass
|
||||
* Tests if the supplied argument is a Class
|
||||
*/
|
||||
export declare const isClass: <T extends Class>(value?: unknown) => value is T;
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isClass = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
/**
|
||||
* @name isClass
|
||||
* Tests if the supplied argument is a Class
|
||||
*/
|
||||
exports.isClass = (0, helpers_js_1.isOnFunction)('isPrototypeOf', 'hasOwnProperty');
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
import type { HexString } from '../types.js';
|
||||
interface Registry {
|
||||
get: (...params: never[]) => any;
|
||||
}
|
||||
interface Codec {
|
||||
readonly registry: Registry;
|
||||
toHex(...params: never[]): HexString;
|
||||
toHuman(...params: never[]): unknown;
|
||||
toU8a: (...params: never[]) => Uint8Array;
|
||||
}
|
||||
export declare function isCodec<T extends Codec = Codec>(value?: unknown): value is T;
|
||||
export {};
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isCodec = isCodec;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
const checkCodec = /*#__PURE__*/ (0, helpers_js_1.isOnObject)('toHex', 'toHuman', 'toU8a');
|
||||
const checkRegistry = /*#__PURE__*/ (0, helpers_js_1.isOnObject)('get');
|
||||
function isCodec(value) {
|
||||
return checkCodec(value) && checkRegistry(value.registry);
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import type { BN } from '../bn/bn.js';
|
||||
interface Compact<T> {
|
||||
toBigInt(): bigint;
|
||||
toBn(): BN;
|
||||
toNumber(): number;
|
||||
unwrap(): T;
|
||||
}
|
||||
/**
|
||||
* @name isCompact
|
||||
* @summary Tests for SCALE-Compact-like object instance.
|
||||
*/
|
||||
export declare const isCompact: <T>(value?: unknown) => value is Compact<T>;
|
||||
export {};
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isCompact = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
/**
|
||||
* @name isCompact
|
||||
* @summary Tests for SCALE-Compact-like object instance.
|
||||
*/
|
||||
exports.isCompact = (0, helpers_js_1.isOnObject)('toBigInt', 'toBn', 'toNumber', 'unwrap');
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isError
|
||||
* @summary Tests for a `Error` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Error`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isError } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isError', isError(new Error('message'))); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isError(value: unknown): value is Error;
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isError = isError;
|
||||
/**
|
||||
* @name isError
|
||||
* @summary Tests for a `Error` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Error`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isError } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isError', isError(new Error('message'))); // => true
|
||||
* ```
|
||||
*/
|
||||
function isError(value) {
|
||||
return (((value && value.constructor) === Error) ||
|
||||
value instanceof Error);
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
type FnType = Function;
|
||||
/**
|
||||
* @name isFunction
|
||||
* @summary Tests for a `function`.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript function.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isFunction } from '@pezkuwi/util';
|
||||
*
|
||||
* isFunction(() => false); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isFunction(value: unknown): value is FnType;
|
||||
export {};
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isFunction = isFunction;
|
||||
/**
|
||||
* @name isFunction
|
||||
* @summary Tests for a `function`.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript function.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isFunction } from '@pezkuwi/util';
|
||||
*
|
||||
* isFunction(() => false); // => true
|
||||
* ```
|
||||
*/
|
||||
function isFunction(value) {
|
||||
return typeof value === 'function';
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export declare function isOn<T>(...fns: (keyof T)[]): (value?: unknown) => value is T;
|
||||
export declare function isOnFunction<T>(...fns: (keyof T)[]): (value?: unknown) => value is T;
|
||||
export declare function isOnObject<T>(...fns: (keyof T)[]): (value?: unknown) => value is T;
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isOn = isOn;
|
||||
exports.isOnFunction = isOnFunction;
|
||||
exports.isOnObject = isOnObject;
|
||||
const function_js_1 = require("./function.js");
|
||||
const object_js_1 = require("./object.js");
|
||||
function isOn(...fns) {
|
||||
return (value) => ((0, object_js_1.isObject)(value) || (0, function_js_1.isFunction)(value)) &&
|
||||
fns.every((f) => (0, function_js_1.isFunction)(value[f]));
|
||||
}
|
||||
function isOnFunction(...fns) {
|
||||
return (value) => (0, function_js_1.isFunction)(value) &&
|
||||
fns.every((f) => (0, function_js_1.isFunction)(value[f]));
|
||||
}
|
||||
function isOnObject(...fns) {
|
||||
return (value) => (0, object_js_1.isObject)(value) &&
|
||||
fns.every((f) => (0, function_js_1.isFunction)(value[f]));
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
import type { HexString } from '../types.js';
|
||||
export declare const REGEX_HEX_PREFIXED: RegExp;
|
||||
export declare const REGEX_HEX_NOPREFIX: RegExp;
|
||||
/**
|
||||
* @name isHex
|
||||
* @summary Tests for a hex string.
|
||||
* @description
|
||||
* Checks to see if the input value is a `0x` prefixed hex string. Optionally (`bitLength` !== -1) checks to see if the bitLength is correct.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isHex } from '@pezkuwi/util';
|
||||
*
|
||||
* isHex('0x1234'); // => true
|
||||
* isHex('0x1234', 8); // => false
|
||||
* ```
|
||||
*/
|
||||
export declare function isHex(value: unknown, bitLength?: number, ignoreLength?: boolean): value is HexString;
|
||||
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.REGEX_HEX_NOPREFIX = exports.REGEX_HEX_PREFIXED = void 0;
|
||||
exports.isHex = isHex;
|
||||
exports.REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
|
||||
exports.REGEX_HEX_NOPREFIX = /^[\da-fA-F]+$/;
|
||||
/**
|
||||
* @name isHex
|
||||
* @summary Tests for a hex string.
|
||||
* @description
|
||||
* Checks to see if the input value is a `0x` prefixed hex string. Optionally (`bitLength` !== -1) checks to see if the bitLength is correct.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isHex } from '@pezkuwi/util';
|
||||
*
|
||||
* isHex('0x1234'); // => true
|
||||
* isHex('0x1234', 8); // => false
|
||||
* ```
|
||||
*/
|
||||
function isHex(value, bitLength = -1, ignoreLength) {
|
||||
return (typeof value === 'string' && (value === '0x' ||
|
||||
exports.REGEX_HEX_PREFIXED.test(value))) && (bitLength === -1
|
||||
? (ignoreLength || (value.length % 2 === 0))
|
||||
: (value.length === (2 + Math.ceil(bitLength / 4))));
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @summary Type checking utilities
|
||||
*/
|
||||
export { isArray } from './array.js';
|
||||
export { isAscii } from './ascii.js';
|
||||
export { isBigInt } from './bigInt.js';
|
||||
export { isBn } from './bn.js';
|
||||
export { isBoolean } from './boolean.js';
|
||||
export { isBuffer } from './buffer.js';
|
||||
export { isChildClass } from './childClass.js';
|
||||
export { isClass } from './class.js';
|
||||
export { isCodec } from './codec.js';
|
||||
export { isCompact } from './compact.js';
|
||||
export { isError } from './error.js';
|
||||
export { isFunction } from './function.js';
|
||||
export { isHex } from './hex.js';
|
||||
export { isInstanceOf } from './instanceOf.js';
|
||||
export { isIp } from './ip.js';
|
||||
export { isJsonObject } from './jsonObject.js';
|
||||
export { isNull } from './null.js';
|
||||
export { isNumber } from './number.js';
|
||||
export { isObject } from './object.js';
|
||||
export { isObservable } from './observable.js';
|
||||
export { isPromise } from './promise.js';
|
||||
export { isRiscV } from './riscv.js';
|
||||
export { isString } from './string.js';
|
||||
export { isTestChain } from './testChain.js';
|
||||
export { isToBigInt } from './toBigInt.js';
|
||||
export { isToBn } from './toBn.js';
|
||||
export { isU8a } from './u8a.js';
|
||||
export { isUndefined } from './undefined.js';
|
||||
export { isUtf8 } from './utf8.js';
|
||||
export { isWasm } from './wasm.js';
|
||||
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isWasm = exports.isUtf8 = exports.isUndefined = exports.isU8a = exports.isToBn = exports.isToBigInt = exports.isTestChain = exports.isString = exports.isRiscV = exports.isPromise = exports.isObservable = exports.isObject = exports.isNumber = exports.isNull = exports.isJsonObject = exports.isIp = exports.isInstanceOf = exports.isHex = exports.isFunction = exports.isError = exports.isCompact = exports.isCodec = exports.isClass = exports.isChildClass = exports.isBuffer = exports.isBoolean = exports.isBn = exports.isBigInt = exports.isAscii = exports.isArray = void 0;
|
||||
/**
|
||||
* @summary Type checking utilities
|
||||
*/
|
||||
var array_js_1 = require("./array.js");
|
||||
Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return array_js_1.isArray; } });
|
||||
var ascii_js_1 = require("./ascii.js");
|
||||
Object.defineProperty(exports, "isAscii", { enumerable: true, get: function () { return ascii_js_1.isAscii; } });
|
||||
var bigInt_js_1 = require("./bigInt.js");
|
||||
Object.defineProperty(exports, "isBigInt", { enumerable: true, get: function () { return bigInt_js_1.isBigInt; } });
|
||||
var bn_js_1 = require("./bn.js");
|
||||
Object.defineProperty(exports, "isBn", { enumerable: true, get: function () { return bn_js_1.isBn; } });
|
||||
var boolean_js_1 = require("./boolean.js");
|
||||
Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return boolean_js_1.isBoolean; } });
|
||||
var buffer_js_1 = require("./buffer.js");
|
||||
Object.defineProperty(exports, "isBuffer", { enumerable: true, get: function () { return buffer_js_1.isBuffer; } });
|
||||
var childClass_js_1 = require("./childClass.js");
|
||||
Object.defineProperty(exports, "isChildClass", { enumerable: true, get: function () { return childClass_js_1.isChildClass; } });
|
||||
var class_js_1 = require("./class.js");
|
||||
Object.defineProperty(exports, "isClass", { enumerable: true, get: function () { return class_js_1.isClass; } });
|
||||
var codec_js_1 = require("./codec.js");
|
||||
Object.defineProperty(exports, "isCodec", { enumerable: true, get: function () { return codec_js_1.isCodec; } });
|
||||
var compact_js_1 = require("./compact.js");
|
||||
Object.defineProperty(exports, "isCompact", { enumerable: true, get: function () { return compact_js_1.isCompact; } });
|
||||
var error_js_1 = require("./error.js");
|
||||
Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return error_js_1.isError; } });
|
||||
var function_js_1 = require("./function.js");
|
||||
Object.defineProperty(exports, "isFunction", { enumerable: true, get: function () { return function_js_1.isFunction; } });
|
||||
var hex_js_1 = require("./hex.js");
|
||||
Object.defineProperty(exports, "isHex", { enumerable: true, get: function () { return hex_js_1.isHex; } });
|
||||
var instanceOf_js_1 = require("./instanceOf.js");
|
||||
Object.defineProperty(exports, "isInstanceOf", { enumerable: true, get: function () { return instanceOf_js_1.isInstanceOf; } });
|
||||
var ip_js_1 = require("./ip.js");
|
||||
Object.defineProperty(exports, "isIp", { enumerable: true, get: function () { return ip_js_1.isIp; } });
|
||||
var jsonObject_js_1 = require("./jsonObject.js");
|
||||
Object.defineProperty(exports, "isJsonObject", { enumerable: true, get: function () { return jsonObject_js_1.isJsonObject; } });
|
||||
var null_js_1 = require("./null.js");
|
||||
Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return null_js_1.isNull; } });
|
||||
var number_js_1 = require("./number.js");
|
||||
Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return number_js_1.isNumber; } });
|
||||
var object_js_1 = require("./object.js");
|
||||
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return object_js_1.isObject; } });
|
||||
var observable_js_1 = require("./observable.js");
|
||||
Object.defineProperty(exports, "isObservable", { enumerable: true, get: function () { return observable_js_1.isObservable; } });
|
||||
var promise_js_1 = require("./promise.js");
|
||||
Object.defineProperty(exports, "isPromise", { enumerable: true, get: function () { return promise_js_1.isPromise; } });
|
||||
var riscv_js_1 = require("./riscv.js");
|
||||
Object.defineProperty(exports, "isRiscV", { enumerable: true, get: function () { return riscv_js_1.isRiscV; } });
|
||||
var string_js_1 = require("./string.js");
|
||||
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return string_js_1.isString; } });
|
||||
var testChain_js_1 = require("./testChain.js");
|
||||
Object.defineProperty(exports, "isTestChain", { enumerable: true, get: function () { return testChain_js_1.isTestChain; } });
|
||||
var toBigInt_js_1 = require("./toBigInt.js");
|
||||
Object.defineProperty(exports, "isToBigInt", { enumerable: true, get: function () { return toBigInt_js_1.isToBigInt; } });
|
||||
var toBn_js_1 = require("./toBn.js");
|
||||
Object.defineProperty(exports, "isToBn", { enumerable: true, get: function () { return toBn_js_1.isToBn; } });
|
||||
var u8a_js_1 = require("./u8a.js");
|
||||
Object.defineProperty(exports, "isU8a", { enumerable: true, get: function () { return u8a_js_1.isU8a; } });
|
||||
var undefined_js_1 = require("./undefined.js");
|
||||
Object.defineProperty(exports, "isUndefined", { enumerable: true, get: function () { return undefined_js_1.isUndefined; } });
|
||||
var utf8_js_1 = require("./utf8.js");
|
||||
Object.defineProperty(exports, "isUtf8", { enumerable: true, get: function () { return utf8_js_1.isUtf8; } });
|
||||
var wasm_js_1 = require("./wasm.js");
|
||||
Object.defineProperty(exports, "isWasm", { enumerable: true, get: function () { return wasm_js_1.isWasm; } });
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isInstanceOf
|
||||
* @summary Tests for a instance of a class.
|
||||
* @description
|
||||
* Checks to see if the input value is an instance of the test class.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isInstanceOf } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isInstanceOf(value: unknown, Clazz: Function): boolean;
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isInstanceOf = isInstanceOf;
|
||||
/**
|
||||
* @name isInstanceOf
|
||||
* @summary Tests for a instance of a class.
|
||||
* @description
|
||||
* Checks to see if the input value is an instance of the test class.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isInstanceOf } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
|
||||
* ```
|
||||
*/
|
||||
function isInstanceOf(value, Clazz) {
|
||||
return (((value && value.constructor) === Clazz) ||
|
||||
value instanceof Clazz);
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @name isIp
|
||||
* @summary Tests if the value is a valid IP address
|
||||
* @description
|
||||
* Checks to see if the value is a valid IP address. Optionally check for either v4/v6
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isIp } from '@pezkuwi/util';
|
||||
*
|
||||
* isIp('192.168.0.1')); // => true
|
||||
* isIp('1:2:3:4:5:6:7:8'); // => true
|
||||
* isIp('192.168.0.1', 'v6')); // => false
|
||||
* isIp('1:2:3:4:5:6:7:8', 'v4'); // => false
|
||||
* ```
|
||||
*/
|
||||
export declare function isIp(value: string, type?: 'v4' | 'v6'): boolean;
|
||||
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isIp = isIp;
|
||||
const v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
|
||||
const v6s = '[a-fA-F\\d]{1,4}';
|
||||
const v6 = `
|
||||
(?:
|
||||
(?:${v6s}:){7}(?:${v6s}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
||||
(?:${v6s}:){6}(?:${v4}|:${v6s}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
||||
(?:${v6s}:){5}(?::${v4}|(?::${v6s}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
||||
(?:${v6s}:){4}(?:(?::${v6s}){0,1}:${v4}|(?::${v6s}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
||||
(?:${v6s}:){3}(?:(?::${v6s}){0,2}:${v4}|(?::${v6s}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
||||
(?:${v6s}:){2}(?:(?::${v6s}){0,3}:${v4}|(?::${v6s}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
||||
(?:${v6s}:){1}(?:(?::${v6s}){0,4}:${v4}|(?::${v6s}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
||||
(?::(?:(?::${v6s}){0,5}:${v4}|(?::${v6s}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
||||
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
||||
`.replace(/\s*\/\/.*$/gm, '').replace(/\n/g, '').trim();
|
||||
const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
|
||||
const v4exact = new RegExp(`^${v4}$`);
|
||||
const v6exact = new RegExp(`^${v6}$`);
|
||||
/**
|
||||
* @name isIp
|
||||
* @summary Tests if the value is a valid IP address
|
||||
* @description
|
||||
* Checks to see if the value is a valid IP address. Optionally check for either v4/v6
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isIp } from '@pezkuwi/util';
|
||||
*
|
||||
* isIp('192.168.0.1')); // => true
|
||||
* isIp('1:2:3:4:5:6:7:8'); // => true
|
||||
* isIp('192.168.0.1', 'v6')); // => false
|
||||
* isIp('1:2:3:4:5:6:7:8', 'v4'); // => false
|
||||
* ```
|
||||
*/
|
||||
function isIp(value, type) {
|
||||
switch (type) {
|
||||
case 'v4': return v4exact.test(value);
|
||||
case 'v6': return v6exact.test(value);
|
||||
default: return v46Exact.test(value);
|
||||
}
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
type ObjectIndexed = Record<string, any>;
|
||||
/**
|
||||
* @name isJsonObject
|
||||
* @summary Tests for a valid JSON `object`.
|
||||
* @description
|
||||
* Checks to see if the input value is a valid JSON object.
|
||||
* It returns false if the input is JSON parsable, but not an Javascript object.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isJsonObject } from '@pezkuwi/util';
|
||||
*
|
||||
* isJsonObject({}); // => true
|
||||
* isJsonObject({
|
||||
* "Test": "1234",
|
||||
* "NestedTest": {
|
||||
* "Test": "5678"
|
||||
* }
|
||||
* }); // => true
|
||||
* isJsonObject(1234); // JSON parsable, but not an object => false
|
||||
* isJsonObject(null); // JSON parsable, but not an object => false
|
||||
* isJsonObject('not an object'); // => false
|
||||
* ```
|
||||
*/
|
||||
export declare function isJsonObject(value: unknown): value is ObjectIndexed;
|
||||
export {};
|
||||
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isJsonObject = isJsonObject;
|
||||
const stringify_js_1 = require("../stringify.js");
|
||||
/**
|
||||
* @name isJsonObject
|
||||
* @summary Tests for a valid JSON `object`.
|
||||
* @description
|
||||
* Checks to see if the input value is a valid JSON object.
|
||||
* It returns false if the input is JSON parsable, but not an Javascript object.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isJsonObject } from '@pezkuwi/util';
|
||||
*
|
||||
* isJsonObject({}); // => true
|
||||
* isJsonObject({
|
||||
* "Test": "1234",
|
||||
* "NestedTest": {
|
||||
* "Test": "5678"
|
||||
* }
|
||||
* }); // => true
|
||||
* isJsonObject(1234); // JSON parsable, but not an object => false
|
||||
* isJsonObject(null); // JSON parsable, but not an object => false
|
||||
* isJsonObject('not an object'); // => false
|
||||
* ```
|
||||
*/
|
||||
function isJsonObject(value) {
|
||||
const str = typeof value !== 'string'
|
||||
? (0, stringify_js_1.stringify)(value)
|
||||
: value;
|
||||
try {
|
||||
const obj = JSON.parse(str);
|
||||
return typeof obj === 'object' && obj !== null;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isNull
|
||||
* @summary Tests for a `null` values.
|
||||
* @description
|
||||
* Checks to see if the input value is `null`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isNull } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isNull', isNull(null)); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isNull(value?: unknown): value is null;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isNull = isNull;
|
||||
/**
|
||||
* @name isNull
|
||||
* @summary Tests for a `null` values.
|
||||
* @description
|
||||
* Checks to see if the input value is `null`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isNull } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isNull', isNull(null)); // => true
|
||||
* ```
|
||||
*/
|
||||
function isNull(value) {
|
||||
return value === null;
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isNumber
|
||||
* @summary Tests for a JavaScript number.
|
||||
* @description
|
||||
* Checks to see if the input value is a valid number.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isNumber } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isNumber', isNumber(1234)); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isNumber(value: unknown): value is number;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isNumber = isNumber;
|
||||
/**
|
||||
* @name isNumber
|
||||
* @summary Tests for a JavaScript number.
|
||||
* @description
|
||||
* Checks to see if the input value is a valid number.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isNumber } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isNumber', isNumber(1234)); // => true
|
||||
* ```
|
||||
*/
|
||||
function isNumber(value) {
|
||||
return typeof value === 'number';
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
type ObjectIndexed = Record<string, any>;
|
||||
/**
|
||||
* @name isObject
|
||||
* @summary Tests for an `object`.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript object.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isObject } from '@pezkuwi/util';
|
||||
*
|
||||
* isObject({}); // => true
|
||||
* isObject('something'); // => false
|
||||
* ```
|
||||
*/
|
||||
export declare function isObject<T extends ObjectIndexed = ObjectIndexed>(value?: unknown): value is T;
|
||||
export {};
|
||||
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isObject = isObject;
|
||||
/**
|
||||
* @name isObject
|
||||
* @summary Tests for an `object`.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript object.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isObject } from '@pezkuwi/util';
|
||||
*
|
||||
* isObject({}); // => true
|
||||
* isObject('something'); // => false
|
||||
* ```
|
||||
*/
|
||||
function isObject(value) {
|
||||
return !!value && typeof value === 'object';
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
import type { Observable } from '../types.js';
|
||||
/**
|
||||
* @name isBObservable
|
||||
* @summary Tests for a `Observable` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BN` (bn.js).
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isObservable } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isObservable', isObservable(...));
|
||||
* ```
|
||||
*/
|
||||
export declare const isObservable: (value?: unknown) => value is Observable;
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isObservable = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
/**
|
||||
* @name isBObservable
|
||||
* @summary Tests for a `Observable` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BN` (bn.js).
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isObservable } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isObservable', isObservable(...));
|
||||
* ```
|
||||
*/
|
||||
exports.isObservable = (0, helpers_js_1.isOn)('next');
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare const isPromise: (value?: unknown) => value is Promise<unknown>;
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isPromise = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
exports.isPromise = (0, helpers_js_1.isOnObject)('catch', 'then');
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @name isRiscV
|
||||
* @summary Tests if the input has a RISC-V header
|
||||
* @description
|
||||
* Checks to see if the input Uint8Array contains a valid RISC-V header
|
||||
*/
|
||||
export declare function isRiscV(bytes: unknown): bytes is Uint8Array;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isRiscV = isRiscV;
|
||||
const eq_js_1 = require("../u8a/eq.js");
|
||||
const u8a_js_1 = require("./u8a.js");
|
||||
const ELF_MAGIC = new Uint8Array([0x7f, 0x45, 0x4c, 0x46]); // ELF magic bytes: 0x7f, 'E', 'L', 'F'
|
||||
const PVM_MAGIC = new Uint8Array([0x50, 0x56, 0x4d, 0x00]); // 'P', 'V', 'M', 0x00
|
||||
/**
|
||||
* @name isRiscV
|
||||
* @summary Tests if the input has a RISC-V header
|
||||
* @description
|
||||
* Checks to see if the input Uint8Array contains a valid RISC-V header
|
||||
*/
|
||||
function isRiscV(bytes) {
|
||||
if ((0, u8a_js_1.isU8a)(bytes)) {
|
||||
const start = bytes.subarray(0, 4);
|
||||
return (0, eq_js_1.u8aEq)(start, PVM_MAGIC) || (0, eq_js_1.u8aEq)(start, ELF_MAGIC);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
import type { AnyString } from '../types.js';
|
||||
/**
|
||||
* @name isString
|
||||
* @summary Tests for a string.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript string.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isString } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isString', isString('test')); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isString(value: unknown): value is AnyString;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isString = isString;
|
||||
/**
|
||||
* @name isString
|
||||
* @summary Tests for a string.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript string.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isString } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isString', isString('test')); // => true
|
||||
* ```
|
||||
*/
|
||||
function isString(value) {
|
||||
return typeof value === 'string' || value instanceof String;
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function isTestChain(chain?: string | null): boolean;
|
||||
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isTestChain = isTestChain;
|
||||
const REGEX_DEV = /(Development|Local Testnet)$/;
|
||||
function isTestChain(chain) {
|
||||
if (!chain) {
|
||||
return false;
|
||||
}
|
||||
return !!REGEX_DEV.test(chain.toString());
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import type { ToBigInt } from '../types.js';
|
||||
export declare const isToBigInt: (value?: unknown) => value is ToBigInt;
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isToBigInt = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
exports.isToBigInt = (0, helpers_js_1.isOn)('toBigInt');
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import type { ToBn } from '../types.js';
|
||||
export declare const isToBn: (value?: unknown) => value is ToBn;
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isToBn = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
exports.isToBn = (0, helpers_js_1.isOn)('toBn');
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isU8a
|
||||
* @summary Tests for a `Uint8Array` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Uint8Array`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isUint8Array } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isU8a', isU8a([])); // => false
|
||||
* ```
|
||||
*/
|
||||
export declare function isU8a(value?: unknown): value is Uint8Array;
|
||||
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isU8a = isU8a;
|
||||
/**
|
||||
* @name isU8a
|
||||
* @summary Tests for a `Uint8Array` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Uint8Array`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isUint8Array } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isU8a', isU8a([])); // => false
|
||||
* ```
|
||||
*/
|
||||
function isU8a(value) {
|
||||
// here we defer the instanceof check which is actually slightly
|
||||
// slower than just checking the constrctor (direct instances)
|
||||
return (((value && value.constructor) === Uint8Array) ||
|
||||
value instanceof Uint8Array);
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name isUndefined
|
||||
* @summary Tests for a `undefined` values.
|
||||
* @description
|
||||
* Checks to see if the input value is `undefined`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isUndefined } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isUndefined', isUndefined(void(0))); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function isUndefined(value?: unknown): value is undefined;
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isUndefined = isUndefined;
|
||||
/**
|
||||
* @name isUndefined
|
||||
* @summary Tests for a `undefined` values.
|
||||
* @description
|
||||
* Checks to see if the input value is `undefined`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { isUndefined } from '@pezkuwi/util';
|
||||
*
|
||||
* console.log('isUndefined', isUndefined(void(0))); // => true
|
||||
* ```
|
||||
*/
|
||||
function isUndefined(value) {
|
||||
return value === undefined;
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @name isUtf8
|
||||
* @summary Tests if the input is valid Utf8
|
||||
* @description
|
||||
* Checks to see if the input string or Uint8Array is valid Utf8
|
||||
*/
|
||||
export declare function isUtf8(value?: number[] | Uint8Array | string | null): boolean;
|
||||
@@ -0,0 +1,200 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isUtf8 = isUtf8;
|
||||
const toU8a_js_1 = require("../u8a/toU8a.js");
|
||||
const string_js_1 = require("./string.js");
|
||||
/**
|
||||
* @name isUtf8
|
||||
* @summary Tests if the input is valid Utf8
|
||||
* @description
|
||||
* Checks to see if the input string or Uint8Array is valid Utf8
|
||||
*/
|
||||
function isUtf8(value) {
|
||||
if (!value) {
|
||||
return (0, string_js_1.isString)(value);
|
||||
}
|
||||
const u8a = (0, toU8a_js_1.u8aToU8a)(value);
|
||||
const len = u8a.length;
|
||||
let i = 0;
|
||||
while (i < len) {
|
||||
if (u8a[i] <= 0x7F) /* 00..7F */ {
|
||||
i += 1;
|
||||
}
|
||||
else if (u8a[i] >= 0xC2 && u8a[i] <= 0xDF) /* C2..DF 80..BF */ {
|
||||
if (i + 1 < len) /* Expect a 2nd byte */ {
|
||||
if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
|
||||
// *message = "After a first byte between C2 and DF, expecting a 2nd byte between 80 and BF";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte between C2 and DF, expecting a 2nd byte.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 2;
|
||||
}
|
||||
else if (u8a[i] === 0xE0) /* E0 A0..BF 80..BF */ {
|
||||
if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
|
||||
if (u8a[i + 1] < 0xA0 || u8a[i + 1] > 0xBF) {
|
||||
// *message = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte of E0, expecting a 3nd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte of E0, expecting two following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
else if (u8a[i] >= 0xE1 && u8a[i] <= 0xEC) /* E1..EC 80..BF 80..BF */ {
|
||||
if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
|
||||
if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
|
||||
// *message = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte between E1 and EC, expecting the 3rd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte between E1 and EC, expecting two following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
else if (u8a[i] === 0xED) /* ED 80..9F 80..BF */ {
|
||||
if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
|
||||
if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x9F) {
|
||||
// *message = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte of ED, expecting 3rd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte of ED, expecting two following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
else if (u8a[i] >= 0xEE && u8a[i] <= 0xEF) /* EE..EF 80..BF 80..BF */ {
|
||||
if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
|
||||
if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
|
||||
// *message = "After a first byte between EE and EF, expecting 2nd byte between 80 and BF.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte between EE and EF, expecting 3rd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte between EE and EF, two following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
else if (u8a[i] === 0xF0) /* F0 90..BF 80..BF 80..BF */ {
|
||||
if (i + 3 < len) /* Expect a 2nd, 3rd 3th byte */ {
|
||||
if (u8a[i + 1] < 0x90 || u8a[i + 1] > 0xBF) {
|
||||
// *message = "After a first byte of F0, expecting 2nd byte between 90 and BF.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte of F0, expecting 3rd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 3] < 0x80 || u8a[i + 3] > 0xBF) {
|
||||
// *message = "After a first byte of F0, expecting 4th byte between 80 and BF.";
|
||||
// *faulty_bytes = 4;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte of F0, expecting three following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 4;
|
||||
}
|
||||
else if (u8a[i] >= 0xF1 && u8a[i] <= 0xF3) /* F1..F3 80..BF 80..BF 80..BF */ {
|
||||
if (i + 3 < len) /* Expect a 2nd, 3rd 3th byte */ {
|
||||
if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
|
||||
// *message = "After a first byte of F1, F2, or F3, expecting a 2nd byte between 80 and BF.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte of F1, F2, or F3, expecting a 3rd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 3] < 0x80 || u8a[i + 3] > 0xBF) {
|
||||
// *message = "After a first byte of F1, F2, or F3, expecting a 4th byte between 80 and BF.";
|
||||
// *faulty_bytes = 4;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte of F1, F2, or F3, expecting three following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 4;
|
||||
}
|
||||
else if (u8a[i] === 0xF4) /* F4 80..8F 80..BF 80..BF */ {
|
||||
if (i + 3 < len) /* Expect a 2nd, 3rd 3th byte */ {
|
||||
if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x8F) {
|
||||
// *message = "After a first byte of F4, expecting 2nd byte between 80 and 8F.";
|
||||
// *faulty_bytes = 2;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
|
||||
// *message = "After a first byte of F4, expecting 3rd byte between 80 and BF.";
|
||||
// *faulty_bytes = 3;
|
||||
return false;
|
||||
}
|
||||
if (u8a[i + 3] < 0x80 || u8a[i + 3] > 0xBF) {
|
||||
// *message = "After a first byte of F4, expecting 4th byte between 80 and BF.";
|
||||
// *faulty_bytes = 4;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// *message = "After a first byte of F4, expecting three following bytes.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
i += 4;
|
||||
}
|
||||
else {
|
||||
// *message = "Expecting bytes in the following ranges: 00..7F C2..F4.";
|
||||
// *faulty_bytes = 1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @name isWasm
|
||||
* @summary Tests if the input has a WASM header
|
||||
* @description
|
||||
* Checks to see if the input Uint8Array contains a valid WASM header
|
||||
*/
|
||||
export declare function isWasm(value?: unknown): value is Uint8Array;
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isWasm = isWasm;
|
||||
const eq_js_1 = require("../u8a/eq.js");
|
||||
const u8a_js_1 = require("./u8a.js");
|
||||
const WASM_MAGIC = new Uint8Array([0, 97, 115, 109]); // \0asm
|
||||
/**
|
||||
* @name isWasm
|
||||
* @summary Tests if the input has a WASM header
|
||||
* @description
|
||||
* Checks to see if the input Uint8Array contains a valid WASM header
|
||||
*/
|
||||
function isWasm(value) {
|
||||
return (0, u8a_js_1.isU8a)(value) && (0, eq_js_1.u8aEq)(value.subarray(0, 4), WASM_MAGIC);
|
||||
}
|
||||
Reference in New Issue
Block a user