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

@thi.ng/idgen

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/idgen - npm Package Compare versions

Comparing version 0.2.20 to 0.2.21

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [0.2.21](https://github.com/thi-ng/umbrella/compare/@thi.ng/idgen@0.2.20...@thi.ng/idgen@0.2.21) (2020-08-28)
**Note:** Version bump only for package @thi.ng/idgen
## [0.2.20](https://github.com/thi-ng/umbrella/compare/@thi.ng/idgen@0.2.19...@thi.ng/idgen@0.2.20) (2020-08-17)

@@ -8,0 +16,0 @@

2

lib/index.umd.js

@@ -1,1 +0,1 @@

!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("tslib"),require("@thi.ng/api")):"function"==typeof define&&define.amd?define(["exports","tslib","@thi.ng/api"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.idgen={}),t.thi.ng[""],t.thi.ng.api)}(this,(function(t,i,e){"use strict";t.IDGen=class{constructor(t=32,i=32-t,s=2**t,h=0){const n=2**t;e.assert(t>0&&t+i<=32,"wrong total bit size [1..32]"),e.assert(s<=n,`requested capacity too large for bit size (max. ${n})`),this.ids=[],this.nextID=h,this.start=h,this._capacity=s,this.num=0,this.mask=n-1,this.vmask=(1<<i)-1,this.shift=t,this._freeID=-1}id(t){return t&this.mask}version(t){return t>>>this.shift&this.vmask}get capacity(){return this._capacity}set capacity(t){if(e.assert(!this.vmask,"can't change capacity w/ versioning enabled"),!(t>=this.mask+1))throw new Error("can't reduce capacity");{const i=Math.ceil(Math.log2(t));e.assert(i>0&&i<=32,"wrong bit size for new capacity [1..32]"),this._capacity=t,this.mask=2**i-1,this.shift=i}}get available(){return this._capacity-this.num-this.start}get used(){return this.num}get freeID(){return this._freeID}*[Symbol.iterator](){for(let t=this.nextID;--t>=0;){const i=this.ids[t];(i&this.mask)===t&&(yield i)}}clear(){this.ids.length=0,this.nextID=this.start,this.num=0,this._freeID=-1}next(){let t;if(-1!==this._freeID){t=this._freeID;const i=this.id(t);this._freeID=this.ids[i],this.ids[i]=t}else e.assert(this.nextID<this._capacity,"max capacity reached"),t=this.nextID++,this.ids[t]=t;return this.num++,this.notify({id:"added",target:this,value:t}),t}free(t){return!!this.has(t)&&(this.ids[this.id(t)]=this._freeID,this._freeID=this.nextVersion(t),this.num--,this.notify({id:"removed",target:this,value:t}),!0)}has(t){const i=this.id(t);return t>=0&&i<this.nextID&&this.ids[i]===t}addListener(t,i,e){}removeListener(t,i,e){}notify(t){}nextVersion(t){return(t&this.mask|(this.version(t)+1&this.vmask)<<this.shift)>>>0}},t.IDGen=i.__decorate([e.INotifyMixin],t.IDGen);t.EVENT_ADDED="added",t.EVENT_REMOVED="removed",t.idgen=(i,e,s,h)=>new t.IDGen(i,e,s,h),Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("tslib"),require("@thi.ng/api")):"function"==typeof define&&define.amd?define(["exports","tslib","@thi.ng/api"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.idgen={}),t.thi.ng[""],t.thi.ng.api)}(this,(function(t,i,e){"use strict";const s="added",h="removed";t.IDGen=class{constructor(t=32,i=32-t,s=2**t,h=0){const n=2**t;e.assert(t>0&&t+i<=32,"wrong total bit size [1..32]"),e.assert(s<=n,`requested capacity too large for bit size (max. ${n})`),this.ids=[],this.nextID=h,this.start=h,this._capacity=s,this.num=0,this.mask=n-1,this.vmask=(1<<i)-1,this.shift=t,this._freeID=-1}id(t){return t&this.mask}version(t){return t>>>this.shift&this.vmask}get capacity(){return this._capacity}set capacity(t){if(e.assert(!this.vmask,"can't change capacity w/ versioning enabled"),!(t>=this.mask+1))throw new Error("can't reduce capacity");{const i=Math.ceil(Math.log2(t));e.assert(i>0&&i<=32,"wrong bit size for new capacity [1..32]"),this._capacity=t,this.mask=2**i-1,this.shift=i}}get available(){return this._capacity-this.num-this.start}get used(){return this.num}get freeID(){return this._freeID}*[Symbol.iterator](){for(let t=this.nextID;--t>=0;){const i=this.ids[t];(i&this.mask)===t&&(yield i)}}clear(){this.ids.length=0,this.nextID=this.start,this.num=0,this._freeID=-1}next(){let t;if(-1!==this._freeID){t=this._freeID;const i=this.id(t);this._freeID=this.ids[i],this.ids[i]=t}else e.assert(this.nextID<this._capacity,"max capacity reached"),t=this.nextID++,this.ids[t]=t;return this.num++,this.notify({id:s,target:this,value:t}),t}free(t){return!!this.has(t)&&(this.ids[this.id(t)]=this._freeID,this._freeID=this.nextVersion(t),this.num--,this.notify({id:h,target:this,value:t}),!0)}has(t){const i=this.id(t);return t>=0&&i<this.nextID&&this.ids[i]===t}addListener(t,i,e){}removeListener(t,i,e){}notify(t){}nextVersion(t){return(t&this.mask|(this.version(t)+1&this.vmask)<<this.shift)>>>0}},t.IDGen=i.__decorate([e.INotifyMixin],t.IDGen);t.EVENT_ADDED=s,t.EVENT_REMOVED=h,t.idgen=(i,e,s,h)=>new t.IDGen(i,e,s,h),Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@thi.ng/idgen",
"version": "0.2.20",
"version": "0.2.21",
"description": "Generator of opaque numeric identifiers with optional support for ID versioning and efficient re-use",

@@ -42,13 +42,13 @@ "module": "./index.js",

"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@microsoft/api-extractor": "^7.9.2",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.26",
"mocha": "^8.1.1",
"@microsoft/api-extractor": "^7.9.11",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.1",
"mocha": "^8.1.2",
"nyc": "^15.1.0",
"ts-node": "^8.10.1",
"ts-node": "^9.0.0",
"typedoc": "^0.18.0",
"typescript": "^3.9.7"
"typescript": "^4.0.2"
},
"dependencies": {
"@thi.ng/api": "^6.12.2",
"@thi.ng/api": "^6.12.3",
"tslib": "^2.0.1"

@@ -77,3 +77,3 @@ },

},
"gitHead": "44824f17050b412d635b576bf5f9b2136dac9554"
"gitHead": "3a55c0df86c5be9c56a1e1a4c0cfcaa2809a160a"
}

@@ -64,3 +64,3 @@ <!-- This file is generated - DO NOT EDIT! -->

Package sizes (gzipped, pre-treeshake): ESM: 843 bytes / CJS: 890 bytes / UMD: 997 bytes
Package sizes (gzipped, pre-treeshake): ESM: 843 bytes / CJS: 890 bytes / UMD: 1006 bytes

@@ -67,0 +67,0 @@ ## Dependencies

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