Add tslint (#151)
This commit is contained in:
@@ -5,19 +5,19 @@
|
||||
import u8aToU8a from './toU8a';
|
||||
|
||||
/**
|
||||
@name u8aConcat
|
||||
@signature u8aConcat (...values: Array<Uint8Array | string>): Uint8Array
|
||||
@summary Creates a concatenated Uint8Array from the inputs.
|
||||
@description
|
||||
Concatenates the input arrays into a single `UInt8Array`.
|
||||
@example
|
||||
import { u8aConcat } from '@polkadot/util';
|
||||
|
||||
u8aConcat(
|
||||
new Uint8Array([1, 2, 3]),
|
||||
new Uint8Array([4, 5, 6])
|
||||
); // [1, 2, 3, 4, 5, 6]
|
||||
*/
|
||||
* @name u8aConcat
|
||||
* @signature u8aConcat (...values: Array<Uint8Array | string>): Uint8Array
|
||||
* @summary Creates a concatenated Uint8Array from the inputs.
|
||||
* @description
|
||||
* Concatenates the input arrays into a single `UInt8Array`.
|
||||
* @example
|
||||
* import { u8aConcat } from '@polkadot/util';
|
||||
*
|
||||
* u8aConcat(
|
||||
* new Uint8Array([1, 2, 3]),
|
||||
* new Uint8Array([4, 5, 6])
|
||||
* ); // [1, 2, 3, 4, 5, 6]
|
||||
*/
|
||||
export default function u8aConcat (..._list: Array<Uint8Array | string>): Uint8Array {
|
||||
const list: Array<Uint8Array> = _list.map(u8aToU8a);
|
||||
const length = list.reduce((total, item) => total + item.length, 0);
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name u8aFixLength
|
||||
@signature u8aFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string
|
||||
@summary Shifts a Uint8Array to a specific bitLength
|
||||
@description
|
||||
Returns a uint8Array with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length.
|
||||
@example
|
||||
import { u8aFixLength } from '@polkadot/util';
|
||||
|
||||
u8aFixLength('0x12') // => 0x12
|
||||
u8aFixLength('0x12', 16) // => 0x0012
|
||||
u8aFixLength('0x1234', 8) // => 0x12
|
||||
*/
|
||||
* @name u8aFixLength
|
||||
* @signature u8aFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string
|
||||
* @summary Shifts a Uint8Array to a specific bitLength
|
||||
* @description
|
||||
* Returns a uint8Array with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length.
|
||||
* @example
|
||||
* import { u8aFixLength } from '@polkadot/util';
|
||||
*
|
||||
* u8aFixLength('0x12') // => 0x12
|
||||
* u8aFixLength('0x12', 16) // => 0x0012
|
||||
* u8aFixLength('0x1234', 8) // => 0x12
|
||||
*/
|
||||
export default function u8aFixLength (value: Uint8Array, bitLength: number = -1, atStart: boolean = false): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import u8aFromBn from '../bn/toU8a';
|
||||
|
||||
/**
|
||||
@name u8aFromBn
|
||||
@signature u8aFromBn (value?: BN): Uint8Array
|
||||
@summary Creates a Uint8Array value from a BN object.
|
||||
@alias bn/toU8a
|
||||
*/
|
||||
* @name u8aFromBn
|
||||
* @signature u8aFromBn (value?: BN): Uint8Array
|
||||
* @summary Creates a Uint8Array value from a BN object.
|
||||
* @alias bn/toU8a
|
||||
*/
|
||||
export default u8aFromBn;
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import u8aFromBuffer from '../buffer/toU8a';
|
||||
|
||||
/**
|
||||
@name u8aFromBuffer
|
||||
@signature u8aFromBuffer (value?: Buffer): Uint8Array
|
||||
@summary Creates a Uint8Array value from a Buffer object.
|
||||
@alias buffer/toU8a
|
||||
*/
|
||||
* @name u8aFromBuffer
|
||||
* @signature u8aFromBuffer (value?: Buffer): Uint8Array
|
||||
* @summary Creates a Uint8Array value from a Buffer object.
|
||||
* @alias buffer/toU8a
|
||||
*/
|
||||
export default u8aFromBuffer;
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import u8aFromHex from '../hex/toU8a';
|
||||
|
||||
/**
|
||||
@name u8aFromHex
|
||||
@signature u8aFromHex (value?: string): Uint8Array
|
||||
@summary Creates a Uint8Array value from a hex string.
|
||||
@alias hex/toU8a
|
||||
*/
|
||||
* @name u8aFromHex
|
||||
* @signature u8aFromHex (value?: string): Uint8Array
|
||||
* @summary Creates a Uint8Array value from a hex string.
|
||||
* @alias hex/toU8a
|
||||
*/
|
||||
export default u8aFromHex;
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// 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]
|
||||
*/
|
||||
* @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 = [];
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ import './polyfill/textEncoder';
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
/**
|
||||
@name u8aFromUtf8
|
||||
@signature u8aFromUtf8 (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';
|
||||
|
||||
u8aFromUtf8('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
|
||||
*/
|
||||
* @name u8aFromUtf8
|
||||
* @signature u8aFromUtf8 (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';
|
||||
*
|
||||
* u8aFromUtf8('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
|
||||
*/
|
||||
export default function u8aFromUtf8 (value?: string): Uint8Array {
|
||||
if (!value) {
|
||||
return new Uint8Array([]);
|
||||
|
||||
@@ -17,8 +17,8 @@ import u8aToU8a from './toU8a';
|
||||
import u8aToUtf8 from './toUtf8';
|
||||
|
||||
/**
|
||||
@summary Utility methods to convert to and from `Uint8Array` objects
|
||||
*/
|
||||
* @summary Utility methods to convert to and from `Uint8Array` objects
|
||||
*/
|
||||
export {
|
||||
u8aConcat,
|
||||
u8aFixLength,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
// tslint:disable-next-line
|
||||
if (typeof TextDecoder === 'undefined') {
|
||||
// @ts-ignore
|
||||
global.TextDecoder = require('util').TextDecoder;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
// tslint:disable-next-line
|
||||
if (typeof TextEncoder === 'undefined') {
|
||||
// @ts-ignore
|
||||
global.TextEncoder = require('util').TextEncoder;
|
||||
|
||||
@@ -8,16 +8,16 @@ import hexToBn from '../hex/toBn';
|
||||
import u8aToHex from './toHex';
|
||||
|
||||
/**
|
||||
@name u8aToBn
|
||||
@signature u8aToHex (value?: Uint8Array, isLe: boolean = false): BN
|
||||
@summary Creates a BN from a Uint8Array object.
|
||||
@description
|
||||
`UInt8Array` input values return the actual BN. `null` or `undefined` values returns an `0x0` value.
|
||||
@example
|
||||
import { u8aToBn } from '@polkadot/util';
|
||||
|
||||
u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
* @name u8aToBn
|
||||
* @signature u8aToHex (value?: Uint8Array, isLe: boolean = false): BN
|
||||
* @summary Creates a BN from a Uint8Array object.
|
||||
* @description
|
||||
* `UInt8Array` input values return the actual BN. `null` or `undefined` values returns an `0x0` value.
|
||||
* @example
|
||||
* import { u8aToBn } from '@polkadot/util';
|
||||
*
|
||||
* u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
export default function u8aToBn (value?: Uint8Array, isLe: boolean = false): BN {
|
||||
return hexToBn(
|
||||
u8aToHex(value),
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name u8aToBuffer
|
||||
@signature u8aToBuffer (value?: UInt8Array): Buffer
|
||||
@summary Creates a Buffer object from a hex string.
|
||||
@description
|
||||
`null` inputs returns an empty `Buffer` result. `UInt8Array` input values return the actual bytes value converted to a `Buffer`. Anything that is not a `UInt8Array` throws an error.
|
||||
@example
|
||||
import { u8aToBuffer } from '@polkadot/util';
|
||||
|
||||
console.log('Buffer', u8aToBuffer('0x123480001f'));
|
||||
*/
|
||||
* @name u8aToBuffer
|
||||
* @signature u8aToBuffer (value?: UInt8Array): Buffer
|
||||
* @summary Creates a Buffer object from a hex string.
|
||||
* @description
|
||||
* `null` inputs returns an empty `Buffer` result. `UInt8Array` input values return the actual bytes value converted to a `Buffer`. Anything that is not a `UInt8Array` throws an error.
|
||||
* @example
|
||||
* import { u8aToBuffer } from '@polkadot/util';
|
||||
*
|
||||
* console.log('Buffer', u8aToBuffer('0x123480001f'));
|
||||
*/
|
||||
export default function u8aToBuffer (value?: Uint8Array): Buffer {
|
||||
if (!value) {
|
||||
return Buffer.from([]);
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name u8aToHex
|
||||
@signature u8aToHex (value?: UInt8Array): string
|
||||
@summary Creates a hex string from a Uint8Array object.
|
||||
@description
|
||||
`UInt8Array` input values return the actual hex string. `null` or `undefined` values returns an `0x` string.
|
||||
@example
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
* @name u8aToHex
|
||||
* @signature u8aToHex (value?: UInt8Array): string
|
||||
* @summary Creates a hex string from a Uint8Array object.
|
||||
* @description
|
||||
* `UInt8Array` input values return the actual hex string. `null` or `undefined` values returns an `0x` string.
|
||||
* @example
|
||||
* import { u8aToHex } from '@polkadot/util';
|
||||
*
|
||||
* u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
export default function u8aToHex (value?: Uint8Array | null, bitLength: number = -1, isPrefixed: boolean = true): string {
|
||||
const prefix = isPrefixed
|
||||
? '0x'
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name u8aToString
|
||||
@signature u8aToString (value?: UInt8Array): string
|
||||
@summary Creates a string from a Uint8Array object.
|
||||
@description
|
||||
`UInt8Array` input values return the actual decoded 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
|
||||
*/
|
||||
* @name u8aToString
|
||||
* @signature u8aToString (value?: UInt8Array): string
|
||||
* @summary Creates a string from a Uint8Array object.
|
||||
* @description
|
||||
* `UInt8Array` input values return the actual decoded 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
|
||||
*/
|
||||
export default function u8aToString (value?: Uint8Array): string {
|
||||
if (!value || !value.length) {
|
||||
return '';
|
||||
|
||||
@@ -10,17 +10,17 @@ import hexToU8a from '../hex/toU8a';
|
||||
import u8aFromUtf8 from './fromUtf8';
|
||||
|
||||
/**
|
||||
@name u8aToU8a
|
||||
@signature u8aToU8a (value?: Uint8Array | string): Uint8Array
|
||||
@summary Creates a Uint8Array value from a Uint8Array bignumber or hex input.
|
||||
@description
|
||||
`null` inputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation.
|
||||
@example
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
|
||||
u8aToU8a(new Uint8Array([0x12, 0x34]); // => Uint8Array([0x12, 0x34])
|
||||
u8aToU8a(0x1234); // => Uint8Array([0x12, 0x34])
|
||||
*/
|
||||
* @name u8aToU8a
|
||||
* @signature u8aToU8a (value?: Uint8Array | string): Uint8Array
|
||||
* @summary Creates a Uint8Array value from a Uint8Array bignumber or hex input.
|
||||
* @description
|
||||
* `null` inputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation.
|
||||
* @example
|
||||
* import { u8aToU8a } from '@polkadot/util';
|
||||
*
|
||||
* u8aToU8a(new Uint8Array([0x12, 0x34]); // => Uint8Array([0x12, 0x34])
|
||||
* u8aToU8a(0x1234); // => Uint8Array([0x12, 0x34])
|
||||
*/
|
||||
export default function u8aToU8a (value?: Buffer | Uint8Array | string | null): Uint8Array {
|
||||
if (!value) {
|
||||
return new Uint8Array(0);
|
||||
|
||||
@@ -7,16 +7,16 @@ 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
|
||||
*/
|
||||
* @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 '';
|
||||
|
||||
Reference in New Issue
Block a user