UNPKG

6.01 kBMarkdownView Raw
1[![platform][img-platform]][url-nodered]
2[![Release Ver][img-release-ver]][url-my-flow]
3[![install size][img-install-size]][url-packagephobia]
4[![downloads][img-downloads-current]][url-npm-package]
5[![downloads][img-downloads-total]][url-npm-package]
6![npm version][img-npm-version]
7[![License][img-license]](License)
8[![dependencies Status][img-depends-status]][url-david-dm]
9[![Total alerts][img-lgtm-alerts]][url-lgtm]
10[![Language grade: JavaScript][img-lgtm-lang-grade]][url-lgtm] ...
11
12
13# node-red-contrib-friendly-id
14A node for [Node-RED](http://www.nodered.org/) that converts a given UUID to a URL-friendly ID(short-uuid). You can also generate secure ID using [nanoid](https://github.com/ai/nanoid) and [short-uuid](https://github.com/oculus42/short-uuid).
15
16## Installation
17Run the following command in the root directory of your Node-RED install:
18```shell
19$ npm install node-red-contrib-friendly-id
20```
21
22## Usage
23
24### from UUID / to UUID
25![encode-decode](.images/encode-decode.gif)
26
27### Generate Friendly ID
28![generate](.images/generate-id.gif)
29
30
31## v0.2.x migration [example flows]
32In version `0.1.x`, the node was depend on a `payload` property (`msg.payload`).
33In version `0.2.x`, these restrictions will be lifted, and the usability of input/output has been improved.
34prevents node wires from becoming complicated.
35
36
37**Okay, so let's walk through some use case scenarios...**
38
39> **Case 1:**
40> How do I set a generated `short-uuid` to `msg.myid` property while preserving the original `msg.payload` property?
41
42![How?](.images/timestamp-shortuuid-how.png)
43
44The expected values of each property are as follows:
45
46```js
47{
48 _msgid: "********.*****",
49 payload: 1612274237107,
50 myid: "wGAYZWkGersMXj5KzA2vDU"
51}
52```
53
54**v0.1.x:**
55
56![v0.1.x](.images/timestamp-shortuuid-v0.1.x.png)
57
58
59**v0.2.x (migration)**
60
61![v0.2.x](.images/timestamp-shortuuid-v0.2.x.png)
62
63```json
64[{"id":"a88c20f.676d3e","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":340,"wires":[]},{"id":"c04fc85.e6ef838","type":"friendly-id","z":"f6f2187d.f17ca8","name":"","mode":"GENERATE-SHORTID","charlen":21,"charset":"DEFAULT","customs":"","tostatus":false,"statusVal":"","statusType":"auto","inputFromVal":"","inputFromType":"auto","outputToVal":"myid","outputToType":"msg","x":300,"y":340,"wires":[["a88c20f.676d3e"]]},{"id":"68101c27.6c4f84","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":340,"wires":[["c04fc85.e6ef838"]]}]
65```
66
67
68> **Case 2:**
69> How do I directly overwrite the converted UUID to a property used for input?
70
71![how?](.images/changes-param-directly-how.png)
72
73
74**v0.1.x:**
75
76![v0.1.x](.images/changes-param-directly-v0.1.x.png)
77
78**v0.2.x (migration)**
79
80![v0.2.x](.images/changes-param-directly-v0.2.x.png)
81
82```json
83[{"id":"130a8293.06421d","type":"http response","z":"f6f2187d.f17ca8","name":"","statusCode":"","headers":{},"x":510,"y":380,"wires":[]},{"id":"283657c9.5e37d8","type":"friendly-id","z":"f6f2187d.f17ca8","name":"","mode":"DECODE","charlen":21,"charset":"DEFAULT","customs":"","tostatus":false,"statusVal":"","statusType":"auto","inputFromVal":"req.params.userid","inputFromType":"msg","outputToVal":"req.params.userid","outputToType":"msg","x":360,"y":380,"wires":[["19a63487.dc85bb","130a8293.06421d"]]},{"id":"92bdbc63.ac83f","type":"http in","z":"f6f2187d.f17ca8","name":"","url":"/api/v2/users/:userid","method":"get","upload":false,"swaggerDoc":"","x":150,"y":380,"wires":[["283657c9.5e37d8"]]},{"id":"19a63487.dc85bb","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req.params.userid","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":340,"wires":[]}]
84```
85
86
87## Acknowledgements
88This project uses the following open source software:
89- [short-uuid](https://www.npmjs.com/package/short-uuid) - [MIT License](https://github.com/oculus42/short-uuid/blob/develop/LICENSE)
90- [nanoid](https://www.npmjs.com/package/nanoid) - [MIT License](https://github.com/ai/nanoid/blob/main/LICENSE)
91- [nanoid-dictionary](https://www.npmjs.com/package/nanoid-dictionary) - [MIT License](https://github.com/CyberAP/nanoid-dictionary/blob/master/LICENSE)
92
93## License
94This project is released under the [MIT License](LICENSE).
95
96
97[img-platform]: https://img.shields.io/badge/platform-Node--RED-brown.svg
98[img-release-ver]: https://img.shields.io/npm/v/node-red-contrib-friendly-id?color=limegreen&label=release
99[img-install-size]: https://packagephobia.com/badge?p=node-red-contrib-friendly-id
100[img-downloads-current]: https://img.shields.io/npm/dm/node-red-contrib-friendly-id.svg
101[img-downloads-total]: https://img.shields.io/npm/dt/node-red-contrib-friendly-id.svg
102[img-npm-version]: https://img.shields.io/badge/npm-6.9.0-blue.svg
103[img-license]: https://img.shields.io/github/license/eternity1984/node-red-contrib-friendly-id
104[img-depends-status]: https://status.david-dm.org/gh/eternity1984/node-red-contrib-friendly-id.svg
105[img-lgtm-alerts]: https://img.shields.io/lgtm/alerts/g/eternity1984/node-red-contrib-friendly-id.svg?logo=lgtm&logoWidth=18
106[img-lgtm-lang-grade]: https://img.shields.io/lgtm/grade/javascript/g/eternity1984/node-red-contrib-friendly-id.svg?logo=lgtm&logoWidth=18
107
108[url-nodered]: https://nodered.org/
109[url-my-flow]: https://flows.nodered.org/node/node-red-contrib-friendly-id
110[url-packagephobia]: https://packagephobia.com/result?p=node-red-contrib-friendly-id
111[url-npm-package]: https://www.npmjs.com/package/node-red-contrib-friendly-id
112[url-david-dm]: https://david-dm.org/eternity1984/node-red-contrib-friendly-id
113[url-lgtm]: https://lgtm.com/projects/g/eternity1984/node-red-contrib-friendly-id/
\No newline at end of file