Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/weihongyu12/think-hashids

Generate a short unique ID from the integer for ThinkJS
https://github.com/weihongyu12/think-hashids

Last synced: 4 months ago
JSON representation

Generate a short unique ID from the integer for ThinkJS

Lists

README

        

# think-hashids
[![npm](https://img.shields.io/npm/v/think-hashids.svg)](https://www.npmjs.com/package/think-hashids)
[![Build Status](https://travis-ci.org/weihongyu12/think-hashids.svg?branch=master)](https://travis-ci.org/weihongyu12/think-hashids)
[![Coverage Status](https://coveralls.io/repos/github/weihongyu12/think-hashids/badge.svg?branch=master)](https://coveralls.io/github/weihongyu12/think-hashids?branch=master)

Generate a short unique ID from the integer for ThinkJS base on [hashids](http://hashids.org/)

## How to use

### Install

```bash
npm install think-hashids --save
```

### Configure extends.js
```javascript
const hashids = require('think-hashids')

module.exports = [
hashids({
salt: 'this is salt',
minLength: 10,
alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
})
];
```

## Config
- salt: Participate in the calculated salt. Default: ''
- minLength: The minimum length of the resulting result. Default:0
- alphabet: Generates the resulting character set .Default: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'

## Method

- this.encode(id): Encode ID
- this.decode(id): Decode ID
- this.encodeHex(id): Encode hex instead of numbers
- this.decodeHex(id): Decode hex instead of numbers