Skip to content

Commit

Permalink
add comments & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amorites committed Feb 20, 2019
1 parent c3b49e7 commit e1e0a00
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions types/nanoid/nanoid-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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 changes: 16 additions & 0 deletions types/nanoid/non-secure/generate.d.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions types/nanoid/non-secure/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e1e0a00

Please sign in to comment.