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

@sumor/short-id

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/short-id

This is a short-id library for Node.js and the browser. You can easily use it to generate a short id from number.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
48K
decreased by-24.23%
Maintainers
0
Weekly downloads
 
Created
Source

short-id

A Sumor Cloud Tool.
More Documentation

This is a short-id library for Node.js and the browser. You can easily use it to generate a short id from number.

CI Test Coverage Audit

Installation

npm i @sumor/short-id --save

Prerequisites

Node.JS version

Require Node.JS version 18.x or above

require Node.JS ES module

As this package is written in ES module, please change the following code in your package.json file:

{
  "type": "module"
}

Usage

Standard Usage
import { encode, decode } from '@sumor/short-id'

// by default using rule 0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ
const shortId1 = encode(10)
console.log(shortId1) // 'a'
const shortId2 = encode(72)
console.log(shortId2) // '1a'

const number1 = decode('a')
console.log(number1) // 10
const number2 = decode('1a')
console.log(number2) // 72
Custom Usage
import { encode, decode } from '@sumor/short-id'

const rule = '0123456789abcdefghigklmnopqrstuvwxyz'
const shortId1 = encode(10, rule)
console.log(shortId1) // 'a'
const shortId2 = encode(46, rule)
console.log(shortId2) // '1a'

const number1 = decode('a', rule)
console.log(number1) // 10
const number2 = decode('1a', rule)
console.log(number2) // 46

Keywords

FAQs

Package last updated on 08 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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