https://github.com/garrettmac/unique-hash
https://github.com/garrettmac/unique-hash
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/garrettmac/unique-hash
- Owner: garrettmac
- Created: 2017-07-27T16:52:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-07T06:50:14.000Z (almost 3 years ago)
- Last Synced: 2024-04-25T05:42:36.097Z (about 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
The best package to create hash ids.
# unique-hash
Useful for saving to
```javascript
import uniqueHash from "unique-hash"//or es5
//var uniqueHash = require("unique-hash").default
let url = "https://www.npmjs.com/package/unique-hash"uniqueHash(url)
//>> output 88870086uniqueHash(url)
//>> output 88870086uniqueHash(url,{format:"string"})
//>> output "iIIHaAIG"uniqueHash(url,{format:"string"})
//>> output "iIIHaAIG"uniqueHash("John H. Smith")
//>> output 983277668
uniqueHash("John H Smith")
//>> output 983277668
uniqueHash("JohnHSmith")
//>> output 983277668uniqueHash("John H. Smith",{format:"kebabCase"})
//>> output "john-h-smith"
uniqueHash("John H Smith",{format:"kebabCase"})
//>> output "john-h-smith"
uniqueHash("JohnHSmith",{format:"kebabCase"})
//>> output "john-h-smith"uniqueHash(url,{
prepend:"articles",
date:new Date(),
})
//>> output "articles/2017/08/27/88870086"uniqueHash(url,{
prepend:"articles",
append:"videos",
appendDate:"hot",
date:new Date(),
formatDate:"YYYY/DD",
format:"string"
})
//>> output "articles/2017/08/hot/iIIHaAIG/videos"```
### Parameters
| Parameter | Default | Description |
|------|-----|-----|
| format | "number" | options: "number", "string" or "kebabCase" |
| prepend | "" | string to prepend output path |
| append | "" |string to append output path |
| appendDate | "" | string to center between date and hash id (eg. output `/YYYY/MM/DD/[HERE]/:hashId`) |
| date | n/a | pass in date to append /YYYY/MM/DD to save path |
| dateFormate | "YYYY/MM/DD" | Date format |
| hashId | n/a | override the output hashId, useful if you want to use with date. |