Skip to content

Commit

Permalink
bump packages version (#24)
Browse files Browse the repository at this point in the history
* bump uuid package version

* bump hashids package version

* bump typescript package version

* bump standard package version
  • Loading branch information
panmona authored Jul 1, 2021
1 parent 7284ec9 commit d22822d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions hyperid.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

const uuid = require('uuid/v4')
const { v4: uuidv4 } = require('uuid')
const parser = require('uuid-parse')
const maxInt = Math.pow(2, 31) - 1
const Buffer = require('buffer').Buffer

function hyperid (opts) {
var fixedLength = false
var urlSafe = false
let fixedLength = false
let urlSafe = false
if (typeof opts === 'boolean') {
fixedLength = opts
} else {
Expand All @@ -16,11 +16,11 @@ function hyperid (opts) {
fixedLength = !!opts.fixedLength
}

generate.uuid = uuid()
generate.uuid = uuidv4()
generate.decode = decode

var id = baseId(generate.uuid, urlSafe)
var count = Math.floor(opts.startFrom || 0)
let id = baseId(generate.uuid, urlSafe)
let count = Math.floor(opts.startFrom || 0)

if (isNaN(count) || !(maxInt > count && count >= 0)) {
throw new Error([
Expand All @@ -33,12 +33,12 @@ function hyperid (opts) {
return generate

function generate () {
var result = fixedLength
const result = fixedLength
? id + pad(count++)
: id + count++

if (count === maxInt) {
generate.uuid = uuid()
generate.uuid = uuidv4()
id = baseId(generate.uuid, urlSafe) // rebase
count = 0
}
Expand All @@ -61,8 +61,8 @@ function pad (count) {
}

function baseId (id, urlSafe) {
var base64Id = Buffer.from(parser.parse(id)).toString('base64')
var l = base64Id.length
let base64Id = Buffer.from(parser.parse(id)).toString('base64')
const l = base64Id.length
if (urlSafe) {
if (base64Id[l - 2] === '=' && base64Id[l - 1] === '=') {
base64Id = base64Id.substr(0, l - 2) + '-'
Expand All @@ -77,7 +77,7 @@ function baseId (id, urlSafe) {

function decode (id, opts) {
opts = opts || {}
var urlSafe = !!opts.urlSafe
const urlSafe = !!opts.urlSafe

if (urlSafe) {
id = id.replace(/-/g, '/').replace(/_/g, '+')
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
"devDependencies": {
"benchmark": "^2.1.4",
"bloomfilter": "0.0.18",
"hashids": "^1.2.2",
"hashids": "^2.2.8",
"nanoid": "^3.1.20",
"nid": "^1.1.0",
"pre-commit": "^1.2.2",
"shortid": "^2.2.15",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tap-dot": "^2.0.0",
"tape": "^5.0.0",
"typescript": "^3.8.3"
"typescript": "^4.3.4"
},
"dependencies": {
"uuid": "^3.4.0",
"uuid": "^8.3.2",
"uuid-parse": "^1.1.0"
}
}
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('generating unique ids', function (t) {
const instance = hyperid()
const ids = []

for (var i = 0; i < 2048; i++) {
for (let i = 0; i < 2048; i++) {
const id = instance()

if (ids.indexOf(id) >= 0) {
Expand All @@ -28,7 +28,7 @@ test('generating unique ids are correct length when fixedLength set to true', fu

const instance = hyperid(true)

for (var i = 0; i < 1000000; i++) {
for (let i = 0; i < 1000000; i++) {
const id = instance()

if (id.length !== 33) {
Expand All @@ -45,7 +45,7 @@ test('generating unique ids are correct length when fixedLength set to true (as

const instance = hyperid({ fixedLength: true })

for (var i = 0; i < 1000000; i++) {
for (let i = 0; i < 1000000; i++) {
const id = instance()

if (id.length !== 33) {
Expand Down
12 changes: 6 additions & 6 deletions test/uniqueness.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ test('uniqueness', function (t) {
16 // number of hash functions.
)

var conflicts = 0
var ids = 0
let conflicts = 0
let ids = 0

const max = maxInt * 2

for (var i = 0; i < max; i += Math.ceil(Math.random() * 4096)) {
for (let i = 0; i < max; i += Math.ceil(Math.random() * 4096)) {
const id = instance()

if (bloom.test(id)) {
Expand All @@ -45,12 +45,12 @@ test('url safe uniqueness', function (t) {
16 // number of hash functions.
)

var conflicts = 0
var ids = 0
let conflicts = 0
let ids = 0

const max = maxInt * 2

for (var i = 0; i < max; i += Math.ceil(Math.random() * 4096)) {
for (let i = 0; i < max; i += Math.ceil(Math.random() * 4096)) {
const id = instance()

if (bloom.test(id)) {
Expand Down

0 comments on commit d22822d

Please sign in to comment.