Area restrita - Questionario
This commit is contained in:
+22
-7
@@ -1,3 +1,15 @@
|
||||
/**
|
||||
* A tiny, secure, URL-friendly, unique string ID generator for JavaScript
|
||||
* with hardware random generator.
|
||||
*
|
||||
* ```js
|
||||
* import { nanoid } from 'nanoid'
|
||||
* model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
|
||||
* ```
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate secure URL-friendly unique ID.
|
||||
*
|
||||
@@ -10,9 +22,10 @@
|
||||
* ```
|
||||
*
|
||||
* @param size Size of the ID. The default size is 21.
|
||||
* @typeparam Type The ID type to replace `string` with some opaque type.
|
||||
* @returns A random string.
|
||||
*/
|
||||
export function nanoid(size?: number): string
|
||||
export function nanoid<Type extends string>(size?: number): Type
|
||||
|
||||
/**
|
||||
* Generate secure unique ID with custom alphabet.
|
||||
@@ -22,18 +35,19 @@ export function nanoid(size?: number): string
|
||||
*
|
||||
* @param alphabet Alphabet used to generate the ID.
|
||||
* @param defaultSize Size of the ID. The default size is 21.
|
||||
* @typeparam Type The ID type to replace `string` with some opaque type.
|
||||
* @returns A random string generator.
|
||||
*
|
||||
* ```js
|
||||
* const { customAlphabet } = require('nanoid')
|
||||
* import { customAlphabet } from 'nanoid'
|
||||
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||
* nanoid() //=> "8ё56а"
|
||||
* ```
|
||||
*/
|
||||
export function customAlphabet(
|
||||
export function customAlphabet<Type extends string>(
|
||||
alphabet: string,
|
||||
defaultSize?: number
|
||||
): (size?: number) => string
|
||||
): (size?: number) => Type
|
||||
|
||||
/**
|
||||
* Generate unique ID with custom random generator and alphabet.
|
||||
@@ -42,7 +56,7 @@ export function customAlphabet(
|
||||
* will not be secure.
|
||||
*
|
||||
* ```js
|
||||
* import { customRandom } from 'nanoid/format'
|
||||
* import { customRandom } from 'nanoid'
|
||||
*
|
||||
* const nanoid = customRandom('abcdef', 5, size => {
|
||||
* const random = []
|
||||
@@ -58,13 +72,14 @@ export function customAlphabet(
|
||||
* @param alphabet Alphabet used to generate a random string.
|
||||
* @param size Size of the random string.
|
||||
* @param random A random bytes generator.
|
||||
* @typeparam Type The ID type to replace `string` with some opaque type.
|
||||
* @returns A random string generator.
|
||||
*/
|
||||
export function customRandom(
|
||||
export function customRandom<Type extends string>(
|
||||
alphabet: string,
|
||||
size: number,
|
||||
random: (bytes: number) => Uint8Array
|
||||
): () => string
|
||||
): (size?: number) => Type
|
||||
|
||||
/**
|
||||
* URL safe symbols.
|
||||
|
||||
Reference in New Issue
Block a user