Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46a05b6a60 | ||
|
|
a9f671b501 | ||
|
|
f1187f5981 | ||
|
|
4134bf8a85 | ||
|
|
4709a62c0b | ||
|
|
900cf21bc5 | ||
|
|
fa8229de06 | ||
|
|
913bf65dab | ||
|
|
769b953983 | ||
|
|
2949e12c55 | ||
|
|
1664a8d8a2 | ||
|
|
ab71a25b96 | ||
|
|
02c1a95ea1 | ||
|
|
3ee6830c0e | ||
|
|
642724ab6d | ||
|
|
022756e6dd | ||
|
|
e29003f51e |
@@ -1,5 +1,19 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 10.4.1 Feb 12, 2023
|
||||
|
||||
Contributed:
|
||||
|
||||
- Locale support for number formatting (Thanks to https://github.com/alko89)
|
||||
- Ledger support for Picasso (Thanks to https://github.com/carlosala)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `isClass` helper (checks if input is actual Class Constructor)
|
||||
- Adjust `isChildClass` to rely on new `isClass`
|
||||
- Upgrade dependencies to latest stable versions
|
||||
|
||||
|
||||
## 10.3.1 Jan 28, 2023
|
||||
|
||||
Contributed:
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
1521 Jaco 10.3.1 (#1719)
|
||||
10 Carlo Sala feat(networks): support ledger for ajuna (#1682)
|
||||
1528 Jaco 10.4.1 (#1728)
|
||||
11 Carlo Sala feat(networks): support ledger for picasso (#1725)
|
||||
9 Antoine Estienne Add eth uri keyring test (#1291)
|
||||
6 Amaury Martiny Add tests from Rust (#283)
|
||||
5 Jakub Pánik Add HydraDX parachain to genesis (#1583)
|
||||
@@ -16,6 +16,7 @@
|
||||
2 Nantian fix bigint type (#1079)
|
||||
2 Stefanie Doll Add missing dependencies to util-crypto (#424)
|
||||
1 Agustinus Theodorus docs: fix typo in naclSeal docs. (#1005)
|
||||
1 Aleš Ferlan feat: allow setting of thousand/decimal separators (#1722)
|
||||
1 Alex Sedighi fix Nodle's known network name (#1699)
|
||||
1 Alexander Krupenkin Added ECDSA keypair support (#589)
|
||||
1 alexdniep added equilibrium slip44; added equilibrium genesis hash (#984)
|
||||
|
||||
+6
-5
@@ -11,10 +11,10 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"versions": {
|
||||
"git": "10.3.1",
|
||||
"npm": "10.3.1"
|
||||
"git": "10.4.1",
|
||||
"npm": "10.4.1"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
@@ -30,14 +30,15 @@
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "NODE_OPTIONS=--experimental-vm-modules 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:node": "polkadot-dev-run-node-test",
|
||||
"test:one": "polkadot-dev-run-test --runInBand"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.12",
|
||||
"@polkadot/dev": "^0.68.2",
|
||||
"@polkadot/dev": "^0.68.18",
|
||||
"@types/jest": "^29.4.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"typescript": "^4.9.4"
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@ledgerhq/hw-transport": "^6.27.10",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.27.10",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.27.10",
|
||||
"@polkadot/util": "10.3.1"
|
||||
"@ledgerhq/hw-transport": "^6.28.0",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.27.11",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.27.11",
|
||||
"@polkadot/util": "10.4.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.7"
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@ledgerhq/hw-transport": "^6.27.10",
|
||||
"@polkadot/hw-ledger-transports": "10.3.1",
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@ledgerhq/hw-transport": "^6.28.0",
|
||||
"@polkadot/hw-ledger-transports": "10.4.1",
|
||||
"@polkadot/util": "10.4.1",
|
||||
"@zondax/ledger-substrate": "^0.40.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ export const ledgerApps: Record<string, string> = {
|
||||
origintrail: 'OriginTrail',
|
||||
parallel: 'Parallel',
|
||||
phala: 'Phala',
|
||||
picasso: 'Picasso',
|
||||
polkadex: 'Polkadex',
|
||||
polkadot: 'Polkadot',
|
||||
polymesh: 'Polymesh',
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@polkadot/util-crypto": "10.3.1"
|
||||
"@polkadot/util": "10.4.1",
|
||||
"@polkadot/util-crypto": "10.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@polkadot/util-crypto": "10.3.1"
|
||||
"@polkadot/util": "10.4.1",
|
||||
"@polkadot/util-crypto": "10.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@polkadot/util": "10.4.1",
|
||||
"@substrate/ss58-registry": "^1.38.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/hw-ledger": "10.3.1"
|
||||
"@polkadot/hw-ledger": "10.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ export const knownGenesis: KnownGenesis = {
|
||||
'0x1bb969d85965e4bb5a651abbedf21a54b6b31a21f66b5401cc3f1e286268d736'
|
||||
],
|
||||
picasso: [
|
||||
'0x6811a339673c9daa897944dcdac99c6e2939cc88245ed21951a0a3c9a2be75bc',
|
||||
'0xe8e7f0f4c4f5a00720b4821dbfddefea7490bcf0b19009961cc46957984e2c1c'
|
||||
],
|
||||
polkadex: [
|
||||
|
||||
@@ -30,6 +30,7 @@ export const knownLedger: KnownLedger = {
|
||||
origintrail: 0x00000162,
|
||||
parallel: 0x00000162,
|
||||
phala: 0x00000162,
|
||||
picasso: 0x000001b2,
|
||||
polkadex: 0x0000031f,
|
||||
polkadot: 0x00000162,
|
||||
polymesh: 0x00000253,
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -5,7 +5,7 @@ import known from '@substrate/ss58-registry';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import other from './test/ss58registry.test.json';
|
||||
import other from './test/ss58registry.test.json' assert { type: 'json' };
|
||||
|
||||
describe('@substrate/ss58-registry', (): void => {
|
||||
it('has known values', (): void => {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": {
|
||||
"crypto": false,
|
||||
"stream": false
|
||||
@@ -30,13 +30,13 @@
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@noble/hashes": "1.1.5",
|
||||
"@noble/hashes": "1.2.0",
|
||||
"@noble/secp256k1": "1.7.1",
|
||||
"@polkadot/networks": "10.3.1",
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@polkadot/networks": "10.4.1",
|
||||
"@polkadot/util": "10.4.1",
|
||||
"@polkadot/wasm-crypto": "^6.4.1",
|
||||
"@polkadot/x-bigint": "10.3.1",
|
||||
"@polkadot/x-randomvalues": "10.3.1",
|
||||
"@polkadot/x-bigint": "10.4.1",
|
||||
"@polkadot/x-randomvalues": "10.4.1",
|
||||
"@scure/base": "1.1.1",
|
||||
"ed2curve": "^0.3.0",
|
||||
"tweetnacl": "^1.0.3"
|
||||
@@ -45,6 +45,6 @@
|
||||
"@types/ed2curve": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "10.3.1"
|
||||
"@polkadot/util": "10.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -34,18 +34,18 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-bigint": "10.3.1",
|
||||
"@polkadot/x-global": "10.3.1",
|
||||
"@polkadot/x-textdecoder": "10.3.1",
|
||||
"@polkadot/x-textencoder": "10.3.1",
|
||||
"@polkadot/x-bigint": "10.4.1",
|
||||
"@polkadot/x-global": "10.4.1",
|
||||
"@polkadot/x-textdecoder": "10.4.1",
|
||||
"@polkadot/x-textencoder": "10.4.1",
|
||||
"@types/bn.js": "^5.1.1",
|
||||
"bn.js": "^5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/x-randomvalues": "10.3.1"
|
||||
"@polkadot/x-randomvalues": "10.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +189,24 @@ describe('formatBalance', (): void => {
|
||||
formatBalance(TESTVAL, { decimals: 15, forceUnit: 'µ' })
|
||||
).toEqual('123.4567 µUnit');
|
||||
});
|
||||
|
||||
it('formats 123,456 (decimals=0, locale=sl)', (): void => {
|
||||
expect(
|
||||
formatBalance(123456, { decimals: 0, locale: 'sl', withSi: true })
|
||||
).toEqual('123,4560 kUnit');
|
||||
});
|
||||
|
||||
it('formats BigInt numbers (locale=sl)', (): void => {
|
||||
expect(
|
||||
formatBalance(123456789000n, { decimals: 15, locale: 'sl', withSi: true })
|
||||
).toEqual('123,4567 µUnit');
|
||||
});
|
||||
|
||||
it('formats 123,456,789,000 (decimals=7, forceUnit=base locale=sl)', (): void => {
|
||||
expect(
|
||||
formatBalance(TESTVAL, { decimals: 7, forceUnit: '-', locale: 'sl' })
|
||||
).toEqual('12.345,6789 Unit');
|
||||
});
|
||||
});
|
||||
|
||||
describe('calcSi', (): void => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { SiDef, ToBn } from '../types';
|
||||
import { bnToBn } from '../bn/toBn';
|
||||
import { isBoolean } from '../is/boolean';
|
||||
import { formatDecimal } from './formatDecimal';
|
||||
import { getSeparator } from './getSeparator';
|
||||
import { calcSi, findSi, SI, SI_MID } from './si';
|
||||
|
||||
interface Defaults {
|
||||
@@ -48,6 +49,10 @@ interface Options {
|
||||
* @description Returns all trailing zeros, otherwise removes (default = true)
|
||||
*/
|
||||
withZero?: boolean;
|
||||
/**
|
||||
* @description The locale to use
|
||||
*/
|
||||
locale?: string;
|
||||
}
|
||||
|
||||
interface BalanceFormatter {
|
||||
@@ -66,7 +71,7 @@ let defaultDecimals = DEFAULT_DECIMALS;
|
||||
let defaultUnit = DEFAULT_UNIT;
|
||||
|
||||
// Formats a string/number with <prefix>.<postfix><type> notation
|
||||
function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, { decimals = defaultDecimals, forceUnit, withAll = false, withSi = true, withSiFull = false, withUnit = true, withZero = true }: Options = {}): string {
|
||||
function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, { decimals = defaultDecimals, forceUnit, withAll = false, withSi = true, withSiFull = false, withUnit = true, withZero = true, locale = 'en' }: Options = {}): string {
|
||||
// we only work with string inputs here - convert anything
|
||||
// into the string-only value
|
||||
let text = bnToBn(input).toString();
|
||||
@@ -127,7 +132,9 @@ function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | b
|
||||
: ` ${withSiFull ? `${si.text}${withUnit ? ' ' : ''}` : si.value}${withUnit ? unit : ''}`
|
||||
: '';
|
||||
|
||||
return `${sign}${formatDecimal(pre)}${post && `.${post}`}${units}`;
|
||||
const { decimal, thousand } = getSeparator(locale);
|
||||
|
||||
return `${sign}${formatDecimal(pre, thousand)}${post && `${decimal}${post}`}${units}`;
|
||||
}
|
||||
|
||||
export const formatBalance = _formatBalance as BalanceFormatter;
|
||||
|
||||
@@ -6,9 +6,9 @@ const NUMBER_REGEX = new RegExp('(\\d+?)(?=(\\d{3})+(?!\\d)|$)', 'g');
|
||||
|
||||
/**
|
||||
* @name formatDecimal
|
||||
* @description Formats a number into string format with thousand seperators
|
||||
* @description Formats a number into string format with thousand separators
|
||||
*/
|
||||
export function formatDecimal (value: string): string {
|
||||
export function formatDecimal (value: string, separator = ','): string {
|
||||
// We can do this by adjusting the regx, however for the sake of clarity
|
||||
// we rather strip and re-add the negative sign in the output
|
||||
const isNegative = value[0].startsWith('-');
|
||||
@@ -17,6 +17,6 @@ export function formatDecimal (value: string): string {
|
||||
: value.match(NUMBER_REGEX);
|
||||
|
||||
return matched
|
||||
? `${isNegative ? '-' : ''}${matched.join(',')}`
|
||||
? `${isNegative ? '-' : ''}${matched.join(separator)}`
|
||||
: value;
|
||||
}
|
||||
|
||||
@@ -37,4 +37,22 @@ describe('formatNumber', (): void => {
|
||||
})
|
||||
).toEqual('12,345');
|
||||
});
|
||||
|
||||
it('formats negative numbers (locale=sl)', (): void => {
|
||||
expect(
|
||||
formatNumber(-123456, { locale: 'sl' })
|
||||
).toEqual('-123.456');
|
||||
});
|
||||
|
||||
it('formats BN numbers (locale=sl)', (): void => {
|
||||
expect(
|
||||
formatNumber(new BN(12345), { locale: 'sl' })
|
||||
).toEqual('12.345');
|
||||
});
|
||||
|
||||
it('formats BigInt numbers (locale=sl)', (): void => {
|
||||
expect(
|
||||
formatNumber(123456789n, { locale: 'sl' })
|
||||
).toEqual('123.456.789');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,11 +6,24 @@ import type { ToBn } from '../types';
|
||||
|
||||
import { bnToBn } from '../bn/toBn';
|
||||
import { formatDecimal } from './formatDecimal';
|
||||
import { getSeparator } from './getSeparator';
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* @description The locale to use
|
||||
*/
|
||||
locale?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name formatNumber
|
||||
* @description Formats a number into string format with thousand seperators
|
||||
* @description Formats a number into string format with thousand separators
|
||||
*/
|
||||
export function formatNumber <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null): string {
|
||||
return formatDecimal(bnToBn(value).toString());
|
||||
export function formatNumber <ExtToBn extends ToBn> (
|
||||
value?: ExtToBn | BN | bigint | number | null,
|
||||
{ locale = 'en' }: Options = {}
|
||||
): string {
|
||||
const { thousand } = getSeparator(locale);
|
||||
|
||||
return formatDecimal(bnToBn(value).toString(), thousand);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { getSeparator } from './getSeparator';
|
||||
|
||||
describe('getSeparator', (): void => {
|
||||
it('uses system locale', (): void => {
|
||||
const n = 1000.1;
|
||||
const locale = {
|
||||
decimal: n.toLocaleString().substring(5, 6),
|
||||
thousand: n.toLocaleString().substring(1, 2)
|
||||
};
|
||||
|
||||
expect(
|
||||
getSeparator()
|
||||
).toEqual(locale);
|
||||
});
|
||||
|
||||
it('uses en locale', (): void => {
|
||||
expect(
|
||||
getSeparator('en')
|
||||
).toEqual({
|
||||
decimal: '.',
|
||||
thousand: ','
|
||||
});
|
||||
});
|
||||
|
||||
it('uses en-gb locale', (): void => {
|
||||
expect(
|
||||
getSeparator('en-gb')
|
||||
).toEqual({
|
||||
decimal: '.',
|
||||
thousand: ','
|
||||
});
|
||||
});
|
||||
|
||||
it('uses sl locale', (): void => {
|
||||
expect(
|
||||
getSeparator('sl')
|
||||
).toEqual({
|
||||
decimal: ',',
|
||||
thousand: '.'
|
||||
});
|
||||
});
|
||||
|
||||
it('uses sl-si locale', (): void => {
|
||||
expect(
|
||||
getSeparator('sl-si')
|
||||
).toEqual({
|
||||
decimal: ',',
|
||||
thousand: '.'
|
||||
});
|
||||
});
|
||||
|
||||
it('uses it-it locale', (): void => {
|
||||
expect(
|
||||
getSeparator('it-it')
|
||||
).toEqual({
|
||||
decimal: ',',
|
||||
thousand: '.'
|
||||
});
|
||||
});
|
||||
|
||||
it('uses ja-jp locale', (): void => {
|
||||
expect(
|
||||
getSeparator('ja-jp')
|
||||
).toEqual({
|
||||
decimal: '.',
|
||||
thousand: ','
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* Get the decimal and thousand separator of a locale
|
||||
* @param locale
|
||||
* @returns {decimal: string, thousand: string}
|
||||
*/
|
||||
export function getSeparator (locale?: string):
|
||||
{ thousand: string, decimal: string } {
|
||||
return {
|
||||
decimal: (0.1).toLocaleString(locale).substring(1, 2),
|
||||
thousand: (1000).toLocaleString(locale).substring(1, 2)
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
import type { Constructor } from '../types';
|
||||
|
||||
import { isClass } from './class';
|
||||
|
||||
/**
|
||||
* @name isChildClass
|
||||
* @summary Tests if the child extends the parent Class
|
||||
@@ -20,8 +22,8 @@ import type { Constructor } from '../types';
|
||||
*/
|
||||
export function isChildClass <P extends Constructor> (Parent: P, Child?: Constructor | null | unknown): Child is P {
|
||||
// https://stackoverflow.com/questions/30993434/check-if-a-constructor-inherits-another-in-es6/30993664
|
||||
return Child
|
||||
return isClass(Child) && isClass(Parent)
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
? Parent === Child || Parent.isPrototypeOf(Child as Constructor)
|
||||
? Parent === Child || Parent.isPrototypeOf(Child)
|
||||
: false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { BN } from '../bn';
|
||||
import { isClass } from '.';
|
||||
|
||||
describe('isClass', (): void => {
|
||||
it('returns false on a pure object', (): void => {
|
||||
expect(isClass({})).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false on instance values', (): void => {
|
||||
expect(
|
||||
isClass(new BN(1))
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns true when a class value', (): void => {
|
||||
expect(
|
||||
isClass(BN)
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns true on extends', (): void => {
|
||||
expect(
|
||||
isClass(class Test extends BN {})
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns true on built-ins', (): void => {
|
||||
expect(
|
||||
isClass(Uint8Array)
|
||||
).toEqual(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor } from '../types';
|
||||
|
||||
import { isOnFunction } from './helpers';
|
||||
|
||||
/**
|
||||
* @name isClass
|
||||
* Tests if the supplied agrument is a Class
|
||||
*/
|
||||
export const isClass: <T extends Constructor> (value?: unknown) => value is T = /*#__PURE__*/ isOnFunction('isPrototypeOf', 'hasOwnProperty');
|
||||
@@ -10,6 +10,12 @@ export function isOn <T> (...fns: (keyof T)[]): (value?: unknown) => value is T
|
||||
fns.every((f) => isFunction((value as T)[f]));
|
||||
}
|
||||
|
||||
export function isOnFunction <T> (...fns: (keyof T)[]): (value?: unknown) => value is T {
|
||||
return (value?: unknown): value is T =>
|
||||
isFunction(value) &&
|
||||
fns.every((f) => isFunction((value as T)[f]));
|
||||
}
|
||||
|
||||
export function isOnObject <T> (...fns: (keyof T)[]): (value?: unknown) => value is T {
|
||||
return (value?: unknown): value is T =>
|
||||
isObject(value) &&
|
||||
|
||||
@@ -11,6 +11,7 @@ export { isBn } from './bn';
|
||||
export { isBuffer } from './buffer';
|
||||
export { isBoolean } from './boolean';
|
||||
export { isChildClass } from './childClass';
|
||||
export { isClass } from './class';
|
||||
export { isCodec } from './codec';
|
||||
export { isCompact } from './compact';
|
||||
export { isError } from './error';
|
||||
|
||||
Vendored
-11
@@ -1,11 +0,0 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Be able to import json in TS
|
||||
// https://stackoverflow.com/questions/49996456/importing-json-file-in-typescript
|
||||
declare module '*.json' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const value: any;
|
||||
|
||||
export default value;
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/util', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -33,7 +33,7 @@ function formatAllCaps (w: string): string {
|
||||
function converter (format: (w: string, i: number) => string): (value: AnyString) => string {
|
||||
return (value: AnyString): string => {
|
||||
const parts = value
|
||||
// replace all seperators (including consequtive) with spaces
|
||||
// replace all separators (including consequtive) with spaces
|
||||
.replace(/[-_., ]+/g, ' ')
|
||||
// we don't want leading or trailing spaces
|
||||
.trim()
|
||||
|
||||
@@ -36,7 +36,7 @@ export function formatOps (count: number, time: number): string {
|
||||
|
||||
return `
|
||||
${formatFixed(ops).padStart(NUM_PAD + PRE_PAD + 1)} ops/s
|
||||
${formatFixed(micro).padStart(NUM_PAD + PRE_PAD + 1)} μs/op`;
|
||||
${formatFixed(micro).padStart(NUM_PAD + PRE_PAD + 1)} us/op`; // μ
|
||||
}
|
||||
|
||||
export function perf (name: string, count: number, inputs: readonly unknown[][], exec: ExecFn, withLog?: boolean): void {
|
||||
|
||||
@@ -7,6 +7,10 @@ import type { BN } from './bn/bn';
|
||||
export interface Constructor<T = any> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
new(...value: any[]): T;
|
||||
|
||||
hasOwnProperty (prop: string): boolean;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
isPrototypeOf (other: any): boolean;
|
||||
}
|
||||
|
||||
export interface ToBigInt {
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
"./shim.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-global": "10.3.1"
|
||||
"@polkadot/x-global": "10.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-bigint', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bigint', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@polkadot/util": "10.4.1",
|
||||
"buffer-es6": "^4.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-global": "10.3.1",
|
||||
"@polkadot/x-global": "10.4.1",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"node-fetch": "^3.3.0"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-global', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-global', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-global": "10.3.1"
|
||||
"@polkadot/x-global": "10.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "10.3.1",
|
||||
"@types/react-native": "^0.71.0"
|
||||
"@polkadot/util": "10.4.1",
|
||||
"@types/react-native": "^0.71.2"
|
||||
},
|
||||
"denoDependencies": {
|
||||
"crypto": "std@0.161.0/node/crypto.ts"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-global": "10.3.1"
|
||||
"@polkadot/x-global": "10.4.1"
|
||||
},
|
||||
"denoDependencies": {
|
||||
"util": "std@0.161.0/node/util.ts"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-global": "10.3.1"
|
||||
"@polkadot/x-global": "10.4.1"
|
||||
},
|
||||
"denoDependencies": {
|
||||
"util": "std@0.161.0/node/util.ts"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.3.1",
|
||||
"version": "10.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.20.13",
|
||||
"@polkadot/x-global": "10.3.1",
|
||||
"@polkadot/x-global": "10.4.1",
|
||||
"@types/websocket": "^1.0.5",
|
||||
"websocket": "^1.0.34"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-ws', path: 'auto', type: 'auto', version: '10.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-ws', path: 'auto', type: 'auto', version: '10.4.1' };
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"@polkadot/x-textencoder": ["x-textencoder/src/browser"],
|
||||
"@polkadot/x-ws": ["x-ws/src/browser"]
|
||||
},
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"target": "es2020"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user