# @cstan/local-uid

> A CommonJS module that generates and tests for a unique identifier.

Latest version **1.0.0** (published 2023-05-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install @cstan/local-uid
pnpm add @cstan/local-uid
yarn add @cstan/local-uid
bun add @cstan/local-uid
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-05-13 |
| First published | 2023-05-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | C. H. Stanton |
| Maintainers | cstanton48 |
| Keywords | uid, uuid, local, proprietary |

## Links

- npm: https://www.npmjs.com/package/@cstan/local-uid
- npm.io page: https://npm.io/package/@cstan/local-uid

## Dependencies (1)

- [@cstan/only-digits](https://npm.io/package/@cstan/only-digits.md) ^1.0.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-05-13

## README

## local-uid

A CommonJS module that generates and tests for a unique identifier.

#### The generator

This unique identifier can be used for database or other data identifiers. It conforms to our agency needs and legacy uid. The format is 12 hexadecimal characters, a hyphen, eight hexadecimal characters, a hyphen, 4 hexadecimal characters, a hyphen and four hexadecimal characters.

The first set of hexadecimal characters are derived from the current time and changes from millisecond to millisecond. The second set of characters are derived from an internal const string or from a string passed in as an argument. The striing passed in could be the hostname, company name or the name of the CEO's daughter (just kidding) but it can be any identifier that makes your generation of the UID uniquely yours. The last two sets of characters are randomly generated numbers converted to hexadecimal.

#### The validator

The validator merely ensures that the string submitted to it has the format generated above, that is 12 hex characters, a hyphen, 8 hex characters, a hyphen, 4 hex characters, a hyphen and 4 more hex characters.

### Installation

```
npm install @cstan/local-uid
```

### Use createLuid

```
const { createLuid } = require("@cstan/local-uid");

const newLuid = createLuid("Acme Corporation");
console.log(`New LUID: ${newLuid});
// New LUID: df8b686e18d4-13d503f2-1178-b8bf
```

### Use validateLuid

```
const { validateLuid } = require("@cstan/local-uid");

fakeLuid = "df8b686e18d4-1178-b8bf-13d503f2";

if( validateLuid(fakeLuid)){
  console.log(`It is a good LUID.`);
} else {
  console.log(`It is an invalid LUID.`);
}
// It is an invalid LUID.

Note this would be an appropriate check before updating a data row or record.
```

---
_Source: https://npm.io/package/@cstan/local-uid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
