@appliedblockchain/helpers
Advanced tools
Comparing version 3.2.1 to 3.3.0
// @flow | ||
const { from: bufferOf } = Buffer | ||
const { inspect } = require('util') | ||
const evenZeroPaddedOf = require('./even-zero-padded-of') | ||
const isHex = require('./is-hex') | ||
/** @returns buffer representation of provided hex string. */ | ||
function bufferOfHex(value /*: string */) { | ||
@@ -10,5 +13,5 @@ if (!isHex(value)) { | ||
} | ||
return Buffer.from(value, 'hex') | ||
return bufferOf(evenZeroPaddedOf(value), 'hex') | ||
} | ||
module.exports = bufferOfHex |
// @flow | ||
const { from: bufferOf } = Buffer | ||
const { inspect } = require('util') | ||
const evenZeroPaddedOf = require('./even-zero-padded-of') | ||
const isHex0x = require('./is-hex0x') | ||
function bufferOfHex0x(value /*: string */) { | ||
/** @returns buffer representation of provided hex0x string. */ | ||
function bufferOfHex0x(value /*: string */) /*: Buffer */ { | ||
if (!isHex0x(value)) { | ||
throw new TypeError(`Expected hex0x string, got ${inspect(value)}.`) | ||
} | ||
return Buffer.from(value.slice(2), 'hex') | ||
return bufferOf(evenZeroPaddedOf(value.slice(2)), 'hex') | ||
} | ||
module.exports = bufferOfHex0x |
# Changelog | ||
## [v3.3.0](../../compare/v3.2.1...v3.3.0) (2019-12-12) | ||
* Adding note on reject-timeout. | ||
* Adding race-promises helper. | ||
* Rearranging test to run linter first, adding BigInt as global to eslint. | ||
* Adding poor-man's big-int hack around flow not supporting bigint yet. | ||
* Adding buffer-of-unsigned helper. | ||
* Renaming hex-of-number to hex-of-unsigned. | ||
* Reusing hex-of-number helper to return correctly odd-padded hex. | ||
* Using padding helper in hex-of-number. | ||
* Updating buffer-of-hex/hex0x helpers to work correctly on odd strings. | ||
* Adding even-zero-padded-of helper. | ||
* Adding hex-of-number helper. | ||
* Adding is-safe-unsigned helper. | ||
* Updating changelog. | ||
## [v3.2.1](../../compare/v3.2.0...v3.2.1) (2019-12-03) | ||
@@ -4,0 +20,0 @@ |
// @flow | ||
const { inspect } = require('util') | ||
const isSafeNonNegative = require('./is-safe-non-negative') | ||
const hexOfNumber = require('./hex-of-number') | ||
/** @returns 0x-prefixed hex string representation of a safe, non-negative integer number. */ | ||
/** @returns 0x-prefixed hex string representation of a safe, unsigned number. */ | ||
function hex0xOfNumber(value /*: number */) /*: string */ { | ||
if (!isSafeNonNegative(value)) { | ||
throw new TypeError(`Expected safe, non-negative number, got ${inspect(value)}.`) | ||
} | ||
return '0x' + value.toString(16) | ||
return '0x' + hexOfNumber(value) | ||
} | ||
module.exports = hex0xOfNumber |
// @flow | ||
const { isSafeInteger } = Number | ||
/** Returns `true` if value is safe integer greater than or equal to zero, `false` otherwise. */ | ||
function isSafeNonNegative(value /*: mixed */) /*: boolean %checks */ { | ||
return ( | ||
typeof value === 'number' && | ||
value >= 0 && | ||
isSafeInteger(value) | ||
) | ||
} | ||
module.exports = isSafeNonNegative | ||
module.exports = require('./is-safe-unsigned') |
{ | ||
"name": "@appliedblockchain/helpers", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "No dependency, single file helpers.", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"doc": "npx documentation readme --section=Api *.js", | ||
"test": "flow check && eslint . && jest", | ||
"test": "eslint . && flow check && jest", | ||
"patch": "npm test && npm version patch && git push && git push --tags && npm publish", | ||
@@ -38,2 +38,5 @@ "minor": "npm test && npm version minor && git push && git push --tags && npm publish", | ||
] | ||
}, | ||
"globals": { | ||
"BigInt": true | ||
} | ||
@@ -40,0 +43,0 @@ }, |
@@ -9,2 +9,4 @@ // @flow | ||
promise.finally(() => clearTimeout(timeoutId)), | ||
// TODO: This leaks promise object. | ||
new Promise((resolve, reject) => { | ||
@@ -11,0 +13,0 @@ timeoutId = setTimeout( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132102
122
3483