https://github.com/entwicklerstube/hashids-in-object
🔎 Go through object, detect id values and decode or encode them
https://github.com/entwicklerstube/hashids-in-object
decode encode hash hashids object url
Last synced: 7 months ago
JSON representation
🔎 Go through object, detect id values and decode or encode them
- Host: GitHub
- URL: https://github.com/entwicklerstube/hashids-in-object
- Owner: entwicklerstube
- License: mit
- Created: 2017-05-28T08:43:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-20T08:46:16.000Z (about 8 years ago)
- Last Synced: 2025-03-04T05:34:54.556Z (7 months ago)
- Topics: decode, encode, hash, hashids, object, url
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/hashids-in-object
- Size: 34.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hashids in object
> Go through object, detect id values and decode or encode them[](https://travis-ci.org/entwicklerstube/hashids-in-object)
### Install
**yarn**
```
yarn add hashids-in-object
```**npm**
```
npm install hashids-in-object --save
```### Usage
```js
import { encode, decode } from 'hashids-in-object'// Input
const example = {
id: 123,
user_id: 391,
name: 'Michael',
contact_id: 12,
some: {
deep: [{
object: {
in: {
array: [{
id: 1
}]
}
}
}]
}
}// Process
const encodedExample = encode(example)// Output
{
id: 'aMj3b',
user_id: 'elpJe',
name: 'Michael',
contact_id: '7ax9b',
some: {
deep: [{
object: {
in: {
array: [{
id: 'aMj3b'
}]
}
}
}]
}
}// Decode it:
decode(encodedExample)// Output
{
id: 123,
user_id: 391,
name: 'Michael',
contact_id: 12,
some: {
deep: [{
object: {
in: {
array: [{
id: 1
}]
}
}
}]
}
}
```### Under the hood
At the moment it uses the [`hashids.js`](https://github.com/ivanakimov/hashids.js) module to encode/decode the single id's.