Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
e6b8613e97 | |||
ed6ccbc417 | |||
688cf007d7 | |||
c8fe270e08 | |||
77e6faef4d | |||
7d4b041c47 | |||
b9eb842fd3 | |||
677c8e3fe7 | |||
b6d5db4605 | |||
0f802e223e | |||
d5438aaaab | |||
4516a1e8ba | |||
00e4d35c55 | |||
039a4ded96 | |||
3448b8cf97 | |||
328fccc086 | |||
201e08e10e | |||
1ee8930525 | |||
6a8fca75c9 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
126
.gitlab-ci.yml
126
.gitlab-ci.yml
@ -1,126 +0,0 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm"]
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,25 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartunique",
|
||||
"shortDescription": "make things unique",
|
||||
"npmPackagename": "@pushrocks/smartunique",
|
||||
"license": "MIT"
|
||||
"description": "A library to generate unique identifiers using methods like UUID and nanoid.",
|
||||
"npmPackagename": "@push.rocks/smartunique",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unique identifier",
|
||||
"UUID",
|
||||
"nanoid",
|
||||
"shortid",
|
||||
"TypeScript",
|
||||
"security",
|
||||
"randomness",
|
||||
"uniqueness"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
1928
package-lock.json
generated
1928
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
59
package.json
59
package.json
@ -1,53 +1,58 @@
|
||||
{
|
||||
"name": "@pushrocks/smartunique",
|
||||
"version": "3.0.2",
|
||||
"name": "@push.rocks/smartunique",
|
||||
"version": "3.0.9",
|
||||
"private": false,
|
||||
"description": "make things unique",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"description": "A library to generate unique identifiers using methods like UUID and nanoid.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitlab.com/pushrocks/smartunique.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartunique.git"
|
||||
},
|
||||
"keywords": [
|
||||
"unique",
|
||||
"key",
|
||||
"uuid",
|
||||
"unique identifier",
|
||||
"UUID",
|
||||
"nanoid",
|
||||
"shortid",
|
||||
"lossless",
|
||||
"pushrocks",
|
||||
"TypeScript"
|
||||
"TypeScript",
|
||||
"security",
|
||||
"randomness",
|
||||
"uniqueness"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/node": "^13.7.7",
|
||||
"tslint": "^6.0.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/shortid": "0.0.29",
|
||||
"@types/uuid": "^7.0.0",
|
||||
"shortid": "^2.2.15",
|
||||
"uuid": "^7.0.2"
|
||||
"@types/uuid": "^9.0.2",
|
||||
"nanoid": "^4.0.2",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_web/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
],
|
||||
"type": "module",
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"homepage": "https://code.foss.global/push.rocks/smartunique"
|
||||
}
|
4719
pnpm-lock.yaml
generated
Normal file
4719
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
151
readme.md
151
readme.md
@ -1,56 +1,137 @@
|
||||
# @pushrocks/smartunique
|
||||
# @push.rocks/smartunique
|
||||
make things unique
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartunique)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartunique)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartunique)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartunique/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartunique/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartunique/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartunique)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartunique)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
To install `@push.rocks/smartunique`, use the following npm command:
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartunique --save
|
||||
```
|
||||
|
||||
This will add it to your project's dependencies. Make sure you have Node.js and npm installed in your development environment.
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
`@push.rocks/smartunique` is a TypeScript-powered module designed to help you generate unique identifiers such as short IDs, UUIDs, or custom unique strings. Its primary use is in scenarios where you need to ensure the uniqueness of elements or entities within your application, such as database keys, user identifiers, or session tokens.
|
||||
|
||||
```javascript
|
||||
// We are using TypeScript syntax here to have types in place
|
||||
import * as smartunique from 'smartunique';
|
||||
### Setting Up Your Project
|
||||
|
||||
// creates a short mathematically highly unique short string
|
||||
let myShortid = smartunique.shortid();
|
||||
Before diving into the examples, ensure your project is set up for TypeScript:
|
||||
|
||||
// creates a string that is possibly unique world wide
|
||||
let myUuid4 = smartunique.uuid4();
|
||||
1. Initialize a new npm project if you haven't already:
|
||||
|
||||
// creates a oneway repeatable unique id within a certain namespace
|
||||
let myUuid5 = smartunique.uuid('myobscureduser@somedomain.com', smartunique.uuid4());
|
||||
```sh
|
||||
npm init -y
|
||||
```
|
||||
|
||||
Learn more about UUIDs: knowledgebase.gitzone.com/uuid.html
|
||||
2. Install TypeScript:
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
```sh
|
||||
npm install typescript --save-dev
|
||||
```
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbh/privacy)
|
||||
3. Initialize TypeScript in your project:
|
||||
|
||||
[](https://push.rocks)
|
||||
```sh
|
||||
npx tsc --init
|
||||
```
|
||||
|
||||
4. Ensure your `tsconfig.json` is configured to support ES Modules, as `@push.rocks/smartunique` is an ES Module package.
|
||||
|
||||
## Contribution
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
### Generating Unique Identifiers
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
Let's explore how to generate different types of unique identifiers using `@push.rocks/smartunique`.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
#### Short Unique Identifiers
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
Short Ids are handy when you need a concise, highly unique identifier.
|
||||
|
||||
```typescript
|
||||
import { shortId } from '@push.rocks/smartunique';
|
||||
|
||||
const myShortId = shortId();
|
||||
console.log(`Generated shortId: ${myShortId}`);
|
||||
|
||||
// Specify a custom length for the shortId
|
||||
const customLengthShortId = shortId(10);
|
||||
console.log(`Generated shortId with custom length: ${customLengthShortId}`);
|
||||
```
|
||||
|
||||
#### UUID Version 4 (Random)
|
||||
|
||||
UUIDs are universally unique identifiers that are widely used for ensuring uniqueness across distributed systems.
|
||||
|
||||
```typescript
|
||||
import { uuid4 } from '@push.rocks/smartunique';
|
||||
|
||||
const myUuid4 = uuid4();
|
||||
console.log(`Generated UUID v4: ${myUuid4}`);
|
||||
```
|
||||
|
||||
#### UUID Version 5 (Name-Based)
|
||||
|
||||
UUID v5 generates a unique identifier based on a namespace identifier and a name.
|
||||
|
||||
```typescript
|
||||
import { uuid5, uuid4 } from '@push.rocks/smartunique';
|
||||
|
||||
const namespaceUuid = uuid4(); // For example purposes, a random UUID serves as the namespace
|
||||
const myUuid5 = uuid5('myUniqueName', namespaceUuid);
|
||||
console.log(`Generated UUID v5: ${myUuid5}`);
|
||||
```
|
||||
|
||||
#### Custom Unique Identifiers
|
||||
|
||||
For cases where you need a custom format for your unique identifiers, `@push.rocks/smartunique` offers `uni` and `uniSimple` functions.
|
||||
|
||||
```typescript
|
||||
import { uni, uniSimple } from '@push.rocks/smartunique';
|
||||
|
||||
const customUni = uni('prefix', 16);
|
||||
console.log(`Generated custom unique identifier: ${customUni}`);
|
||||
|
||||
const simpleUni = uniSimple('simple', 4);
|
||||
console.log(`Generated simple unique identifier: ${simpleUni}`);
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
Through these examples, you've seen how to generate various types of unique identifiers using `@push.rocks/smartunique`. Whether you need short IDs for concise references, UUIDs for global uniqueness, or custom unique identifiers for specific use cases, this package provides the tools necessary for your project's unique identifier needs.
|
||||
|
||||
Make sure to explore the package further to fully leverage its capabilities in your applications.
|
||||
|
||||
---
|
||||
|
||||
For any further assistance or contribution to the project, please refer to the repository on [GitLab](https://gitlab.com/pushrocks/smartunique) or its mirror on [GitHub](https://github.com/push.rocks/smartunique). Contributions, whether in the form of feature requests, bug reports, or pull requests, are always welcome.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartunique from '../ts/index';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartunique from '../ts/index.js';
|
||||
|
||||
tap.test('should create shortid', async () => {
|
||||
const result = smartunique.shortId();
|
||||
console.log(result);
|
||||
const result2 = smartunique.shortId(8);
|
||||
console.log(result2);
|
||||
});
|
||||
|
||||
tap.test('should create uuidv4', async () => {
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartunique',
|
||||
version: '3.0.9',
|
||||
description: 'A library to generate unique identifiers using methods like UUID and nanoid.'
|
||||
}
|
20
ts/index.ts
20
ts/index.ts
@ -1,10 +1,10 @@
|
||||
import * as plugins from './smartunique.plugins';
|
||||
import * as plugins from './smartunique.plugins.js';
|
||||
|
||||
/**
|
||||
* returns short strings that are unique to very high degree od certainty
|
||||
*/
|
||||
export const shortId = (): string => {
|
||||
return plugins.shortid.generate();
|
||||
export const shortId = (sizeArg?: number): string => {
|
||||
return plugins.nanoid.nanoid(sizeArg);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -18,10 +18,18 @@ export const uuid5 = (customStringArg: string, namespaceArg = plugins.uuid.v5.DN
|
||||
return plugins.uuid.v5(customStringArg, namespaceArg);
|
||||
};
|
||||
|
||||
export const uni = () => {
|
||||
return 'unixxxxxxxxxxx'.replace(/[xy]/g, c => {
|
||||
export const uni = (prefix: string = 'uni', lengthArg = 24) => {
|
||||
return `${prefix}_${'x'.repeat(lengthArg).replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
})}`;
|
||||
};
|
||||
|
||||
export const uniSimple = (prefix: string = 'uni', lengthArg = 8) => {
|
||||
return `${prefix}${'x'.repeat(lengthArg).replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
})}`;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import shortid from 'shortid';
|
||||
import * as nanoid from 'nanoid';
|
||||
import * as uuid from 'uuid';
|
||||
|
||||
export { shortid, uuid };
|
||||
export { nanoid, uuid };
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user