add comments & tests

This commit is contained in:
amorites
2019-02-20 14:34:15 +08:00
parent c3b49e7066
commit e1e0a00f7f
3 changed files with 37 additions and 0 deletions
+6
View File
@@ -6,6 +6,8 @@ import randomBrowser = require('nanoid/random-browser');
import url = require('nanoid/url');
import nanoidAsync = require('nanoid/async');
import nanoidAsyncBrowser = require('nanoid/async-browser');
import nanoidNonSecure = require('nanoid/non-secure');
import generateNonSecure = require('nanoid/non-secure/generate');
const _random = (size: number) => [1, 2, 3, 4];
@@ -22,5 +24,9 @@ nanoidAsync(null, (error, id) => {
});
nanoidAsyncBrowser().then((id) => console.log(id));
nanoidAsyncBrowser(10).then((id) => console.log(id));
nanoidNonSecure();
nanoidNonSecure(10);
generateNonSecure('0123456789абвгдеё', 5);
generateNonSecure('0123456789абвгдеё');
console.log(url);
+16
View File
@@ -1,3 +1,19 @@
/**
* Generate URL-friendly unique ID. This method use non-secure predictable
* random generator.
*
* By default, ID will have 21 symbols to have a collision probability similar
* to UUID v4.
*
* @param alphabet Symbols to be used in ID.
* @param [size=21] The number of symbols in ID.
*
* @return Random string.
*
* @example
* const nanoid = require('nanoid/non-secure')
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
*/
declare function generate(alphabet: string, size?: number): string;
export = generate;
+15
View File
@@ -1,3 +1,18 @@
/**
* Generate URL-friendly unique ID. This method use non-secure predictable
* random generator.
*
* By default, ID will have 21 symbols to have a collision probability similar
* to UUID v4.
*
* @param [size=21] The number of symbols in ID.
*
* @return Random string.
*
* @example
* const nanoid = require('nanoid/non-secure')
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
*/
declare function nanoid(size?: number): string;
export = nanoid;