From e1e0a00f7f9e1a50d0ab96033eea0bf8da564e20 Mon Sep 17 00:00:00 2001 From: amorites <> Date: Wed, 20 Feb 2019 14:18:26 +0800 Subject: [PATCH] add comments & tests --- types/nanoid/nanoid-tests.ts | 6 ++++++ types/nanoid/non-secure/generate.d.ts | 16 ++++++++++++++++ types/nanoid/non-secure/index.d.ts | 15 +++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/types/nanoid/nanoid-tests.ts b/types/nanoid/nanoid-tests.ts index e026ec0659..8783d1b61f 100644 --- a/types/nanoid/nanoid-tests.ts +++ b/types/nanoid/nanoid-tests.ts @@ -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); diff --git a/types/nanoid/non-secure/generate.d.ts b/types/nanoid/non-secure/generate.d.ts index 4df7dfb94e..c7fac1dfef 100644 --- a/types/nanoid/non-secure/generate.d.ts +++ b/types/nanoid/non-secure/generate.d.ts @@ -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; diff --git a/types/nanoid/non-secure/index.d.ts b/types/nanoid/non-secure/index.d.ts index b6a78f8c52..d3cd25d817 100644 --- a/types/nanoid/non-secure/index.d.ts +++ b/types/nanoid/non-secure/index.d.ts @@ -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;