Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ksuid

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ksuid - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

4

base62.js

@@ -7,3 +7,3 @@ 'use strict'

function encode (buffer, fixedLength) {
return baseConvertIntArray(buffer, {from: 256, to: 62, fixedLength})
return baseConvertIntArray(buffer, { from: 256, to: 62, fixedLength })
.map(value => CHARS[value])

@@ -22,4 +22,4 @@ .join('')

})
return Buffer.from(baseConvertIntArray(input, {from: 62, to: 256, fixedLength}))
return Buffer.from(baseConvertIntArray(input, { from: 62, to: 256, fixedLength }))
}
exports.decode = decode

@@ -13,3 +13,7 @@ /// <reference types="node" />

static random(): Promise<KSUID>;
static random(timeInMs: number): Promise<KSUID>;
static random(date: Date): Promise<KSUID>;
static randomSync(): KSUID;
static randomSync(timeInMs: number): KSUID;
static randomSync(date: Date): KSUID;
static fromParts(timeInMs: number, payload: Buffer): KSUID;

@@ -16,0 +20,0 @@ static isValid(buffer: Buffer): boolean;

'use strict'
const {randomBytes} = require('crypto')
const {inspect: {custom: customInspectSymbol}} = require('util')
const padStart = require('string.prototype.padstart')
const { randomBytes } = require('crypto')
const { inspect: { custom: customInspectSymbol }, promisify } = require('util')
const base62 = require('./base62')
function asyncRandomBytes (size) {
return new Promise((resolve, reject) => {
randomBytes(size, (err, bytes) => {
/* istanbul ignore if */
if (err) {
reject(err)
} else {
resolve(bytes)
}
})
})
}
const asyncRandomBytes = promisify(randomBytes)

@@ -26,3 +13,3 @@ // KSUID's epoch starts more recently so that the 32-bit number space gives a

const MAX_TIME_IN_MS = 1e3 * (Math.pow(2, 32) - 1) + EPOCH_IN_MS
const MAX_TIME_IN_MS = 1e3 * (2 ** 32 - 1) + EPOCH_IN_MS

@@ -93,3 +80,3 @@ // Timestamp is a uint32

const encoded = base62.encode(bufferLookup.get(this), STRING_ENCODED_LENGTH)
return padStart(encoded, STRING_ENCODED_LENGTH, '0')
return encoded.padStart(STRING_ENCODED_LENGTH, '0')
}

@@ -117,9 +104,10 @@

static random () {
return asyncRandomBytes(PAYLOAD_BYTE_LENGTH).then(payload => new KSUID(fromParts(Date.now(), payload)))
static async random (time = Date.now()) {
const payload = await asyncRandomBytes(PAYLOAD_BYTE_LENGTH)
return new KSUID(fromParts(Number(time), payload))
}
static randomSync () {
static randomSync (time = Date.now()) {
const payload = randomBytes(PAYLOAD_BYTE_LENGTH)
return new KSUID(fromParts(Date.now(), payload))
return new KSUID(fromParts(Number(time), payload))
}

@@ -159,8 +147,8 @@

}
Object.defineProperty(KSUID.prototype, Symbol.toStringTag, {value: 'KSUID'})
Object.defineProperty(KSUID.prototype, Symbol.toStringTag, { value: 'KSUID' })
// A string-encoded maximum value for a KSUID
Object.defineProperty(KSUID, 'MAX_STRING_ENCODED', {value: 'aWgEPTl1tmebfsQzFP4bxwgy80V'})
Object.defineProperty(KSUID, 'MAX_STRING_ENCODED', { value: 'aWgEPTl1tmebfsQzFP4bxwgy80V' })
// A string-encoded minimum value for a KSUID
Object.defineProperty(KSUID, 'MIN_STRING_ENCODED', {value: '000000000000000000000000000'})
Object.defineProperty(KSUID, 'MIN_STRING_ENCODED', { value: '000000000000000000000000000' })
module.exports = KSUID
{
"name": "ksuid",
"version": "1.2.0",
"version": "2.0.0",
"description": "Node.js implementation of K-Sortable Globally Unique IDs",
"engine": {
"node": ">=6 <7 || >=8 <9 || >=10"
"node": ">=10 <11 || >=12 <13 || >=14"
},
"main": "index.js",
"types": "index.d.ts",
"files": [

@@ -16,4 +15,3 @@ "index.js",

"scripts": {
"lint": "as-i-preach",
"test": "npm run -s lint && tsc --noEmit test/typings.ts && nyc ava"
"test": "standard && tsd && c8 ava"
},

@@ -35,22 +33,12 @@ "repository": {

"dependencies": {
"base-convert-int-array": "^1.0.1",
"string.prototype.padstart": "^3.0.0"
"base-convert-int-array": "^1.0.1"
},
"devDependencies": {
"@novemberborn/as-i-preach": "^10.1.0",
"@types/node": "^10.12.18",
"ava": "^1.1.0",
"codecov": "^3.1.0",
"lolex": "^3.0.0",
"nyc": "^13.1.0",
"typescript": "^3.2.4"
},
"nyc": {
"reporter": [
"html",
"lcov",
"text"
]
},
"standard-engine": "@novemberborn/as-i-preach"
"@sinonjs/fake-timers": "^6.0.1",
"@types/node": "^10.17.28",
"ava": "^3.11.1",
"c8": "^7.3.0",
"standard": "^14.3.4",
"tsd": "^0.13.1"
}
}
# ksuid
A Node.js implementation of [Segment's KSUID
library](https://github.com/segmentio/ksuid). Supports Node.js 6, 8 and 10.
A Node.js implementation of [Segment's KSUID library](https://github.com/segmentio/ksuid). Supports Node.js 10, 12, 14 and newer.
You may also be interested in
[`ksuid-cli`](https://www.npmjs.com/package/ksuid-cli).
You may also be interested in [`ksuid-cli`](https://www.npmjs.com/package/ksuid-cli).

@@ -23,8 +21,2 @@ ## Installation

Or, using [TypeScript](https://www.typescriptlang.org/):
```typescript
import KSUID = require('ksuid')
```
### Creation

@@ -44,2 +36,9 @@

You can also specify a specific time, either in milliseconds or as a `Date` object:
```js
const ksuidFromDate = KSUID.randomSync(new Date("2014-05-25T16:53:20Z"))
const ksuidFromMillisecondsAsync = await KSUID.random(1401036800000)
```
Or you can compose it using a timestamp and a 16-byte payload:

@@ -46,0 +45,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc