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

@chronark/prefixed-id

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chronark/prefixed-id - npm Package Compare versions

Comparing version 0.3.8 to 0.4.0

dist/index.d.ts

30

package.json
{
"name": "@chronark/prefixed-id",
"version": "0.3.8",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"dependencies": {
"base-x": "^3.0.9"
"version": "0.4.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"keywords": [],
"author": "Andreas Thomas",
"license": "ISC",
"devDependencies": {
"@types/node": "^18.8.5",
"rome": "^11.0.0",
"tsup": "^6.2.3",
"tsx": "^3.10.1",
"typescript": "^4.8.4"
},
"peerDependencies": {}
}
"scripts": {
"test": "node --loader=tsx --test ./**/*.test.ts ",
"build": "tsup",
"fmt": "rome check . --apply-suggested && rome format . --write"
}
}

@@ -1,21 +0,55 @@

# prefixed-id
<div align="center">
<h1 align="center">@chronark/prefixed-id</h1>
<h5>pre_JUbF9zRGz9hrFXUyNJLXcowD9GsqCD</h5>
</div>
Easy way to generate prefixed unique ids similar to what stripe does.
Based on uuid v4.
<br/>
This is just a typesafe convenient wrapper for generating prefixed ids.
A minimal library to generate Stripe inspired predixed ids for your application.
# Usage
Works in
- Nodejs
- Cloudflare Workers
- Vercel Edge
```typescript
import { IdGenerator } from '@chronark/prefixed-id';
## Install
```
npm i @chronark/prefixed-id
```
## Usage
### Nodejs
```ts
import nodeCrypto from "node:crypto"
const idGenerator = new IdGenerator({
humanReadableName: 'prefix',
// Example:
user: 'u',
});
prefixes: {
"user": "u",
},
crypto: nodeCrypto
})
idGenerator.id('user');
// -> u_xxxxxxxxxxxxxxxxxx...
console.log(idGenerator.id("user"))
// u_PtbBA7NGcYYDpae6ULWujk
```
### WebCrypto
- Cloudflare Workers
- Vercel Edge
```ts
const idGenerator = new IdGenerator({
prefixes: {
"user": "u",
},
crypto: crypto // will be globally defined
})
console.log(idGenerator.id("user"))
// u_PtbBA7NGcYYDpae6ULWujk
```
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