Compare commits

...
39 Commits
Author SHA1 Message Date
github-actions[bot] 9830457c9a [CI Skip] release/stable 10.4.2
skip-checks: true
2023-02-19 08:15:26 +00:00
Jaco 4619ab6668 10.4.2 (#1741)
* 10.4.2

* dep up changelog entry
2023-02-19 10:11:47 +02:00
github-actions[bot] d886c02b23 [CI Skip] bump/beta 10.4.2-8-x
skip-checks: true
2023-02-18 11:13:59 +00:00
Jaco 7d745661b7 Bump deps (#1740)
* Bump deps

* lint fixes
2023-02-18 13:10:13 +02:00
github-actions[bot] da9c2bc10b [CI Skip] bump/beta 10.4.2-7-x
skip-checks: true
2023-02-16 12:53:16 +00:00
Carlo Sala eab8d44487 feat(networks): support ledger for pendulum (#1739) 2023-02-16 14:49:31 +02:00
github-actions[bot] 19ecae37dd [CI Skip] bump/beta 10.4.2-6-x
skip-checks: true
2023-02-15 14:44:23 +00:00
Jaco 3d3e46cb77 Adjust performance compare (#1738) 2023-02-15 16:40:39 +02:00
github-actions[bot] e09027e83d [CI Skip] bump/beta 10.4.2-5-x
skip-checks: true
2023-02-15 09:58:19 +00:00
Jaco c544e0b478 Bump deps (#1737) 2023-02-15 11:53:55 +02:00
github-actions[bot] f914061365 [CI Skip] bump/beta 10.4.2-4-x
skip-checks: true
2023-02-15 07:19:59 +00:00
Jaco 55e4e8209e Fix CI release workflow (#1736) 2023-02-15 09:15:27 +02:00
Jaco 193c9ebb37 Reset global formatBalance test side effects (#1735) 2023-02-15 08:07:56 +02:00
Jaco 5d67d92454 Use latest LTS for CI scripts (#1734) 2023-02-14 10:46:54 +02:00
github-actions[bot] 3a0d566f60 [CI Skip] bump/beta 10.4.2-3-x
skip-checks: true
2023-02-13 17:44:09 +00:00
Jaco 675f1e71b5 Bump dev (#1733) 2023-02-13 19:40:12 +02:00
github-actions[bot] 4bbf38c7e4 [CI Skip] bump/beta 10.4.2-2-x
skip-checks: true
2023-02-13 08:30:36 +00:00
Jaco fd76246c11 Enufer u8aToU8a(Buffer) return non-Buffer instance (#1731) 2023-02-13 10:26:46 +02:00
github-actions[bot] 0b14539a98 [CI Skip] bump/beta 10.4.2-1-x
skip-checks: true
2023-02-12 11:54:19 +00:00
Jaco 09b1a0e6e3 Bump dev (#1730) 2023-02-12 13:50:35 +02:00
github-actions[bot] 03e64c9120 [CI Skip] bump/beta 10.4.2-0-x
skip-checks: true
2023-02-12 10:58:52 +00:00
Jaco f848c87fde Remove it.concurrent (jest advises against use) (#1729) 2023-02-12 12:55:02 +02:00
github-actions[bot] 46a05b6a60 [CI Skip] release/stable 10.4.1
skip-checks: true
2023-02-12 09:19:44 +00:00
Jaco a9f671b501 10.4.1 (#1728) 2023-02-12 11:14:33 +02:00
github-actions[bot] f1187f5981 [CI Skip] bump/beta 10.3.2-6-x
skip-checks: true
2023-02-11 15:55:56 +00:00
Jaco 4134bf8a85 Bump deps (#1727) 2023-02-11 17:52:08 +02:00
github-actions[bot] 4709a62c0b [CI Skip] bump/beta 10.3.2-5-x
skip-checks: true
2023-02-07 13:11:55 +00:00
Jaco 900cf21bc5 Bump deps (#1726) 2023-02-07 15:08:02 +02:00
github-actions[bot] fa8229de06 [CI Skip] bump/beta 10.3.2-4-x
skip-checks: true
2023-02-07 13:00:21 +00:00
Aleš Ferlan 913bf65dab feat: allow setting of thousand/decimal separators (#1722)
* feat: allow setting of thousand/decimal separators

* fix: add file header and fix lint errors

* fix: move getSeparator to format
2023-02-07 14:56:27 +02:00
Carlo Sala 769b953983 feat(networks): support ledger for picasso (#1725) 2023-02-07 14:55:00 +02:00
github-actions[bot] 2949e12c55 [CI Skip] bump/beta 10.3.2-3-x
skip-checks: true
2023-02-05 12:11:05 +00:00
Jaco 1664a8d8a2 Bump dev (#1724) 2023-02-05 14:05:53 +02:00
github-actions[bot] ab71a25b96 [CI Skip] bump/beta 10.3.2-2-x
skip-checks: true
2023-02-05 07:55:38 +00:00
Jaco 02c1a95ea1 Bump dev (#1723) 2023-02-05 09:51:48 +02:00
github-actions[bot] 3ee6830c0e [CI Skip] bump/beta 10.3.2-1-x
skip-checks: true
2023-02-03 08:52:36 +00:00
Jaco 642724ab6d Bump deps (incl. TS) (#1721) 2023-02-03 10:48:19 +02:00
github-actions[bot] 022756e6dd [CI Skip] bump/beta 10.3.2-0-x
skip-checks: true
2023-02-03 08:02:56 +00:00
Jaco e29003f51e Add isClass helper (#1720)
* Add isClass helper

* add isOnFunction helper
2023-02-03 09:59:18 +02:00
57 changed files with 2461 additions and 1030 deletions
+4 -1
View File
@@ -12,7 +12,10 @@ jobs:
YARN_ENABLE_SCRIPTS: false
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
- uses: denoland/setup-deno@004814556e37c54a2f6e31384c9e18e983317366
with:
deno-version: vx.x.x
+4 -1
View File
@@ -19,10 +19,13 @@ jobs:
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT_BOT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT_BOT }}
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
- name: ${{ matrix.step }}
run: |
yarn install --immutable | grep -v 'YN0013'
+26
View File
@@ -1,5 +1,31 @@
# CHANGELOG
## 10.4.2 Feb 19, 2023
Contributed:
- Ledger support for Pendulum (Thanks to https://github.com/carlosala)
Changes:
- Ensure `u8aToU8a` correctly unwraps Buffer value (check ordering)
- Upgrade dependencies to latest stable versions
## 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
View File
@@ -1,5 +1,5 @@
1521 Jaco 10.3.1 (#1719)
10 Carlo Sala feat(networks): support ledger for ajuna (#1682)
1539 Jaco 10.4.2 (#1741)
12 Carlo Sala feat(networks): support ledger for pendulum (#1739)
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)
+7 -6
View File
@@ -11,10 +11,10 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"versions": {
"git": "10.3.1",
"npm": "10.3.1"
"git": "10.4.2",
"npm": "10.4.2"
},
"workspaces": [
"packages/*"
@@ -28,16 +28,17 @@
"deno": "yarn polkadot-dev-deno-map && yarn build && deno check --import-map=import_map.json mod.ts",
"lint": "polkadot-dev-run-lint",
"postinstall": "polkadot-dev-yarn-only",
"test": "NODE_OPTIONS=--experimental-vm-modules polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns crosscheck --testPathIgnorePatterns toMiniSecretCmp",
"test": "NODE_OPTIONS=--experimental-vm-modules polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns toMiniSecretCmp",
"test:mnemonicCmp": "polkadot-dev-run-test packages/util-crypto/src/mnemonic/toMiniSecretCmp.spec.ts",
"test:node": "polkadot-dev-run-node-test --browser ^toMiniSecretCmp",
"test:one": "polkadot-dev-run-test --runInBand"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@polkadot/dev": "^0.68.2",
"@polkadot/dev": "^0.68.37",
"@types/jest": "^29.4.0"
},
"resolutions": {
"typescript": "^4.9.4"
"typescript": "^4.9.5"
}
}
+6 -6
View File
@@ -16,18 +16,18 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.1",
"@ledgerhq/hw-transport-webhid": "^6.27.12",
"@ledgerhq/hw-transport-webusb": "^6.27.12",
"@polkadot/util": "10.4.2"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.7"
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.9"
}
}
@@ -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.2' };
+5 -5
View File
@@ -19,13 +19,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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",
"@zondax/ledger-substrate": "^0.40.4"
"@ledgerhq/hw-transport": "^6.28.1",
"@polkadot/hw-ledger-transports": "10.4.2",
"@polkadot/util": "10.4.2",
"@zondax/ledger-substrate": "^0.40.5"
}
}
+2
View File
@@ -25,7 +25,9 @@ export const ledgerApps: Record<string, string> = {
nodle: 'Nodle',
origintrail: 'OriginTrail',
parallel: 'Parallel',
pendulum: 'Pendulum',
phala: 'Phala',
picasso: 'Picasso',
polkadex: 'Polkadex',
polkadot: 'Polkadot',
polymesh: 'Polymesh',
+1 -1
View File
@@ -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.2' };
+5 -5
View File
@@ -20,15 +20,15 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@polkadot/util": "10.3.1",
"@polkadot/util-crypto": "10.3.1"
"@polkadot/util": "10.4.2",
"@polkadot/util-crypto": "10.4.2"
},
"peerDependencies": {
"@polkadot/util": "10.3.1",
"@polkadot/util-crypto": "10.3.1"
"@polkadot/util": "10.4.2",
"@polkadot/util-crypto": "10.4.2"
}
}
+1 -1
View File
@@ -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.2' };
+3 -3
View File
@@ -17,14 +17,14 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@polkadot/util": "10.3.1",
"@polkadot/util": "10.4.2",
"@substrate/ss58-registry": "^1.38.0"
},
"devDependencies": {
"@polkadot/hw-ledger": "10.3.1"
"@polkadot/hw-ledger": "10.4.2"
}
}
@@ -85,10 +85,14 @@ export const knownGenesis: KnownGenesis = {
parallel: [
'0xe61a41c53f5dcd0beb09df93b34402aada44cb05117b71059cce40a2723a4e97'
],
pendulum: [
'0x5d3c298622d5634ed019bf61ea4b71655030015bde9beb0d6a24743714462c86'
],
phala: [
'0x1bb969d85965e4bb5a651abbedf21a54b6b31a21f66b5401cc3f1e286268d736'
],
picasso: [
'0x6811a339673c9daa897944dcdac99c6e2939cc88245ed21951a0a3c9a2be75bc',
'0xe8e7f0f4c4f5a00720b4821dbfddefea7490bcf0b19009961cc46957984e2c1c'
],
polkadex: [
+2
View File
@@ -29,7 +29,9 @@ export const knownLedger: KnownLedger = {
nodle: 0x000003eb,
origintrail: 0x00000162,
parallel: 0x00000162,
pendulum: 0x00000162,
phala: 0x00000162,
picasso: 0x000001b2,
polkadex: 0x0000031f,
polkadot: 0x00000162,
polymesh: 0x00000253,
+1 -1
View File
@@ -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.2' };
+1 -1
View File
@@ -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 => {
+7 -7
View File
@@ -22,7 +22,7 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.2",
"@polkadot/util": "10.4.2",
"@polkadot/wasm-crypto": "^6.4.1",
"@polkadot/x-bigint": "10.3.1",
"@polkadot/x-randomvalues": "10.3.1",
"@polkadot/x-bigint": "10.4.2",
"@polkadot/x-randomvalues": "10.4.2",
"@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.2"
}
}
@@ -14,24 +14,21 @@ const NUM_CHECKS = 5;
// generate either a JS or WASM mnemonic
describe.each([true, false])('mnemonicToMiniSecret (compare), onlyJsMnemonic=%p', (onlyJsMnemonic): void => {
beforeAll(async (): Promise<void> => {
await cryptoWaitReady();
});
// loop through lots of mnemonics
describe.each(arrayRange(NUM_RUNS))('run=%p', (): void => {
// compare both JS and WASM outputs against original
describe.each([true, false])('onlyJsMini=%p', (onlyJsMini): void => {
describe.each([true, false])('onlyJsMini=%p', async (onlyJsMini): Promise<void> => {
await cryptoWaitReady();
// NOTE we cannot actually use the onlyJsMnemonic flag here
const mnemonic = mnemonicGenerate(12);
describe(mnemonic, (): void => {
// do iterations to check and re-check that all matches
it.concurrent.each(arrayRange(NUM_CHECKS))('check=%p', (count): void => {
it.each(arrayRange(NUM_CHECKS))('check=%p', (count): void => {
const minisecret = mnemonicToMiniSecret(mnemonic, count ? `${count}` : '', onlyJsMnemonic);
const edpub = ed25519PairFromSeed(minisecret).publicKey;
const srpub = sr25519PairFromSeed(minisecret).publicKey;
const testmini = mnemonicToMiniSecret(mnemonic, count ? `${count}` : '', onlyJsMini);
// explicit minisecret compare
+1 -1
View File
@@ -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.2' };
+20 -20
View File
@@ -6,20 +6,6 @@
"engines": {
"node": ">=14.0.0"
},
"exports": {
"./hex/toU8a": {
"node": {
"require": "./cjs/hex/toU8aBuffer.js",
"default": "./hex/toU8aBuffer.js"
}
},
"./u8a/toHex": {
"node": {
"require": "./cjs/u8a/toHexBuffer.js",
"default": "./u8a/toHexBuffer.js"
}
}
},
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"license": "Apache-2.0",
"maintainers": [],
@@ -34,18 +20,32 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"main": "index.js",
"exports": {
"./hex/toU8a": {
"node": {
"require": "./cjs/hex/toU8aBuffer.js",
"default": "./hex/toU8aBuffer.js"
}
},
"./u8a/toHex": {
"node": {
"require": "./cjs/u8a/toHexBuffer.js",
"default": "./u8a/toHexBuffer.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.2",
"@polkadot/x-global": "10.4.2",
"@polkadot/x-textdecoder": "10.4.2",
"@polkadot/x-textencoder": "10.4.2",
"@types/bn.js": "^5.1.1",
"bn.js": "^5.2.1"
},
"devDependencies": {
"@polkadot/x-randomvalues": "10.3.1"
"@polkadot/x-randomvalues": "10.4.2"
}
}
+60 -32
View File
@@ -4,9 +4,46 @@
import { BN } from '../bn';
import { formatBalance } from '.';
const FMT_DEFAULTS = {
decimals: 0,
unit: 'Unit'
};
describe('formatBalance', (): void => {
const TESTVAL = new BN('123456789000');
// We mess around with the global setDefaults inside some tests,
// ensure we restore it to the defaults straight after each run
afterEach((): void => {
formatBalance.setDefaults(FMT_DEFAULTS);
});
it('returns options for dropdown', (): void => {
formatBalance.setDefaults({ decimals: 0, unit: 'TEST' });
expect(
formatBalance.getOptions()
).toEqual([
{ power: 0, text: 'TEST', value: '-' },
{ power: 3, text: 'Kilo', value: 'k' },
{ power: 6, text: 'Mill', value: 'M' },
{ power: 9, text: 'Bill', value: 'B' },
{ power: 12, text: 'Tril', value: 'T' },
{ power: 15, text: 'Peta', value: 'P' },
{ power: 18, text: 'Exa', value: 'E' },
{ power: 21, text: 'Zeta', value: 'Z' },
{ power: 24, text: 'Yotta', value: 'Y' }
]);
});
it('can set defaults from array values', (): void => {
formatBalance.setDefaults({ decimals: [12, 24], unit: ['Multi', 'Unit'] });
expect(
formatBalance(TESTVAL)
).toEqual('123.4567 mMulti');
});
describe('SI formatting', (): void => {
it('formats empty to 0', (): void => {
expect(formatBalance()).toEqual('0');
@@ -184,11 +221,29 @@ describe('formatBalance', (): void => {
).toEqual('12,345.6789 Unit');
});
it('formats 123,456,789,000 (decimals=15, forceUnit=µ)', (): void => {
it('formats 123,456,789,000 (decimals=15, forceUnit=micro)', (): void => {
expect(
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 => {
@@ -215,10 +270,9 @@ describe('formatBalance', (): void => {
describe('defaults', (): void => {
it('returns defaults', (): void => {
expect(formatBalance.getDefaults()).toEqual({
decimals: 0,
unit: 'Unit'
});
expect(
formatBalance.getDefaults()
).toEqual(FMT_DEFAULTS);
});
it('formats 123,456,789,000 (defaultDecimals=12)', (): void => {
@@ -230,37 +284,11 @@ describe('formatBalance', (): void => {
});
it('formats 123,456,789,000 (defaultUnit=TEST)', (): void => {
formatBalance.setDefaults({ unit: 'TEST' });
formatBalance.setDefaults({ decimals: 12, unit: 'TEST' });
expect(
formatBalance(TESTVAL)
).toEqual('123.4567 mTEST');
});
});
it('returns options for dropdown', (): void => {
formatBalance.setDefaults({ decimals: 0, unit: 'TEST' });
expect(
formatBalance.getOptions()
).toEqual([
{ power: 0, text: 'TEST', value: '-' },
{ power: 3, text: 'Kilo', value: 'k' },
{ power: 6, text: 'Mill', value: 'M' },
{ power: 9, text: 'Bill', value: 'B' },
{ power: 12, text: 'Tril', value: 'T' },
{ power: 15, text: 'Peta', value: 'P' },
{ power: 18, text: 'Exa', value: 'E' },
{ power: 21, text: 'Zeta', value: 'Z' },
{ power: 24, text: 'Yotta', value: 'Y' }
]);
});
it('can set defaults from array values', (): void => {
formatBalance.setDefaults({ decimals: [12, 24], unit: ['Multi', 'Unit'] });
expect(
formatBalance(TESTVAL)
).toEqual('123.4567 mMulti');
});
});
+9 -2
View File
@@ -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, locale = 'en', withAll = false, withSi = true, withSiFull = false, withUnit = true, withZero = true }: 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;
+3 -3
View File
@@ -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');
});
});
+16 -3
View File
@@ -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: ','
});
});
});
+15
View File
@@ -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)
};
}
+4 -2
View File
@@ -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;
}
+35
View File
@@ -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);
});
});
+12
View File
@@ -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');
+6
View File
@@ -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) &&
+1
View File
@@ -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';
-11
View File
@@ -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;
}
+1 -1
View File
@@ -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.2' };
+1 -1
View File
@@ -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()
+28 -27
View File
@@ -9,7 +9,7 @@ type ExecFn = (...params: any[]) => unknown;
const NUM_PAD = 16;
const PRE_PAD = 32;
function loop (count: number, inputs: readonly unknown[][], exec: ExecFn): [number, unknown[]] {
function loop (exec: ExecFn, count: number, inputs: readonly unknown[][]): [number, unknown[]] {
const start = performance.now();
const results = new Array<unknown>(inputs.length);
@@ -40,14 +40,14 @@ ${formatFixed(micro).padStart(NUM_PAD + PRE_PAD + 1)} μs/op`;
}
export function perf (name: string, count: number, inputs: readonly unknown[][], exec: ExecFn, withLog?: boolean): void {
if (process.env.GITHUB_REPOSITORY) {
return;
}
const test = process.env.GITHUB_REPOSITORY
? it.skip
: it;
it(`performance: ${name}`, (): void => {
const [time, results] = loop(count, inputs, exec);
test(`performance: ${name}`, (): void => {
const [time, results] = loop(exec, count, inputs);
console.log(`
console.error(`
performance run for ${name} completed with ${formatNumber(count)} iterations.
${`${name}:`.padStart(PRE_PAD)} ${time.toFixed(2).padStart(NUM_PAD)} ms${formatOps(count, time)}
@@ -60,28 +60,29 @@ ${`${name}:`.padStart(PRE_PAD)} ${time.toFixed(2).padStart(NUM_PAD)} ms${formatO
}
export function perfCmp (name: string, [first, second]: [string, string], count: number, inputs: readonly unknown[][], exec: ExecFn): void {
if (process.env.GITHUB_REPOSITORY) {
return;
}
const test = process.env.GITHUB_REPOSITORY
? it.skip
: it;
it(`performance: ${name}`, (): void => {
const pa = inputs.map((values) => [...values, false]);
const pb = inputs.map((values) => [...values, true]);
const [ta, ra] = loop(count, pa, exec);
const [tb, rb] = loop(count, pb, exec);
console.log(`
performance run for ${name} completed with ${formatNumber(count)} iterations.
${`${first}:`.padStart(PRE_PAD)} ${ta.toFixed(2).padStart(NUM_PAD)} ms ${ta < tb ? '(fastest)' : `(slowest, ${(ta / tb).toFixed(2)}x)`}${formatOps(count, ta)}
${`${second}:`.padStart(PRE_PAD)} ${tb.toFixed(2).padStart(NUM_PAD)} ms ${ta > tb ? '(fastest)' : `(slowest, ${(tb / ta).toFixed(2)}x)`}${formatOps(count, tb)}
`);
const unmatched = ra.filter((r, i) =>
JSON.stringify(r) !== JSON.stringify(rb[i])
test(`performance: ${name}`, (): void => {
const [[t1, r1], [t2, r2]] = [false, true].map((flag) =>
loop(exec, count, inputs.map((values) =>
[...values, flag]
))
);
expect(unmatched.length).toEqual(0);
console.error(`
performance run for ${name} completed with ${formatNumber(count)} iterations.
${`${first}:`.padStart(PRE_PAD)} ${t1.toFixed(2).padStart(NUM_PAD)} ms ${t1 < t2 ? '(fastest)' : `(slowest, ${(t1 / t2).toFixed(2)}x)`}${formatOps(count, t1)}
${`${second}:`.padStart(PRE_PAD)} ${t2.toFixed(2).padStart(NUM_PAD)} ms ${t1 > t2 ? '(fastest)' : `(slowest, ${(t2 / t1).toFixed(2)}x)`}${formatOps(count, t2)}
`);
expect(
r1.filter((_, i) =>
JSON.stringify(r1[i]) !== JSON.stringify(r2[i])
)
).toHaveLength(0);
});
}
+4
View File
@@ -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 {
+7 -2
View File
@@ -26,10 +26,15 @@ import { stringToU8a } from '../string/toU8a';
*/
export function u8aToU8a (value?: U8aLike | null): Uint8Array {
return isU8a(value)
? value
// NOTE isBuffer needs to go here since it actually extends
// Uint8Array on Node.js environments, so all Buffer are Uint8Array,
// but Uint8Array is not Buffer
? isBuffer(value)
? new Uint8Array(value)
: value
: isHex(value)
? hexToU8a(value)
: isBuffer(value) || Array.isArray(value)
: Array.isArray(value)
? new Uint8Array(value)
: stringToU8a(value);
}
+2 -2
View File
@@ -20,9 +20,9 @@
"./shim.cjs"
],
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@polkadot/x-global": "10.3.1"
"@polkadot/x-global": "10.4.2"
}
}
+1 -1
View File
@@ -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.2' };
+2 -2
View File
@@ -17,11 +17,11 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13",
"@polkadot/util": "10.3.1",
"@polkadot/util": "10.4.2",
"buffer-es6": "^4.9.3"
}
}
+1 -1
View File
@@ -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.2' };
+2 -2
View File
@@ -17,13 +17,13 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.2",
"@types/node-fetch": "^2.6.2",
"node-fetch": "^3.3.0"
}
+1 -1
View File
@@ -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.2' };
+1 -1
View File
@@ -17,7 +17,7 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.13"
+1 -1
View File
@@ -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.2' };
+4 -4
View File
@@ -17,17 +17,17 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.2"
},
"devDependencies": {
"@polkadot/util": "10.3.1",
"@types/react-native": "^0.71.0"
"@polkadot/util": "10.4.2",
"@types/react-native": "^0.71.3"
},
"denoDependencies": {
"crypto": "std@0.161.0/node/crypto.ts"
+1 -1
View File
@@ -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.2' };
+2 -2
View File
@@ -17,13 +17,13 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.2"
},
"denoDependencies": {
"util": "std@0.161.0/node/util.ts"
+1 -1
View File
@@ -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.2' };
+2 -2
View File
@@ -17,13 +17,13 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.2"
},
"denoDependencies": {
"util": "std@0.161.0/node/util.ts"
+1 -1
View File
@@ -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.2' };
+2 -2
View File
@@ -17,13 +17,13 @@
},
"sideEffects": false,
"type": "module",
"version": "10.3.1",
"version": "10.4.2",
"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.2",
"@types/websocket": "^1.0.5",
"websocket": "^1.0.34"
}
+1 -1
View File
@@ -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.2' };
+1
View File
@@ -24,6 +24,7 @@
"@polkadot/x-textencoder": ["x-textencoder/src/browser"],
"@polkadot/x-ws": ["x-ws/src/browser"]
},
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "es2020"
}
+2035 -852
View File
File diff suppressed because it is too large Load Diff