# libj-guid

> ## Unique id generator for browser

Latest version **1.3.0** (published 2019-08-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install libj-guid
pnpm add libj-guid
yarn add libj-guid
bun add libj-guid
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2019-08-15 |
| First published | 2019-08-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 61.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | saeidfarahi |

## Links

- npm: https://www.npmjs.com/package/libj-guid
- Repository: https://github.com/saeidjoker/libj-guid
- Homepage: https://github.com/saeidjoker/libj-guid#readme
- Issues: https://github.com/saeidjoker/libj-guid/issues
- npm.io page: https://npm.io/package/libj-guid

## Recent versions

- 1.3.0 (latest) — 2019-08-15
- 1.2.2 — 2019-08-10
- 1.2.1 — 2019-08-09
- 1.2.0 — 2019-08-08
- 1.0.1 — 2019-08-08
- 1.0.0 — 2019-08-08

## README

# libj-guid
### Part of libj tools

## GUID generator for browser

## Usage (npm)
```
npm install libj-guid
```
```
import { guid } from 'libj-guid'

var guidWithoutHyphen = guid.create();
//aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee


var guidWithHyphen = guid.create(true);
//aaaaaaaabbbbccccddddeeeeeeeeeeee


var emptyGuid = guid.empty();
//00000000-0000-0000-0000-000000000000

var emptyGuidNoHyphen = guid.emptyNoHyphen();
//00000000000000000000000000000000


var id = guid.newId();
//e_aaaaaaaabbbbccccddddeeeeeeeeeeee
```

## Test
- Run this in a separate command line to start node server
```
node server.js
```
- Run one of the following to re-create bundles
```
npm run dev
npm run dev:watch
```
- Navigate to http://localhost:3000

## Build
```
npm run build
npm run build:watch
```

## Make sure to test everything in all browsers (specially IE 10/11)


## Source:
```
export default class Guid {
    /**
     * Creates a new guid
     * @param {Boolean} hyphen if true then the guid will be like aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee otherwise there will be no hyphen
     * @returns {String}
     */
    create(hyphen) {
        function s4() {
            return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
        }
        if (hyphen === undefined || hyphen === null) {
            return `${s4()}${s4()}${s4()}${s4()}${s4()}${s4()}${s4()}${s4()}`;
        }
        return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
    }
    /**
     * Returns a new random id using create(false)
     * @returns {String}
     */
    newId() {
        return `e_${this.create()}`;
    }
    /**
     * Empty value for guid : '00000000-0000-0000-0000-000000000000'
     * @returns {String}
     */
    empty() {
        return '00000000-0000-0000-0000-000000000000';
    }
    /**
     * Empty value for guid : '00000000000000000000000000000000'
     * @returns {String}
     */
    emptyNoHyphen() {
        return '00000000000000000000000000000000';
    }
}
```

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