to-unsigned-int32
Advanced tools
Comparing version 1.0.1 to 2.0.0
14
index.js
@@ -0,4 +1,7 @@ | ||
module.exports = toUInt32 | ||
module.exports.toUInt32Sync = toUInt32Sync | ||
var dz = require('dezalgo') | ||
module.exports = function (n, callback) { | ||
function toUInt32 (n, callback) { | ||
callback = dz(callback) | ||
@@ -14,1 +17,10 @@ | ||
} | ||
function toUInt32Sync (n) { | ||
if (n >= 0xff) { | ||
throw new Error('Number can not represent in 32 bit') | ||
} | ||
var buffr = new Buffer(4) | ||
buffr.writeUInt32BE(n, 0) | ||
return buffr | ||
} |
{ | ||
"name": "to-unsigned-int32", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "convert to number of 32 bit buffer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,25 +15,37 @@ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
``` | ||
## Usage | ||
```js | ||
var toUInt32 = require('to-unsigned-int32') | ||
## API | ||
toUInt32(12, function (err, res) { | ||
console.log(res) //<Buffer 00 00 00 0c> | ||
}) | ||
1. #####Async API | ||
``` | ||
Module only support async api. | ||
```js | ||
var toUInt32 = require('to-unsigned-int32') | ||
`n` can be number in any base. | ||
toUInt32(12, function (err, res) { | ||
console.log(res) //<Buffer 00 00 00 0c> | ||
}) | ||
`callback` get two arguments: | ||
``` | ||
1. An error object. | ||
`n` can be number in any base. | ||
2. Buffer with length of 4. | ||
`callback` get two arguments: | ||
* An error object. | ||
* Buffer with length of 4. | ||
2. #####Sync API | ||
```js | ||
var toUInt32 = require('to-unsigned-int32') | ||
console.log(toUInt32.toUInt32Sync(12)) //<Buffer 00 00 00 0c> | ||
``` | ||
`n` can be number in any base. | ||
returns buffer with length 4. | ||
## licence | ||
=== | ||
MIT | ||
@@ -22,1 +22,14 @@ var tap = require('tap') | ||
}) | ||
tap.test('toUInt32Sync: should throw error when number can not fit in 32 bit', function (t) { | ||
t.throws(function () { | ||
toUInt32.toUInt32Sync(0xfff) | ||
}, 'Number can not represent in 32 bit') | ||
t.end() | ||
}) | ||
tap.test('toUInt32Sync: should return correct buffer for value number', function (t) { | ||
var buffr = toUInt32.toUInt32Sync(0xC) | ||
t.equal(buffr.readUInt32BE(0), 0xC) | ||
t.end() | ||
}) |
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
3175
50
51