@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hasPrefix = require('./hasPrefix');
|
||||
import hasPrefix from './hasPrefix';
|
||||
|
||||
/**
|
||||
@name hexAddPrefix
|
||||
@@ -16,7 +16,7 @@ const hasPrefix = require('./hasPrefix');
|
||||
|
||||
console.log('With prefix', hexAddPrefix('0a0b12')) // => 0x0a0b12
|
||||
*/
|
||||
module.exports = function hexAddPrefix (value: ?string): string {
|
||||
export default function hexAddPrefix (value: ?string): string {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (value && hasPrefix(value)) {
|
||||
return value;
|
||||
@@ -28,4 +28,4 @@ module.exports = function hexAddPrefix (value: ?string): string {
|
||||
: '';
|
||||
|
||||
return `0x${prefix}${value || ''}`;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexAddPrefix } = require('./index');
|
||||
import { hexAddPrefix } from './index';
|
||||
|
||||
describe('hexAddPrefix', () => {
|
||||
it('does not add when prefix is available', () => {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hexAddPrefix = require('./addPrefix');
|
||||
const hexStripPrefix = require('./stripPrefix');
|
||||
import hexAddPrefix from './addPrefix';
|
||||
import hexStripPrefix from './stripPrefix';
|
||||
|
||||
/**
|
||||
@name hexFixLength
|
||||
@@ -19,7 +19,7 @@ const hexStripPrefix = require('./stripPrefix');
|
||||
console.log('fixed', hexFixLength('0x12', 16, true)) // => 0x0012
|
||||
console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
|
||||
*/
|
||||
module.exports = function hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string {
|
||||
export default function hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string {
|
||||
const strLength = Math.ceil(bitLength / 4);
|
||||
const hexLength = strLength + 2;
|
||||
|
||||
@@ -38,4 +38,4 @@ module.exports = function hexFixLength (value: string, bitLength: number = -1, w
|
||||
return hexAddPrefix(
|
||||
`${'0'.repeat(strLength)}${hexStripPrefix(value)}`.slice(-1 * strLength)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexFixLength } = require('./index');
|
||||
import { hexFixLength } from './index';
|
||||
|
||||
describe('hexFixLength', () => {
|
||||
it('returns bitLength === -1 as-is', () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hexFromBn = require('../bn/toHex');
|
||||
import hexFromBn from '../bn/toHex';
|
||||
|
||||
/**
|
||||
@name hexFromBn
|
||||
@@ -11,4 +11,4 @@ const hexFromBn = require('../bn/toHex');
|
||||
@summary Creates a hex value from a BN.js bignumber object.
|
||||
@alias bn/toHex
|
||||
*/
|
||||
module.exports = hexFromBn;
|
||||
export default hexFromBn;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const isFunction = require('../is/function');
|
||||
import isFunction from '../is/function';
|
||||
|
||||
const { hexFromBn } = require('./index');
|
||||
import { hexFromBn } from './index';
|
||||
|
||||
describe('hexFromBn', () => {
|
||||
it('exists as a function', () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hexFromNumber = require('../number/toHex');
|
||||
import hexFromNumber from '../number/toHex';
|
||||
|
||||
/**
|
||||
@name hexFromNumber
|
||||
@@ -11,4 +11,4 @@ const hexFromNumber = require('../number/toHex');
|
||||
@summary Creates a hex value from a number.
|
||||
@alias number/toHex
|
||||
*/
|
||||
module.exports = hexFromNumber;
|
||||
export default hexFromNumber;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const isFunction = require('../is/function');
|
||||
import isFunction from '../is/function';
|
||||
|
||||
const { hexFromNumber } = require('./index');
|
||||
import { hexFromNumber } from './index';
|
||||
|
||||
describe('hexFromNumber', () => {
|
||||
it('exists as a function', () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const isHex = require('../is/hex');
|
||||
import isHex from '../is/hex';
|
||||
|
||||
/**
|
||||
@name hexHasPrefix
|
||||
@@ -16,7 +16,7 @@ const isHex = require('../is/hex');
|
||||
|
||||
console.log('has prefix', hexHasPrefix('0x1234')); // => true
|
||||
*/
|
||||
module.exports = function hexHasPrefix (value: ?string): boolean {
|
||||
export default function hexHasPrefix (value: ?string): boolean {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
return !!(value && isHex(value, -1, true) && value.substr(0, 2) === '0x');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexHasPrefix } = require('./index');
|
||||
import { hexHasPrefix } from './index';
|
||||
|
||||
describe('hexHasPrefix', () => {
|
||||
it('returns true when hex prefix is found', () => {
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hexAddPrefix = require('./addPrefix');
|
||||
const hexFixLength = require('./fixLength');
|
||||
const hexFromBn = require('./fromBn');
|
||||
const hexFromNumber = require('./fromNumber');
|
||||
const hexHasPrefix = require('./hasPrefix');
|
||||
const hexStripPrefix = require('./stripPrefix');
|
||||
const hexToBn = require('./toBn');
|
||||
const hexToNumber = require('./toNumber');
|
||||
const hexToU8a = require('./toU8a');
|
||||
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';
|
||||
import hexToNumber from './toNumber';
|
||||
import hexToU8a from './toU8a';
|
||||
|
||||
/**
|
||||
@summary Internal utilities to create and test for hex values
|
||||
*/
|
||||
module.exports = {
|
||||
export {
|
||||
hexAddPrefix,
|
||||
hexFixLength,
|
||||
hexFromBn,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hasPrefix = require('./hasPrefix');
|
||||
import hasPrefix from './hasPrefix';
|
||||
|
||||
const UNPREFIX_HEX_REGEX = /^[a-fA-F0-9]+$/;
|
||||
|
||||
@@ -18,7 +18,7 @@ const UNPREFIX_HEX_REGEX = /^[a-fA-F0-9]+$/;
|
||||
|
||||
console.log('stripped', hexStripPrefix('0x1234')); // => 1234
|
||||
*/
|
||||
module.exports = function hexStripPrefix (value: ?string): string {
|
||||
export default function hexStripPrefix (value: ?string): string {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (!value) {
|
||||
return '';
|
||||
@@ -33,4 +33,4 @@ module.exports = function hexStripPrefix (value: ?string): string {
|
||||
}
|
||||
|
||||
throw new Error(`Invalid hex ${value} passed to hexStripPrefix`);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexStripPrefix } = require('./index');
|
||||
import { hexStripPrefix } from './index';
|
||||
|
||||
describe('hexStripPrefix', () => {
|
||||
it('returns an empty string when null value supplied', () => {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const BN = require('bn.js');
|
||||
import BN from 'bn.js';
|
||||
|
||||
const hexStripPrefix = require('./stripPrefix');
|
||||
import hexStripPrefix from './stripPrefix';
|
||||
|
||||
function reverse (value: string): string {
|
||||
return (value.match(new RegExp('.{1,2}', 'g')) || [])
|
||||
@@ -24,7 +24,7 @@ function reverse (value: string): string {
|
||||
|
||||
hexToBn('0x123480001f'); // => BN(0x123480001f)
|
||||
*/
|
||||
module.exports = function hexToBn (_value?: string, isLe: boolean = false): BN {
|
||||
export default function hexToBn (_value?: string, isLe: boolean = false): BN {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (!_value) {
|
||||
return new BN(0);
|
||||
@@ -33,4 +33,4 @@ module.exports = function hexToBn (_value?: string, isLe: boolean = false): BN {
|
||||
const value = hexStripPrefix(_value);
|
||||
|
||||
return new BN((isLe ? reverse(value) : value) || '00', 16);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexToBn } = require('./index');
|
||||
import { hexToBn } from './index';
|
||||
|
||||
describe('hexToBn', () => {
|
||||
it('converts prefixed hex values to BN', () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const hexToBn = require('./toBn');
|
||||
import hexToBn from './toBn';
|
||||
|
||||
/**
|
||||
@name hexToNumber
|
||||
@@ -16,11 +16,11 @@ const hexToBn = require('./toBn');
|
||||
|
||||
hexToNumber('0x1234'); // => 0x1234
|
||||
*/
|
||||
module.exports = function hexToNumber (value?: string): number {
|
||||
export default function hexToNumber (value?: string): number {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (!value) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
return hexToBn(value).toNumber();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexToNumber } = require('./index');
|
||||
import { hexToNumber } from './index';
|
||||
|
||||
describe('hexToNumber', () => {
|
||||
it('converts an empty to NaN', () => {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
const assert = require('../assert');
|
||||
const isHex = require('../is/hex');
|
||||
const hexStripPrefix = require('./stripPrefix');
|
||||
import assert from '../assert';
|
||||
import isHex from '../is/hex';
|
||||
import hexStripPrefix from './stripPrefix';
|
||||
|
||||
/**
|
||||
@name hexToU8a
|
||||
@@ -19,7 +19,7 @@ const hexStripPrefix = require('./stripPrefix');
|
||||
hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
|
||||
hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
|
||||
*/
|
||||
module.exports = function hexToU8a (_value?: string | null, bitLength: number = -1): Uint8Array {
|
||||
export default function hexToU8a (_value?: string | null, bitLength: number = -1): Uint8Array {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
if (!_value) {
|
||||
return new Uint8Array([]);
|
||||
@@ -42,4 +42,4 @@ module.exports = function hexToU8a (_value?: string | null, bitLength: number =
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const { hexToU8a } = require('./index');
|
||||
import { hexToU8a } from './index';
|
||||
|
||||
describe('hexToU8a', () => {
|
||||
it('returns an empty Uint8Array when null provided', () => {
|
||||
|
||||
Reference in New Issue
Block a user