diff --git a/lerna.json b/lerna.json index ffeee2287..60aa4b450 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "0.31.7" + "version": "0.32.0" } diff --git a/packages/db/package.json b/packages/db/package.json index 60dc7b8dc..cdbc76fa9 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/db", - "version": "0.31.7", + "version": "0.32.0", "description": "Implementation of a basic sync in-memory and on-disk databases with overlays", "main": "index.js", "keywords": [ @@ -29,8 +29,8 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/db#readme", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/trie-hash": "^0.31.7", - "@polkadot/util": "^0.31.7", + "@polkadot/trie-hash": "^0.32.0", + "@polkadot/util": "^0.32.0", "@types/mkdirp": "^0.5.2", "@types/snappy": "^6.0.0", "lru_map": "^0.3.3", diff --git a/packages/db/src/engines/LruDb.spec.js b/packages/db/src/engines/LruDb.spec.js index 0efdd0427..890649e92 100644 --- a/packages/db/src/engines/LruDb.spec.js +++ b/packages/db/src/engines/LruDb.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import toU8a from '@polkadot/util/u8a/fromString'; +import toU8a from '@polkadot/util/u8a/toU8a'; import LruDb from './LruDb'; import MemoryDb from './MemoryDb'; diff --git a/packages/db/src/engines/TransactionDb.spec.js b/packages/db/src/engines/TransactionDb.spec.js index f03500c0c..b34e3f3ad 100644 --- a/packages/db/src/engines/TransactionDb.spec.js +++ b/packages/db/src/engines/TransactionDb.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import toU8a from '@polkadot/util/u8a/fromString'; +import toU8a from '@polkadot/util/string/toU8a'; import MemoryDb from './MemoryDb'; import TransactionDb from './TransactionDb'; diff --git a/packages/keyring/package.json b/packages/keyring/package.json index d37134f02..8bcd7b14e 100644 --- a/packages/keyring/package.json +++ b/packages/keyring/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/keyring", - "version": "0.31.7", + "version": "0.32.0", "description": "Keyring management", "main": "index.js", "engines": { @@ -31,8 +31,8 @@ "homepage": "https://github.com/polkadot-js/client/tree/master/packages/keyring#readme", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/util": "^0.31.7", - "@polkadot/util-crypto": "^0.31.7", + "@polkadot/util": "^0.32.0", + "@polkadot/util-crypto": "^0.32.0", "@types/bs58": "^3.0.30", "bs58": "^4.0.1" } diff --git a/packages/keyring/src/index.spec.js b/packages/keyring/src/index.spec.js index b223fdb31..90f236a63 100644 --- a/packages/keyring/src/index.spec.js +++ b/packages/keyring/src/index.spec.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. import hexToU8a from '@polkadot/util/hex/toU8a'; -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import Keyring from './index'; import setPrefix from './address/setPrefix'; diff --git a/packages/keyring/src/pair/decode.ts b/packages/keyring/src/pair/decode.ts index d450d53ab..c847564b3 100644 --- a/packages/keyring/src/pair/decode.ts +++ b/packages/keyring/src/pair/decode.ts @@ -2,9 +2,9 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. +import stringToU8a from '@polkadot/util/string/toU8a'; import u8aConcat from '@polkadot/util/u8a/concat'; import u8aFixLength from '@polkadot/util/u8a/fixLength'; -import u8aFromString from '@polkadot/util/u8a/fromString'; import assert from '@polkadot/util/assert'; import naclDecrypt from '@polkadot/util-crypto/nacl/decrypt'; import naclFromSeed from '@polkadot/util-crypto/nacl/keypair/fromSeed'; @@ -24,7 +24,7 @@ export default function decode (passphrase?: string, _encrypted?: Uint8Array) { ? (naclDecrypt( encrypted.subarray(24), encrypted.subarray(0, 24), - u8aFixLength(u8aFromString(passphrase), 256, true)) as Uint8Array) + u8aFixLength(stringToU8a(passphrase), 256, true)) as Uint8Array) : encrypted; assert(encoded, `Unable to unencrypt using the supplied passphrase`); diff --git a/packages/keyring/src/pair/encode.ts b/packages/keyring/src/pair/encode.ts index 42ae39646..c9aed60c2 100644 --- a/packages/keyring/src/pair/encode.ts +++ b/packages/keyring/src/pair/encode.ts @@ -2,9 +2,9 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. +import stringToU8a from '@polkadot/util/string/toU8a'; import u8aConcat from '@polkadot/util/u8a/concat'; import u8aFixLength from '@polkadot/util/u8a/fixLength'; -import u8aFromString from '@polkadot/util/u8a/fromString'; import naclEncrypt from '@polkadot/util-crypto/nacl/encrypt'; import { PKCS8_DIVIDER, PKCS8_HEADER } from './defaults'; @@ -21,7 +21,7 @@ export default function encode (secretKey: Uint8Array, passphrase?: string): Uin return encoded; } - const { encrypted, nonce } = naclEncrypt(encoded, u8aFixLength(u8aFromString(passphrase), 256, true)); + const { encrypted, nonce } = naclEncrypt(encoded, u8aFixLength(stringToU8a(passphrase), 256, true)); return u8aConcat(nonce, encrypted); } diff --git a/packages/keyring/src/testing.ts b/packages/keyring/src/testing.ts index f07e883bf..9d8ec9122 100644 --- a/packages/keyring/src/testing.ts +++ b/packages/keyring/src/testing.ts @@ -4,12 +4,12 @@ import { KeyringInstance } from './types'; -import u8aFromString from '@polkadot/util/u8a/fromString'; +import stringToU8a from '@polkadot/util/string/toU8a'; import Keyring from './index'; function padSeed (seed: string): Uint8Array { - return u8aFromString(seed.padEnd(32, ' ')); + return stringToU8a(seed.padEnd(32, ' ')); } const SEEDS: { [index: string ]: Uint8Array } = { diff --git a/packages/trie-db/package.json b/packages/trie-db/package.json index 5268e4385..484761d82 100644 --- a/packages/trie-db/package.json +++ b/packages/trie-db/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/trie-db", - "version": "0.31.7", + "version": "0.32.0", "description": "This is an implementation of the modified merkle patricia tree as speficed in Ethereum's yellow paper, adpated for Polkadot", "main": "index.js", "keywords": [ @@ -29,13 +29,13 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-db#readme", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/trie-hash": "^0.31.7", - "@polkadot/util": "^0.31.7", - "@polkadot/util-crypto": "^0.31.7", - "@polkadot/util-rlp": "^0.31.7" + "@polkadot/trie-hash": "^0.32.0", + "@polkadot/util": "^0.32.0", + "@polkadot/util-crypto": "^0.32.0", + "@polkadot/util-rlp": "^0.32.0" }, "devDependencies": { - "@polkadot/db": "^0.31.7", + "@polkadot/db": "^0.32.0", "ethereumjs-testing": "1.0.4" } } diff --git a/packages/trie-hash/package.json b/packages/trie-hash/package.json index 156401cd5..b6c343c7b 100644 --- a/packages/trie-hash/package.json +++ b/packages/trie-hash/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/trie-hash", - "version": "0.31.7", + "version": "0.32.0", "description": "Creation of triehash values", "main": "index.js", "keywords": [ @@ -29,8 +29,8 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-hash#readme", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/util": "^0.31.7", - "@polkadot/util-crypto": "^0.31.7", - "@polkadot/util-rlp": "^0.31.7" + "@polkadot/util": "^0.32.0", + "@polkadot/util-crypto": "^0.32.0", + "@polkadot/util-rlp": "^0.32.0" } } diff --git a/packages/trie-hash/src/root.spec.js b/packages/trie-hash/src/root.spec.js index ae2d315c5..b7fdd824c 100644 --- a/packages/trie-hash/src/root.spec.js +++ b/packages/trie-hash/src/root.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import hexToU8a from '@polkadot/util/hex/toU8a'; import { trieRoot } from './index'; diff --git a/packages/trie-hash/src/rootOrdered.spec.js b/packages/trie-hash/src/rootOrdered.spec.js index 09b165491..6bd4c155b 100644 --- a/packages/trie-hash/src/rootOrdered.spec.js +++ b/packages/trie-hash/src/rootOrdered.spec.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. import hexToU8a from '@polkadot/util/hex/toU8a'; -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import { trieRootOrdered } from './index'; diff --git a/packages/trie-hash/src/util/asNibbles.spec.js b/packages/trie-hash/src/util/asNibbles.spec.js index 9e55c784b..db19b4e86 100644 --- a/packages/trie-hash/src/util/asNibbles.spec.js +++ b/packages/trie-hash/src/util/asNibbles.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import asNibbles from './asNibbles'; diff --git a/packages/trie-hash/src/util/fromNibbles.spec.js b/packages/trie-hash/src/util/fromNibbles.spec.js index 2841c165f..148196325 100644 --- a/packages/trie-hash/src/util/fromNibbles.spec.js +++ b/packages/trie-hash/src/util/fromNibbles.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import u8aFromString from '@polkadot/util/u8a/fromString'; +import stringToU8a from '@polkadot/util/string/toU8a'; import fromNibbles from './fromNibbles'; @@ -13,7 +13,7 @@ describe('fromNibbles', () => { new Uint8Array([4, 1]) ) ).toEqual( - u8aFromString('A') + stringToU8a('A') ); }); diff --git a/packages/util-crypto/package.json b/packages/util-crypto/package.json index 5d4f6a10c..02acd5874 100644 --- a/packages/util-crypto/package.json +++ b/packages/util-crypto/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-crypto", - "version": "0.31.7", + "version": "0.32.0", "description": "A collection of useful crypto utilities for @polkadot", "main": "index.js", "keywords": [ @@ -29,7 +29,7 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/util": "^0.31.7", + "@polkadot/util": "^0.32.0", "@types/bip39": "^2.4.0", "bip39": "^2.5.0", "blakejs": "^1.1.0", diff --git a/packages/util-crypto/src/keccak/asU8a.spec.js b/packages/util-crypto/src/keccak/asU8a.spec.js index 87b871166..bcae9a623 100644 --- a/packages/util-crypto/src/keccak/asU8a.spec.js +++ b/packages/util-crypto/src/keccak/asU8a.spec.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. import hexToU8a from '@polkadot/util/hex/toU8a'; -import u8aFromString from '@polkadot/util/u8a/fromString'; +import stringToU8a from '@polkadot/util/string/toU8a'; import { keccakAsU8a } from './index'; @@ -30,7 +30,7 @@ describe('keccakAsU8a', () => { it('returns an hex representation (Uint8Array)', () => { expect( keccakAsU8a( - u8aFromString(input) + stringToU8a(input) ) ).toEqual(output); }); diff --git a/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js b/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js index 1e9fceec4..da994dc9c 100644 --- a/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js +++ b/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import { naclKeypairFromSeed } from '../index'; diff --git a/packages/util-crypto/src/nacl/keypair/fromString.ts b/packages/util-crypto/src/nacl/keypair/fromString.ts index 419506633..3f3caad1d 100644 --- a/packages/util-crypto/src/nacl/keypair/fromString.ts +++ b/packages/util-crypto/src/nacl/keypair/fromString.ts @@ -4,7 +4,7 @@ import { KeypairType } from '../../types'; -import u8aFromUtf8 from '@polkadot/util/u8a/fromUtf8'; +import stringToU8a from '@polkadot/util/string/toU8a'; import blake2AsU8a from '../../blake2/asU8a'; import fromSeed from './fromSeed'; @@ -23,7 +23,7 @@ import fromSeed from './fromSeed'; export default function naclKeypairFromString (value: string): KeypairType { return fromSeed( blake2AsU8a( - u8aFromUtf8(value), + stringToU8a(value), 256 ) ); diff --git a/packages/util-crypto/src/nacl/sign.spec.js b/packages/util-crypto/src/nacl/sign.spec.js index 64e922d2a..51de73c83 100644 --- a/packages/util-crypto/src/nacl/sign.spec.js +++ b/packages/util-crypto/src/nacl/sign.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import { naclSign, naclKeypairFromSeed } from './index'; diff --git a/packages/util-crypto/src/nacl/verify.spec.js b/packages/util-crypto/src/nacl/verify.spec.js index 6362fbcda..862133658 100644 --- a/packages/util-crypto/src/nacl/verify.spec.js +++ b/packages/util-crypto/src/nacl/verify.spec.js @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import u8aFromString from '@polkadot/util/u8a/fromString'; +import u8aFromString from '@polkadot/util/string/toU8a'; import { naclVerify, naclKeypairFromSeed } from './index'; diff --git a/packages/util-rlp/package.json b/packages/util-rlp/package.json index 422110668..ba9d692f1 100644 --- a/packages/util-rlp/package.json +++ b/packages/util-rlp/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-rlp", - "version": "0.31.7", + "version": "0.32.0", "description": "RLP encoding and decoding", "main": "index.js", "keywords": [ @@ -31,7 +31,7 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-hash#readme", "dependencies": { "@babel/runtime": "^7.0.0", - "@polkadot/util": "^0.31.7" + "@polkadot/util": "^0.32.0" }, "devDependencies": { "ethereumjs-testing": "1.0.4" diff --git a/packages/util-rlp/src/encoder/toU8a.ts b/packages/util-rlp/src/encoder/toU8a.ts index fa25c8b96..d1e5f3fce 100644 --- a/packages/util-rlp/src/encoder/toU8a.ts +++ b/packages/util-rlp/src/encoder/toU8a.ts @@ -15,7 +15,7 @@ import isString from '@polkadot/util/is/string'; import isU8a from '@polkadot/util/is/u8a'; import isUndefined from '@polkadot/util/is/undefined'; import numberToU8a from '@polkadot/util/number/toU8a'; -import u8aFromUtf8 from '@polkadot/util/u8a/fromUtf8'; +import stringToU8a from '@polkadot/util/string/toU8a'; type Encoder = { check: (value: any) => boolean, @@ -31,7 +31,7 @@ function convertString (value: string): Uint8Array { return hexToU8a(value); } - return u8aFromUtf8(value); + return stringToU8a(value); } function convertU8a (value: Uint8Array): Uint8Array { diff --git a/packages/util/package.json b/packages/util/package.json index b8d1c3ce9..645dcc2fc 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util", - "version": "0.31.7", + "version": "0.32.0", "description": "A collection of useful utilities for @polkadot", "main": "index.js", "keywords": [ diff --git a/packages/util/src/buffer/fromU8a.spec.js b/packages/util/src/buffer/fromU8a.spec.js deleted file mode 100644 index afcc8ca00..000000000 --- a/packages/util/src/buffer/fromU8a.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { bufferFromU8a } from './index'; - -describe('bufferFromU8a', () => { - it('exists as a function', () => { - expect( - isFunction(bufferFromU8a) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/buffer/fromU8a.ts b/packages/util/src/buffer/fromU8a.ts deleted file mode 100644 index 1c40144d7..000000000 --- a/packages/util/src/buffer/fromU8a.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import bufferFromU8a from '../u8a/toBuffer'; - -/** - * @name bufferFromU8a - * @signature bufferFromU8a (value?: string): Buffer - * @summary Creates a Buffer object from a Uint8Array. - * @alias u8a/toBuffer - */ -export default bufferFromU8a; diff --git a/packages/util/src/buffer/index.ts b/packages/util/src/buffer/index.ts index 2660cd04d..92fca1bf1 100644 --- a/packages/util/src/buffer/index.ts +++ b/packages/util/src/buffer/index.ts @@ -2,13 +2,11 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import bufferFromU8a from './fromU8a'; import bufferToU8a from './toU8a'; /** * @summary Utility methods to convert to and from `Buffer` objects */ export { - bufferFromU8a, bufferToU8a }; diff --git a/packages/util/src/hex/fromBn.spec.js b/packages/util/src/hex/fromBn.spec.js deleted file mode 100644 index 402ce03d3..000000000 --- a/packages/util/src/hex/fromBn.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { hexFromBn } from './index'; - -describe('hexFromBn', () => { - it('exists as a function', () => { - expect( - isFunction(hexFromBn) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/hex/fromBn.ts b/packages/util/src/hex/fromBn.ts deleted file mode 100644 index 748ea4c99..000000000 --- a/packages/util/src/hex/fromBn.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import hexFromBn from '../bn/toHex'; - -/** - * @name hexFromBn - * @signature hexFromBn (value?: BN): string - * @summary Creates a hex value from a BN.js bignumber object. - * @alias bn/toHex - */ -export default hexFromBn; diff --git a/packages/util/src/hex/fromNumber.spec.js b/packages/util/src/hex/fromNumber.spec.js deleted file mode 100644 index 073338409..000000000 --- a/packages/util/src/hex/fromNumber.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { hexFromNumber } from './index'; - -describe('hexFromNumber', () => { - it('exists as a function', () => { - expect( - isFunction(hexFromNumber) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/hex/fromNumber.ts b/packages/util/src/hex/fromNumber.ts deleted file mode 100644 index 8807bd100..000000000 --- a/packages/util/src/hex/fromNumber.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import hexFromNumber from '../number/toHex'; - -/** - * @name hexFromNumber - * @signature hexFromNumber (value?: number): string - * @summary Creates a hex value from a number. - * @alias number/toHex - */ -export default hexFromNumber; diff --git a/packages/util/src/hex/index.ts b/packages/util/src/hex/index.ts index 7360875ad..1956282f8 100644 --- a/packages/util/src/hex/index.ts +++ b/packages/util/src/hex/index.ts @@ -4,8 +4,6 @@ import hexAddPrefix from './addPrefix'; import hexFixLength from './fixLength'; -import hexFromBn from './fromBn'; -import hexFromNumber from './fromNumber'; import hexHasPrefix from './hasPrefix'; import hexStripPrefix from './stripPrefix'; import hexToBn from './toBn'; @@ -18,8 +16,6 @@ import hexToU8a from './toU8a'; export { hexAddPrefix, hexFixLength, - hexFromBn, - hexFromNumber, hexHasPrefix, hexStripPrefix, hexToBn, diff --git a/packages/util/src/number/fromHex.spec.js b/packages/util/src/number/fromHex.spec.js deleted file mode 100644 index 8e2616bc0..000000000 --- a/packages/util/src/number/fromHex.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { numberFromHex } from './index'; - -describe('numberFromHex', () => { - it('exists as a function', () => { - expect( - isFunction(numberFromHex) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/number/fromHex.ts b/packages/util/src/number/fromHex.ts deleted file mode 100644 index 246fd5059..000000000 --- a/packages/util/src/number/fromHex.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import numberFromHex from '../hex/toNumber'; - -/** - * @name numberFromHex - * @signature numberFromHex (value?: Hex): number - * @summary Creates a Number value from a Buffer object. - * @alias hex/toNumber - */ -export default numberFromHex; diff --git a/packages/util/src/number/index.ts b/packages/util/src/number/index.ts index 16a9e35e1..85d912261 100644 --- a/packages/util/src/number/index.ts +++ b/packages/util/src/number/index.ts @@ -2,7 +2,6 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import numberFromHex from './fromHex'; import numberToHex from './toHex'; import numberToU8a from './toU8a'; @@ -10,7 +9,6 @@ import numberToU8a from './toU8a'; * @summary Utility methods to convert to and from `number` values */ export { - numberFromHex, numberToHex, numberToU8a }; diff --git a/packages/util/src/string/index.ts b/packages/util/src/string/index.ts index aa7293130..5bb8657d6 100644 --- a/packages/util/src/string/index.ts +++ b/packages/util/src/string/index.ts @@ -5,6 +5,7 @@ import stringCamelCase from './camelCase'; import stringLowerFirst from './lowerFirst'; import stringShorten from './shorten'; +import stringToU8a from './toU8a'; import stringUpperFirst from './upperFirst'; /** @@ -14,5 +15,6 @@ export { stringCamelCase, stringLowerFirst, stringShorten, + stringToU8a, stringUpperFirst }; diff --git a/packages/util/src/u8a/polyfill/textDecoder.spec.js b/packages/util/src/string/polyfill/textDecoder.spec.js similarity index 100% rename from packages/util/src/u8a/polyfill/textDecoder.spec.js rename to packages/util/src/string/polyfill/textDecoder.spec.js diff --git a/packages/util/src/u8a/polyfill/textDecoder.ts b/packages/util/src/string/polyfill/textDecoder.ts similarity index 100% rename from packages/util/src/u8a/polyfill/textDecoder.ts rename to packages/util/src/string/polyfill/textDecoder.ts diff --git a/packages/util/src/u8a/polyfill/textEncoder.spec.js b/packages/util/src/string/polyfill/textEncoder.spec.js similarity index 100% rename from packages/util/src/u8a/polyfill/textEncoder.spec.js rename to packages/util/src/string/polyfill/textEncoder.spec.js diff --git a/packages/util/src/u8a/polyfill/textEncoder.ts b/packages/util/src/string/polyfill/textEncoder.ts similarity index 100% rename from packages/util/src/u8a/polyfill/textEncoder.ts rename to packages/util/src/string/polyfill/textEncoder.ts diff --git a/packages/util/src/u8a/fromUtf8.spec.js b/packages/util/src/string/toU8a.spec.js similarity index 79% rename from packages/util/src/u8a/fromUtf8.spec.js rename to packages/util/src/string/toU8a.spec.js index 80bc599ad..69767cc7f 100644 --- a/packages/util/src/u8a/fromUtf8.spec.js +++ b/packages/util/src/string/toU8a.spec.js @@ -2,18 +2,18 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import { u8aFromUtf8 } from './index'; +import { stringToU8a } from './index'; -describe('u8aFromUtf8', () => { +describe('stringToU8a', () => { it('decodes to an empty string for undefined', () => { expect( - u8aFromUtf8() + stringToU8a() ).toEqual(new Uint8Array([])); }); it('encodes the string correctly', () => { expect( - u8aFromUtf8('Привет, мир!') + stringToU8a('Привет, мир!') ).toEqual( new Uint8Array([208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 44, 32, 208, 188, 208, 184, 209, 128, 33]) ); diff --git a/packages/util/src/u8a/fromUtf8.ts b/packages/util/src/string/toU8a.ts similarity index 69% rename from packages/util/src/u8a/fromUtf8.ts rename to packages/util/src/string/toU8a.ts index 74e6c50e6..c6b94b24f 100644 --- a/packages/util/src/u8a/fromUtf8.ts +++ b/packages/util/src/string/toU8a.ts @@ -7,17 +7,17 @@ import './polyfill/textEncoder'; const encoder = new TextEncoder(); /** - * @name u8aFromUtf8 - * @signature u8aFromUtf8 (value?: string): UInt8Array + * @name stringToU8a + * @signature stringToU8a (value?: string): UInt8Array * @summary Creates a Uint8Array object from a utf-8 string. * @description * String input values return the actual encoded `UInt8Array`. `null` or `undefined` values returns an empty encoded array. * @example - * import { u8aFromUtf8 } from '@polkadot/util'; + * import { stringToU8a } from '@polkadot/util'; * - * u8aFromUtf8('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f] + * stringToU8a('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f] */ -export default function u8aFromUtf8 (value?: string): Uint8Array { +export default function stringToU8a (value?: string): Uint8Array { if (!value) { return new Uint8Array([]); } diff --git a/packages/util/src/u8a/fromBn.spec.js b/packages/util/src/u8a/fromBn.spec.js deleted file mode 100644 index f722b14bb..000000000 --- a/packages/util/src/u8a/fromBn.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { u8aFromBn } from './index'; - -describe('u8aFromBn', () => { - it('exists as a function', () => { - expect( - isFunction(u8aFromBn) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/u8a/fromBn.ts b/packages/util/src/u8a/fromBn.ts deleted file mode 100644 index 383547f8a..000000000 --- a/packages/util/src/u8a/fromBn.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import u8aFromBn from '../bn/toU8a'; - -/** - * @name u8aFromBn - * @signature u8aFromBn (value?: BN): Uint8Array - * @summary Creates a Uint8Array value from a BN object. - * @alias bn/toU8a - */ -export default u8aFromBn; diff --git a/packages/util/src/u8a/fromBuffer.spec.js b/packages/util/src/u8a/fromBuffer.spec.js deleted file mode 100644 index 0cf41a5e5..000000000 --- a/packages/util/src/u8a/fromBuffer.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { u8aFromBuffer } from './index'; - -describe('u8aFromBuffer', () => { - it('exists as a function', () => { - expect( - isFunction(u8aFromBuffer) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/u8a/fromBuffer.ts b/packages/util/src/u8a/fromBuffer.ts deleted file mode 100644 index 4e5dc62c6..000000000 --- a/packages/util/src/u8a/fromBuffer.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import u8aFromBuffer from '../buffer/toU8a'; - -/** - * @name u8aFromBuffer - * @signature u8aFromBuffer (value?: Buffer): Uint8Array - * @summary Creates a Uint8Array value from a Buffer object. - * @alias buffer/toU8a - */ -export default u8aFromBuffer; diff --git a/packages/util/src/u8a/fromHex.spec.js b/packages/util/src/u8a/fromHex.spec.js deleted file mode 100644 index 1103e199e..000000000 --- a/packages/util/src/u8a/fromHex.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import isFunction from '../is/function'; - -import { u8aFromHex } from './index'; - -describe('u8aFromHex', () => { - it('exists as a function', () => { - expect( - isFunction(u8aFromHex) - ).toEqual(true); - }); -}); diff --git a/packages/util/src/u8a/fromHex.ts b/packages/util/src/u8a/fromHex.ts deleted file mode 100644 index 5e6732390..000000000 --- a/packages/util/src/u8a/fromHex.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import u8aFromHex from '../hex/toU8a'; - -/** - * @name u8aFromHex - * @signature u8aFromHex (value?: string): Uint8Array - * @summary Creates a Uint8Array value from a hex string. - * @alias hex/toU8a - */ -export default u8aFromHex; diff --git a/packages/util/src/u8a/fromString.spec.js b/packages/util/src/u8a/fromString.spec.js deleted file mode 100644 index 5bef4ffaa..000000000 --- a/packages/util/src/u8a/fromString.spec.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { u8aFromString } from './index'; - -describe('u8aFromString', () => { - it('encodes a string byte for byte', () => { - expect( - u8aFromString('12345678901234567890123456789012') - ).toEqual( - new Uint8Array([ - 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32 - ]) - ); - }); -}); diff --git a/packages/util/src/u8a/fromString.ts b/packages/util/src/u8a/fromString.ts deleted file mode 100644 index e57474b26..000000000 --- a/packages/util/src/u8a/fromString.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -/** - * @name u8aFromString - * @signature u8aFromString (value: string): UInt8Array - * @summary Creates a Uint8Array object from a string. - * @description - * String input values return the actual encoded `UInt8Array`. - * @example - * import { u8aFromString } from '@polkadot/util'; - * - * u8aFromString('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f] - */ -export default function u8aFromString (value: string): Uint8Array { - const stringArray = []; - - for (let index = 0; index < value.length; index++) { - stringArray.push( - value.charCodeAt(index) - ); - } - - return new Uint8Array(stringArray); -} diff --git a/packages/util/src/u8a/index.ts b/packages/util/src/u8a/index.ts index 9216f8840..5d052cfad 100644 --- a/packages/util/src/u8a/index.ts +++ b/packages/util/src/u8a/index.ts @@ -4,17 +4,11 @@ import u8aConcat from './concat'; import u8aFixLength from './fixLength'; -import u8aFromBn from './fromBn'; -import u8aFromBuffer from './fromBuffer'; -import u8aFromHex from './fromHex'; -import u8aFromUtf8 from './fromUtf8'; -import u8aFromString from './fromString'; import u8aToBn from './toBn'; import u8aToBuffer from './toBuffer'; import u8aToHex from './toHex'; import u8aToString from './toString'; import u8aToU8a from './toU8a'; -import u8aToUtf8 from './toUtf8'; /** * @summary Utility methods to convert to and from `Uint8Array` objects @@ -22,15 +16,9 @@ import u8aToUtf8 from './toUtf8'; export { u8aConcat, u8aFixLength, - u8aFromBn, - u8aFromBuffer, - u8aFromHex, - u8aFromString, - u8aFromUtf8, u8aToBn, u8aToBuffer, u8aToHex, u8aToString, - u8aToU8a, - u8aToUtf8 + u8aToU8a }; diff --git a/packages/util/src/u8a/toString.spec.js b/packages/util/src/u8a/toString.spec.js index 8fae6411b..21ebff2fc 100644 --- a/packages/util/src/u8a/toString.spec.js +++ b/packages/util/src/u8a/toString.spec.js @@ -20,8 +20,8 @@ describe('u8aToString', () => { it('decodes the buffer correctly', () => { expect( u8aToString( - new Uint8Array([21, 23, 45, 67]) + new Uint8Array([208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 44, 32, 208, 188, 208, 184, 209, 128, 33]) ) - ).toEqual('21,23,45,67'); + ).toEqual('Привет, мир!'); }); }); diff --git a/packages/util/src/u8a/toString.ts b/packages/util/src/u8a/toString.ts index 192dafdda..658b62bb5 100644 --- a/packages/util/src/u8a/toString.ts +++ b/packages/util/src/u8a/toString.ts @@ -2,21 +2,25 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. +import '../string/polyfill/textDecoder'; + +const decoder = new TextDecoder('utf-8'); + /** * @name u8aToString * @signature u8aToString (value?: UInt8Array): string - * @summary Creates a string from a Uint8Array object. + * @summary Creates a utf-8 string from a Uint8Array object. * @description - * `UInt8Array` input values return the actual decoded string. `null` or `undefined` values returns an empty string. + * `UInt8Array` input values return the actual decoded utf-8 string. `null` or `undefined` values returns an empty string. * @example * import { u8aToString } from '@polkadot/util'; * - * u8aToString(new Uint8Array([21,23,45,67])); // 21,23,45,67 + * u8aToString(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])); // hello */ export default function u8aToString (value?: Uint8Array): string { if (!value || !value.length) { return ''; } - return value.toString(); + return decoder.decode(value); } diff --git a/packages/util/src/u8a/toU8a.ts b/packages/util/src/u8a/toU8a.ts index b35f3a611..564edd211 100644 --- a/packages/util/src/u8a/toU8a.ts +++ b/packages/util/src/u8a/toU8a.ts @@ -7,7 +7,7 @@ import isHex from '../is/hex'; import isString from '../is/string'; import bufferToU8a from '../buffer/toU8a'; import hexToU8a from '../hex/toU8a'; -import u8aFromUtf8 from './fromUtf8'; +import stringToU8a from '../string/toU8a'; /** * @name u8aToU8a @@ -35,7 +35,7 @@ export default function u8aToU8a (value?: Array | Buffer | Uint8Array | return hexToU8a(value); } - return u8aFromUtf8(value); + return stringToU8a(value); } if (Array.isArray(value)) { diff --git a/packages/util/src/u8a/toUtf8.spec.js b/packages/util/src/u8a/toUtf8.spec.js deleted file mode 100644 index b5a2fbec4..000000000 --- a/packages/util/src/u8a/toUtf8.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import { u8aToUtf8 } from './index'; - -describe('u8aToUtf8', () => { - it('decodes to an empty string for undefined', () => { - expect( - u8aToUtf8() - ).toEqual(''); - }); - - it('decodes to an empty string for empty buffer', () => { - expect( - u8aToUtf8(new Uint8Array([])) - ).toEqual(''); - }); - - it('decodes the buffer correctly', () => { - expect( - u8aToUtf8( - new Uint8Array([208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 44, 32, 208, 188, 208, 184, 209, 128, 33]) - ) - ).toEqual('Привет, мир!'); - }); -}); diff --git a/packages/util/src/u8a/toUtf8.ts b/packages/util/src/u8a/toUtf8.ts deleted file mode 100644 index f222c5aec..000000000 --- a/packages/util/src/u8a/toUtf8.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017-2018 @polkadot/util authors & contributors -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -import './polyfill/textDecoder'; - -const decoder = new TextDecoder('utf-8'); - -/** - * @name u8aToUtf8 - * @signature u8aToUtf8 (value?: UInt8Array): string - * @summary Creates a utf-8 string from a Uint8Array object. - * @description - * `UInt8Array` input values return the actual decoded utf-8 string. `null` or `undefined` values returns an empty string. - * @example - * import { u8aToUtf8 } from '@polkadot/util'; - * - * u8aToUtf8(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])); // hello - */ -export default function u8aToUtf8 (value?: Uint8Array): string { - if (!value || !value.length) { - return ''; - } - - return decoder.decode(value); -}