Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53249f51b8 | ||
|
|
4883106c3d | ||
|
|
b3f60da550 | ||
|
|
644f32dfaa | ||
|
|
bf4c6b497f | ||
|
|
a74ac0a0f9 | ||
|
|
6701f7420f | ||
|
|
8e43a2d105 | ||
|
|
9560301883 | ||
|
|
889bd36432 | ||
|
|
e310a63059 | ||
|
|
98082774f7 | ||
|
|
4d680f4b0c | ||
|
|
ff7c086b5b | ||
|
|
63b38c56ff | ||
|
|
8be38e40a1 | ||
|
|
9eb2f14dee | ||
|
|
733d7c1948 | ||
|
|
08ac55d7cd | ||
|
|
e2f5a85d14 | ||
|
|
77289d0ec0 | ||
|
|
29406a0010 | ||
|
|
006d55f5c1 | ||
|
|
650a3ca4a8 |
+2
-1
@@ -17,4 +17,5 @@
|
||||
|
||||
7.0.2
|
||||
7.0.3
|
||||
7.1.2
|
||||
7.1.2
|
||||
7.8.2
|
||||
@@ -1,5 +1,26 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 7.8.2 Nov 7, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Expose internal `isArray` check
|
||||
- Move `object{Property, Properties}` from api repo
|
||||
|
||||
|
||||
## 7.8.1 Nov 6, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Added Acala genesisHash (Thanks to https://github.com/qwer951123)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `objectClear` and `objectSpread` utility functions
|
||||
- Add `lazyMethod` & `lazyMethods` utility functions
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
|
||||
|
||||
## 7.7.1 Oct 31, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
+5
-5
@@ -10,7 +10,7 @@
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
@@ -21,16 +21,16 @@
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"networks:crosscheck": "polkadot-dev-run-test packages/networks/src/crosscheck",
|
||||
"networks:sync": "node packages/networks/scripts/fromSubstrate.mjs",
|
||||
"networks:sync": "yarn build && node packages/networks/scripts/fromSubstrate.mjs",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck --testPathIgnorePatterns toMiniSecretCmp",
|
||||
"test:mnemonicCmp": "polkadot-dev-run-test packages/util-crypto/src/mnemonic/toMiniSecretCmp.spec.ts",
|
||||
"test:one": "polkadot-dev-run-test --runInBand"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.15.8",
|
||||
"@polkadot/dev": "^0.63.18",
|
||||
"@polkadot/ts": "^0.4.12",
|
||||
"@babel/core": "^7.16.0",
|
||||
"@polkadot/dev": "^0.63.27",
|
||||
"@polkadot/ts": "^0.4.13",
|
||||
"@types/ed2curve": "^0.2.2",
|
||||
"@types/jest": "^27.0.2"
|
||||
},
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@ledgerhq/hw-transport": "^6.11.2",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.11.2",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.11.2"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '7.8.2' };
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/hw-ledger-transports": "7.7.1",
|
||||
"@polkadot/util": "7.7.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/hw-ledger-transports": "7.8.2",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@zondax/ledger-substrate": "^0.18.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '7.8.2' };
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
export type LedgerTypes = 'hid' | 'u2f' | 'webusb';
|
||||
|
||||
export interface AccountOptions {
|
||||
@@ -15,7 +17,7 @@ export interface LedgerAddress {
|
||||
}
|
||||
|
||||
export interface LedgerSignature {
|
||||
signature: string;
|
||||
signature: HexString;
|
||||
}
|
||||
|
||||
export interface LedgerVersion {
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/util": "7.7.1",
|
||||
"@polkadot/util-crypto": "7.7.1"
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/util-crypto": "7.8.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "7.7.1",
|
||||
"@polkadot/util-crypto": "7.7.1"
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/util-crypto": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '7.8.2' };
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { EncryptedJsonEncoding, Keypair, KeypairType } from '@polkadot/util
|
||||
import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta, SignOptions } from '../types';
|
||||
import type { PairInfo } from './types';
|
||||
|
||||
import { assert, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a, convertPublicKeyToCurve25519, convertSecretKeyToCurve25519, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, naclKeypairFromSeed as naclFromSeed, naclOpen, naclSeal, naclSign, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVrfSign, schnorrkelVrfVerify, secp256k1Compress, secp256k1Expand, secp256k1KeypairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify } from '@polkadot/util-crypto';
|
||||
|
||||
import { decodePair } from './decode';
|
||||
@@ -181,7 +181,7 @@ export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: P
|
||||
secretKey = new Uint8Array();
|
||||
},
|
||||
setMeta: (additional: KeyringPair$Meta): void => {
|
||||
meta = { ...meta, ...additional };
|
||||
meta = objectSpread({}, meta, additional);
|
||||
},
|
||||
sign: (message: HexString | string | Uint8Array, options: SignOptions = {}): Uint8Array => {
|
||||
assert(!isLocked(secretKey), 'Cannot sign with a locked key pair');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import type { KeyringPair$Json, KeyringPair$Meta } from '../types';
|
||||
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
import { jsonEncryptFormat } from '@polkadot/util-crypto';
|
||||
|
||||
interface PairStateJson {
|
||||
@@ -12,9 +13,8 @@ interface PairStateJson {
|
||||
}
|
||||
|
||||
export function pairToJson (type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
|
||||
return {
|
||||
...jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted),
|
||||
return objectSpread({}, jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
|
||||
address,
|
||||
meta
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4"
|
||||
"@babel/runtime": "^7.16.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "7.7.1",
|
||||
"@polkadot/x-fetch": "7.7.1"
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/x-fetch": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ export const substrateRegistry = 'https://raw.githubusercontent.com/paritytech/s
|
||||
// last. This make lookups for the current a simple genesisHash[0]
|
||||
// (See Kusama as an example)
|
||||
export const knownGenesis: KnownGenesis = {
|
||||
acala: [
|
||||
'0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c'
|
||||
],
|
||||
bifrost: [
|
||||
'0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed'
|
||||
],
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '7.8.2' };
|
||||
|
||||
@@ -270,13 +270,13 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Dhiway CORD Network',
|
||||
decimals: [12, 12],
|
||||
displayName: 'CORD Network',
|
||||
network: 'cord',
|
||||
prefix: 29,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['DCU'],
|
||||
website: 'https://dhiway.com/'
|
||||
symbols: ['DHI', 'WAY'],
|
||||
website: 'https://cord.network/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
@@ -638,6 +638,15 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
symbols: ['QTZ'],
|
||||
website: 'https://unique.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Pioneer Network by Bit.Country',
|
||||
network: 'pioneer_network',
|
||||
prefix: 268,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['NEER'],
|
||||
website: 'https://bit.country'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Moonbeam',
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/networks": "7.7.1",
|
||||
"@polkadot/util": "7.7.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/networks": "7.8.2",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"@polkadot/wasm-crypto": "^4.2.1",
|
||||
"@polkadot/x-randomvalues": "7.7.1",
|
||||
"@polkadot/x-randomvalues": "7.8.2",
|
||||
"base-x": "^3.0.9",
|
||||
"base64-js": "^1.5.1",
|
||||
"blakejs": "^1.1.1",
|
||||
@@ -46,11 +46,11 @@
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"@types/create-hash": "^1.2.2",
|
||||
"@types/elliptic": "^6.4.13",
|
||||
"@types/elliptic": "^6.4.14",
|
||||
"@types/scryptsy": "^2.0.0",
|
||||
"@types/xxhashjs": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "7.7.1"
|
||||
"@polkadot/util": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '7.8.2' };
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-textdecoder": "7.7.1",
|
||||
"@polkadot/x-textencoder": "7.7.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-textdecoder": "7.8.2",
|
||||
"@polkadot/x-textencoder": "7.8.2",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.12.0",
|
||||
"camelcase": "^6.2.0",
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { HexString, ToBn, ToBnOptions } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { u8aToHex } from '../u8a';
|
||||
import { bnToU8a } from './toU8a';
|
||||
|
||||
@@ -36,14 +37,14 @@ function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number
|
||||
return ZERO_STR;
|
||||
}
|
||||
|
||||
const _options = {
|
||||
isLe: false,
|
||||
isNegative: false,
|
||||
// Backwards-compatibility
|
||||
...(isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1)
|
||||
};
|
||||
|
||||
return u8aToHex(bnToU8a(value, _options));
|
||||
return u8aToHex(
|
||||
bnToU8a(value, objectSpread(
|
||||
{ isLe: false, isNegative: false },
|
||||
isNumber(arg1)
|
||||
? { bitLength: arg1, isLe: arg2 }
|
||||
: arg1
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
export { bnToHex };
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ToBn, ToBnOptions } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { bnToBn } from './toBn';
|
||||
|
||||
interface Options extends ToBnOptions {
|
||||
@@ -43,12 +44,12 @@ function createValue (valueBn: BN, byteLength: number, { isLe, isNegative }: Opt
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, options?: Options): Uint8Array;
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, bitLength?: number, isLe?: boolean): Uint8Array;
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, arg1: number | Options = { bitLength: -1, isLe: true, isNegative: false }, arg2?: boolean): Uint8Array {
|
||||
const options: Options = {
|
||||
bitLength: -1,
|
||||
isLe: true,
|
||||
isNegative: false,
|
||||
...isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1
|
||||
};
|
||||
const options: Options = objectSpread(
|
||||
{ bitLength: -1, isLe: true, isNegative: false },
|
||||
isNumber(arg1)
|
||||
? { bitLength: arg1, isLe: arg2 }
|
||||
: arg1
|
||||
);
|
||||
|
||||
const valueBn = bnToBn(value);
|
||||
const byteLength = options.bitLength === -1
|
||||
|
||||
@@ -15,9 +15,11 @@ export * from './extractTime';
|
||||
export * from './format';
|
||||
export * from './hex';
|
||||
export * from './is';
|
||||
export * from './lazy';
|
||||
export * from './logger';
|
||||
export * from './memoize';
|
||||
export * from './number';
|
||||
export * from './object';
|
||||
export * from './promisify';
|
||||
export * from './string';
|
||||
export * from './stringify';
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import type { Time } from './types';
|
||||
|
||||
import { objectSpread } from './object/spread';
|
||||
|
||||
const HRS = 60 * 60;
|
||||
const DAY = HRS * 24;
|
||||
|
||||
@@ -21,12 +23,12 @@ function addTime (a: Time, b: Time): Time {
|
||||
};
|
||||
}
|
||||
|
||||
const ZERO = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
||||
const ZERO: Time = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
||||
|
||||
function extractDays (milliseconds: number, hrs: number): Time {
|
||||
const days = Math.floor(hrs / 24);
|
||||
|
||||
return addTime({ ...ZERO, days }, extractTime(milliseconds - (days * DAY * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { days }), extractTime(milliseconds - (days * DAY * 1000)));
|
||||
}
|
||||
|
||||
function extractHrs (milliseconds: number, mins: number): Time {
|
||||
@@ -35,7 +37,7 @@ function extractHrs (milliseconds: number, mins: number): Time {
|
||||
if (hrs < 24) {
|
||||
const hours = Math.floor(hrs);
|
||||
|
||||
return addTime({ ...ZERO, hours }, extractTime(milliseconds - (hours * HRS * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { hours }), extractTime(milliseconds - (hours * HRS * 1000)));
|
||||
}
|
||||
|
||||
return extractDays(milliseconds, hrs);
|
||||
@@ -47,7 +49,7 @@ function extractMins (milliseconds: number, secs: number): Time {
|
||||
if (mins < 60) {
|
||||
const minutes = Math.floor(mins);
|
||||
|
||||
return addTime({ ...ZERO, minutes }, extractTime(milliseconds - (minutes * 60 * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { minutes }), extractTime(milliseconds - (minutes * 60 * 1000)));
|
||||
}
|
||||
|
||||
return extractHrs(milliseconds, mins);
|
||||
@@ -59,7 +61,7 @@ function extractSecs (milliseconds: number): Time {
|
||||
if (secs < 60) {
|
||||
const seconds = Math.floor(secs);
|
||||
|
||||
return addTime({ ...ZERO, seconds }, extractTime(milliseconds - (seconds * 1000)));
|
||||
return addTime(objectSpread({}, ZERO, { seconds }), extractTime(milliseconds - (seconds * 1000)));
|
||||
}
|
||||
|
||||
return extractMins(milliseconds, secs);
|
||||
@@ -81,7 +83,7 @@ export function extractTime (milliseconds?: number): Time {
|
||||
if (!milliseconds) {
|
||||
return ZERO;
|
||||
} else if (milliseconds < 1000) {
|
||||
return { ...ZERO, milliseconds };
|
||||
return objectSpread({}, ZERO, { milliseconds });
|
||||
}
|
||||
|
||||
return extractSecs(milliseconds);
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ToBnOptions } from '../types';
|
||||
|
||||
import { BN } from '../bn/bn';
|
||||
import { isBoolean } from '../is/boolean';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { hexStripPrefix } from './stripPrefix';
|
||||
|
||||
function reverse (value: string): string {
|
||||
@@ -36,16 +37,12 @@ export function hexToBn (value?: string | null, options: ToBnOptions | boolean =
|
||||
return new BN(0);
|
||||
}
|
||||
|
||||
const _options: ToBnOptions = {
|
||||
isLe: false,
|
||||
isNegative: false,
|
||||
// Backwards-compatibility
|
||||
...(
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
: options
|
||||
)
|
||||
};
|
||||
const _options: ToBnOptions = objectSpread(
|
||||
{ isLe: false, isNegative: false },
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
: options
|
||||
);
|
||||
const _value = hexStripPrefix(value);
|
||||
|
||||
// FIXME: Use BN's 3rd argument `isLe` once this issue is fixed
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* @name isArray
|
||||
* @summary Tests for a Array instance.
|
||||
*/
|
||||
export function isArray <T> (value: unknown): value is Array<T> {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isInstanceOf } from './instanceOf';
|
||||
|
||||
/**
|
||||
* @name isError
|
||||
* @summary Tests for a `Error` object instance.
|
||||
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
|
||||
* ```
|
||||
*/
|
||||
export function isError (value: unknown): value is Error {
|
||||
return isInstanceOf(value, Error);
|
||||
return value instanceof Error;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
/**
|
||||
* @summary Type checking utilities
|
||||
*/
|
||||
export { isArray } from './array';
|
||||
export { isAscii } from './ascii';
|
||||
export { isBigInt } from './bigInt';
|
||||
export { isBn } from './bn';
|
||||
|
||||
@@ -5,8 +5,7 @@ import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
|
||||
interface Observable {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
next: (...params: any[]) => any;
|
||||
next: (...params: unknown[]) => unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isInstanceOf } from './instanceOf';
|
||||
|
||||
/**
|
||||
* @name isU8a
|
||||
* @summary Tests for a `Uint8Array` object instance.
|
||||
@@ -18,5 +16,5 @@ import { isInstanceOf } from './instanceOf';
|
||||
* ```
|
||||
*/
|
||||
export function isU8a (value?: unknown): value is Uint8Array {
|
||||
return isInstanceOf(value, Uint8Array);
|
||||
return value instanceof Uint8Array;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isUndefined } from './is/undefined';
|
||||
|
||||
type AnyFn = (...args: unknown[]) => unknown;
|
||||
|
||||
type WithToString = { toString: () => string };
|
||||
|
||||
export function lazyMethod <T, K> (result: Record<string, T> | AnyFn, item: K, creator: (d: K) => T, getName?: (d: K) => string): void {
|
||||
const name = getName
|
||||
? getName(item)
|
||||
: (item as WithToString).toString();
|
||||
let value: T | undefined;
|
||||
|
||||
Object.defineProperty(result, name, {
|
||||
// This allows for re-configuration with the embedded defineProperty below
|
||||
// and ensures that on tested browsers and Node, it _will_ be redefined
|
||||
// and thus short-circuited for future access
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
|
||||
// Use a function here, we don't want to capture the outer this, i.e.
|
||||
// don't use arrow functions in this context since we have a this inside
|
||||
get: function (): T {
|
||||
// This check should _always_ be false and unneeded, since we override
|
||||
// with a value below ... however we ensure we are quire vigilant against
|
||||
// all environment failures, so we are rather be safe than sorry
|
||||
if (isUndefined(value)) {
|
||||
value = creator(item);
|
||||
|
||||
try {
|
||||
// re-define the property as a value, next time around this
|
||||
// getter will only return the computed value
|
||||
Object.defineProperty(this, name, { value });
|
||||
} catch {
|
||||
// ignore any errors, since this _should_ not happen due to
|
||||
// the "configurable" property above. But if it ever does
|
||||
// from here-on we will be the cached value the next time
|
||||
// around (with a very slight dip in performance)
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function lazyMethods <T, K> (result: Record<string, T>, items: K[], creator: (v: K) => T, getName?: (m: K) => string): Record<string, T> {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
lazyMethod(result, items[i], creator, getName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { objectClear } from '.';
|
||||
|
||||
describe('objectClear', (): void => {
|
||||
it('clears an object', (): void => {
|
||||
expect(
|
||||
objectClear({ a: 1, b: 2, c: { d: 3, e: 4 } })
|
||||
).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function objectClear <T> (value: Record<string, T>): Record<string, T> {
|
||||
const keys = Object.keys(value);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
delete value[keys[i]];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { objectSpread } from './spread';
|
||||
|
||||
export function objectCopy <T extends object> (source: T): T {
|
||||
return objectSpread({}, source);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { objectClear } from './clear';
|
||||
export { objectCopy } from './copy';
|
||||
export { objectProperty, objectProperties } from './property';
|
||||
export { objectSpread } from './spread';
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isUndefined } from '../is/undefined';
|
||||
|
||||
export function objectProperty (that: object, key: string, getter: (k: string) => unknown): void {
|
||||
// We use both the hasOwnProperty as well as isUndefined checks here, since it may be set
|
||||
// in inherited classes and _Own_ properties refers to the class only, not only parents
|
||||
if (!Object.prototype.hasOwnProperty.call(that, key) && isUndefined((that as Record<string, unknown>)[key])) {
|
||||
const get = () => getter(key);
|
||||
|
||||
Object.defineProperty(that, key, { enumerable: true, get });
|
||||
}
|
||||
}
|
||||
|
||||
export function objectProperties (that: object, keys: string[], getter: (k: string, i: number) => unknown): void {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
objectProperty(that, keys[i], (k) => getter(k, i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { objectSpread } from '.';
|
||||
|
||||
describe('objectSpread', (): void => {
|
||||
it('spreads an object from multiple sources', (): void => {
|
||||
expect(
|
||||
objectSpread({ a: 1 }, { b: 2 }, { a: 2, c: { d: 3, e: 4 } })
|
||||
).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } });
|
||||
});
|
||||
|
||||
it('spreads an object from multiple sources (with null & undefined)', (): void => {
|
||||
expect(
|
||||
objectSpread({ a: 1 }, null, { b: 2 }, undefined, { a: 2, c: { d: 3, e: 4 } })
|
||||
).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function objectSpread <T extends object> (dest: object, ...sources: (object | undefined | null)[]): T {
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const src = sources[i];
|
||||
|
||||
if (src) {
|
||||
const keys = Object.keys(src);
|
||||
|
||||
for (let j = 0; j < keys.length; j++) {
|
||||
const key = keys[j];
|
||||
|
||||
(dest as Record<string, unknown>)[key] = (src as Record<string, unknown>)[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dest as T;
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/util', version: '7.8.2' };
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/util": "7.7.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/util": "7.8.2",
|
||||
"buffer-es6": "^4.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', version: '7.8.2' };
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-global": "7.7.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-global": "7.8.2",
|
||||
"@types/node-fetch": "^2.5.12",
|
||||
"node-fetch": "^2.6.5"
|
||||
"node-fetch": "^2.6.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', version: '7.8.2' };
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4"
|
||||
"@babel/runtime": "^7.16.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-global', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-global', version: '7.8.2' };
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-global": "7.7.1"
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-global": "7.8.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-native": "^0.66.1"
|
||||
"@types/react-native": "^0.66.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '7.8.2' };
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-global": "7.7.1"
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-global": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '7.8.2' };
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-global": "7.7.1"
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-global": "7.8.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', version: '7.8.2' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "7.7.1",
|
||||
"version": "7.8.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/x-global": "7.7.1",
|
||||
"@babel/runtime": "^7.16.0",
|
||||
"@polkadot/x-global": "7.8.2",
|
||||
"@types/websocket": "^1.0.4",
|
||||
"websocket": "^1.0.34"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-ws', version: '7.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-ws', version: '7.8.2' };
|
||||
|
||||
Reference in New Issue
Block a user