Parcourir la source

docs: better warning for randomId

Sv443 il y a 1 an
Parent
commit
275020cad7
2 fichiers modifiés avec 5 ajouts et 1 suppressions
  1. 4 1
      README.md
  2. 1 0
      lib/math.ts

+ 4 - 1
README.md

@@ -824,6 +824,9 @@ randomId(length?: number, radix?: number): string
 ```
 ```
   
   
 Generates a cryptographically strong random ID of a given length and [radix (base).](https://en.wikipedia.org/wiki/Radix)  
 Generates a cryptographically strong random ID of a given length and [radix (base).](https://en.wikipedia.org/wiki/Radix)  
+Uses the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) for generating the random numbers.  
+⚠️ This is not intended for generating encryption keys, only for generating IDs with a decent amount of entropy!  
+  
 The default length is 16 and the default radix is 16 (hexadecimal).  
 The default length is 16 and the default radix is 16 (hexadecimal).  
 You may change the radix to get digits from different numerical systems.  
 You may change the radix to get digits from different numerical systems.  
 Use 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal and 36 for alphanumeric.  
 Use 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal and 36 for alphanumeric.  
@@ -1273,7 +1276,7 @@ randomizeArray(array: Array): Array
 ```
 ```
   
   
 Returns a copy of an array with its items in a random order.  
 Returns a copy of an array with its items in a random order.  
-If the array is empty, the originally passed empty array will be returned without copying.  
+If the array is empty, a new, empty array will be returned.  
   
   
 <details><summary><b>Example - click to view</b></summary>
 <details><summary><b>Example - click to view</b></summary>
 
 

+ 1 - 0
lib/math.ts

@@ -48,6 +48,7 @@ export function randRange(...args: number[]): number {
 /**
 /**
  * Generates a random ID with the specified length and radix (16 characters and hexadecimal by default)  
  * Generates a random ID with the specified length and radix (16 characters and hexadecimal by default)  
  * Uses [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) for better cryptographic randomness  
  * Uses [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) for better cryptographic randomness  
+ * ⚠️ Not suitable for generating encryption keys! Use [`crypto.subtle.generateKey()`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey) for that.
  * @param length The length of the ID to generate (defaults to 16)
  * @param length The length of the ID to generate (defaults to 16)
  * @param radix The [radix](https://en.wikipedia.org/wiki/Radix) of each digit (defaults to 16 which is hexadecimal. Use 2 for binary, 10 for decimal, 36 for alphanumeric, etc.)
  * @param radix The [radix](https://en.wikipedia.org/wiki/Radix) of each digit (defaults to 16 which is hexadecimal. Use 2 for binary, 10 for decimal, 36 for alphanumeric, etc.)
  */
  */