Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JonL1 authored Oct 28, 2020
1 parent 945e8f1 commit d4404d6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
62 changes: 62 additions & 0 deletions nanoid.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
type: 'nanoid',
module : 'nanoid',
action : 'nanoid',
groupTitle : 'Nanoid',
groupIcon : 'fal fa-lg fal fa-barcode comp-data',
title : 'Nano ID',
icon : 'fal fa-lg fa-barcode comp-data',
dataPickObject: true,
properties : [
{
group: 'Nano ID options',
variables: [
{ name: 'name', optionName: 'name', title: 'Name', type: 'text', required: true, defaultValue: 'NanoID', help: 'This will be the name for the output key and the tag used in the expression builder'},
{ name: 'api', optionName: 'api', title: 'Method',
type: 'droplist',
values: [
{title: 'Secure', value: 'secure', show:[], hide:['alphabet'] },
{title: 'Non-Secure', value: 'nonsecure', show:[], hide:['alphabet'] },
{title: 'Custom Alphabet Secure', value: 'custom_secure', show:['alphabet'], hide:[]},
{title: 'Custom Alphabet Non-Secure', value: 'custom_nonsecure', show:['alphabet'], hide:[]}
], defaultValue: '',
help: 'Choose the method to generate Nano ID. Non-Secure ones prioritize performance over security and low collision probability'
,}
{ name: 'size', optionName:'size', title: 'ID Size', type: 'number', required: true, defaultValue :'21', help: 'The size of the NanoID generated. The smaller it is the increased probability of collision. Default: 21'},
{ name: 'alphabet', optionName:'alphabet', title: 'Alphabet', type: 'text', required: false, defaultValue :'', help: 'Add the string of characters you want to use as your custom alphabet. The smaller it is the increased probability of collision.'},
{ name: 'nanoidOutput', optionName: 'output', title: 'Output', type: 'boolean', defaultValue: false }
]
}
]
},
{
type: 'ananoid',
module : 'nanoid',
action : 'ananoid',
groupTitle : 'Nanoid',
groupIcon : 'fal fa-lg fal fa-barcode comp-data',
title : 'Nano ID Asynchronous',
icon : 'fal fa-lg fa-barcode-scan comp-data',
dataPickObject: true,
properties : [
{
group: 'Nano ID Async options',
variables: [
{ name: 'name', optionName: 'name', title: 'Name', type: 'text', required: true, defaultValue: 'NanoID', help: 'This will be the name for the output key and the tag used in the expression builder'},
{ name: 'api', optionName: 'api', title: 'Method',
type: 'droplist',
values: [
{title: 'Secure', value: 'secure', show:[], hide:['alphabet'] },
{title: 'Custom Alphabet Secure', value: 'custom_secure', show:['alphabet'], hide:[]},
], defaultValue: '',
help: 'Choose the method to generate Nano ID.'
,}
{ name: 'size', optionName:'size', title: 'ID Size', type: 'number', required: true, defaultValue :'21', help: 'The size of the NanoID generated. The smaller it is the increased probability of collision. Default: 21'},
{ name: 'alphabet', optionName:'alphabet', title: 'Alphabet', type: 'text', required: false, defaultValue :'', help: 'Add the string of characters you want to use as your custom alphabet. The smaller it is the increased probability of collision.'},
{ name: 'nanoidOutput', optionName: 'output', title: 'Output', type: 'boolean', defaultValue: false }
]
}
]
}
]
28 changes: 28 additions & 0 deletions nanoid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { nanoid: s, customAlphabet: custom_secure } = require('nanoid')
const { nanoid: ns, customAlphabet: custom_nonsecure } = require('nanoid/non-secure');
const { nanoid: as, customAlphabet: acustom_secure } = require('nanoid/async')

exports.nanoid = function (options) {
switch (options.api) {
case 'secure':
return s(Number(options.size) || 21);
case 'nonsecure':
return ns(Number(options.size) || 21);
case 'custom_secure':
cs = custom_secure(this.parseRequired(options.alphabet ? String(options.alphabet) : null, 'string', 'parameter alphabet is required.'), Number(options.size) || 21)
return cs();
case 'custom_nonsecure':
cns = custom_nonsecure(this.parseRequired(options.alphabet ? String(options.alphabet) : null, 'string', 'parameter alphabet is required.'), Number(options.size) || 21)
return cns();
}
};

exports.ananoid = async function (options) {
switch (options.api) {
case 'secure':
return await as(Number(options.size) || 21);
case 'custom_secure':
acs = acustom_secure(this.parseRequired(options.alphabet ? String(options.alphabet) : null, 'string', 'parameter alphabet is required.'), Number(options.size) || 21)
return await acs();
}
};

0 comments on commit d4404d6

Please sign in to comment.