Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jedrzejginter/uid.macro
Insert uuid v4 or random string at build-time with babel macros.
https://github.com/jedrzejginter/uid.macro
babel-macros randomstring uuid
Last synced: 9 days ago
JSON representation
Insert uuid v4 or random string at build-time with babel macros.
- Host: GitHub
- URL: https://github.com/jedrzejginter/uid.macro
- Owner: jedrzejginter
- License: mit
- Created: 2021-01-21T19:55:43.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-08T20:30:51.000Z (almost 4 years ago)
- Last Synced: 2024-12-20T22:22:17.450Z (about 1 month ago)
- Topics: babel-macros, randomstring, uuid
- Language: JavaScript
- Homepage:
- Size: 168 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# uid.macro
Insert [`uuid` v4](https://www.npmjs.com/package/uuid) or [`random string`](https://www.npmjs.com/package/randomstring) at build-time with [`babel macros`](https://github.com/kentcdodds/babel-plugin-macros).
## Installation
```
npm install --save-dev uid.macro
```You'll also need to install and configure [`babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros) if you haven't already.
## Usage
- `uuid` version 4
```js
import { uuid } from 'uid.macro';
const value = uuid();↓ ↓ ↓ ↓ ↓ ↓
const value = '44a79dfb-6805-46c7-bd79-04420e7d6bcc';
```- random string (optional length)
```js
import { str } from 'uid.macro';
const value = str();
const other = str(7);↓ ↓ ↓ ↓ ↓ ↓
const value = 'XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT';
const other = 'xqm5wXX';
```