https://github.com/fabiospampinato/strid
Get a unique string identifier for any input value.
https://github.com/fabiospampinato/strid
identifier string unique
Last synced: 11 months ago
JSON representation
Get a unique string identifier for any input value.
- Host: GitHub
- URL: https://github.com/fabiospampinato/strid
- Owner: fabiospampinato
- License: mit
- Created: 2022-11-28T17:24:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-24T16:28:51.000Z (almost 3 years ago)
- Last Synced: 2024-11-20T17:44:32.747Z (over 1 year ago)
- Topics: identifier, string, unique
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Strid
Get a unique string identifier for any input value.
## Details
- All values that are the same according to `Object.is` will have the same string identifier.
- All values that are different according to `Object.is` will have different string identifiers.
- If your engine hasn't implemented [this](https://github.com/tc39/proposal-symbols-as-weakmap-keys) proposal then input symbols will be kept in memory indefinitely.
## Install
```sh
npm install strid
```
## Usage
```ts
import strid from 'strid';
// Let's get a unique string identifier for some values
strid ( null ); // => 'n';
strid ( undefined ); // => 'u';
strid ( true ); // => 't';
strid ( false ); // => 'f';
strid ( 0 ); // => '0';
strid ( -0 ); // => '-0';
strid ( 0n ); // => '0n';
strid ( 'foo' ); // => 'sfoo';
strid ( () => {} ); // => 'c1';
strid ( () => {} ); // => 'c2';
strid ( {} ); // => 'c3';
strid ( [] ); // => 'c4';
strid ( Symbol () ); // -> 'c5'
```
## License
MIT © Fabio Spampinato