Socket
Socket
Sign inDemoInstall

@handy-common-utils/misc-utils

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.5.0

26

dist/codec.d.ts

@@ -12,3 +12,3 @@ /**

* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -21,3 +21,3 @@ * @returns BASE64 string representing the integer input, or the original input if it is null or undefined.

* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -30,3 +30,3 @@ * @returns BASE64 string without trailing '=' representing the integer input, or the original input if it is null or undefined.

* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -39,5 +39,5 @@ * @param replacements A string containing replacement characters for "/", "+", and "=".

/**
* Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailling '='.
* Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailing '='.
* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -49,2 +49,18 @@ * @param replacements A string containing replacement characters for "/" and "+".

export declare function shortBase64UrlFromUInt32<T extends number | undefined | null>(ui32: T, replacements?: string): Exclude<T, number> | string;
/**
* Generate a strong (using crypto.randomFillSync(...)) random string that is URL/path safe.
* In the generated string, approximately every 6 characters represent randomly generated 32 bits.
* For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
* @param len length of the string to be generated
* @returns the random string
*/
export declare function generateRandomString(len: number): string;
/**
* Generate a weak (using Math.random()) random string that is URL/path safe.
* In the generated string, approximately every 6 characters represent randomly generated 32 bits.
* For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
* @param len length of the string to be generated
* @returns the random string
*/
export declare function generateRandomStringQuickly(len: number): string;
//# sourceMappingURL=codec.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.shortBase64UrlFromUInt32 = exports.base64UrlFromUInt32 = exports.shortBase64FromUInt32 = exports.base64FromUInt32 = exports.urlSafe = void 0;
exports.generateRandomStringQuickly = exports.generateRandomString = exports.shortBase64UrlFromUInt32 = exports.base64UrlFromUInt32 = exports.shortBase64FromUInt32 = exports.base64FromUInt32 = exports.urlSafe = void 0;
const tslib_1 = require("tslib");
// eslint-disable-next-line unicorn/prefer-node-protocol
const crypto = tslib_1.__importStar(require("crypto"));
/**

@@ -23,3 +26,3 @@ * Make a "normal" (BASE64) string URL/path safe.

* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -40,3 +43,3 @@ * @returns BASE64 string representing the integer input, or the original input if it is null or undefined.

* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -55,3 +58,3 @@ * @returns BASE64 string without trailing '=' representing the integer input, or the original input if it is null or undefined.

* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -67,5 +70,5 @@ * @param replacements A string containing replacement characters for "/", "+", and "=".

/**
* Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailling '='.
* Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailing '='.
* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)

@@ -80,1 +83,35 @@ * @param replacements A string containing replacement characters for "/" and "+".

exports.shortBase64UrlFromUInt32 = shortBase64UrlFromUInt32;
/**
* Generate a strong (using crypto.randomFillSync(...)) random string that is URL/path safe.
* In the generated string, approximately every 6 characters represent randomly generated 32 bits.
* For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
* @param len length of the string to be generated
* @returns the random string
*/
function generateRandomString(len) {
// 32 bits => 6 characters
const numbers = new Uint32Array(Math.ceil((len + 1) / 6));
crypto.randomFillSync(numbers);
const strings = [];
for (const i of numbers) {
strings.push(shortBase64UrlFromUInt32(i));
}
return strings.join('').slice(0, len);
}
exports.generateRandomString = generateRandomString;
/**
* Generate a weak (using Math.random()) random string that is URL/path safe.
* In the generated string, approximately every 6 characters represent randomly generated 32 bits.
* For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
* @param len length of the string to be generated
* @returns the random string
*/
function generateRandomStringQuickly(len) {
// 32 bits => 6 characters
const strings = [];
for (let i = 0; i < Math.ceil((len + 1) / 6); i++) {
strings.push(shortBase64UrlFromUInt32((Math.random() * 4294967295) >>> 0));
}
return strings.join('').slice(0, len);
}
exports.generateRandomStringQuickly = generateRandomStringQuickly;

2

package.json
{
"name": "@handy-common-utils/misc-utils",
"version": "1.4.0",
"version": "1.5.0",
"description": "Miscellaneous utilities",

@@ -5,0 +5,0 @@ "scripts": {

@@ -618,3 +618,3 @@ # @handy-common-utils/misc-utils

| :------ | :------ | :------ |
| `ui32` | `T` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |
| `ui32` | `T` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |

@@ -645,3 +645,3 @@ ###### Returns

| :------ | :------ | :------ | :------ |
| `ui32` | `T` | `undefined` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |
| `ui32` | `T` | `undefined` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |
| `replacements` | `string` | `'_-='` | A string containing replacement characters for "/", "+", and "=". If omitted, default value of '_-=' would be used. |

@@ -657,2 +657,46 @@

##### generateRandomString
▸ **generateRandomString**(`len`): `string`
Generate a strong (using crypto.randomFillSync(...)) random string that is URL/path safe.
In the generated string, approximately every 6 characters represent randomly generated 32 bits.
For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
###### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `len` | `number` | length of the string to be generated |
###### Returns
`string`
the random string
___
##### generateRandomStringQuickly
▸ **generateRandomStringQuickly**(`len`): `string`
Generate a weak (using Math.random()) random string that is URL/path safe.
In the generated string, approximately every 6 characters represent randomly generated 32 bits.
For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
###### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `len` | `number` | length of the string to be generated |
###### Returns
`string`
the random string
___
##### shortBase64FromUInt32

@@ -674,3 +718,3 @@

| :------ | :------ | :------ |
| `ui32` | `T` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |
| `ui32` | `T` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |

@@ -689,3 +733,3 @@ ###### Returns

Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailling '='.
Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailing '='.

@@ -702,3 +746,3 @@ ###### Type parameters

| :------ | :------ | :------ | :------ |
| `ui32` | `T` | `undefined` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when valueis anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |
| `ui32` | `T` | `undefined` | A 32-bit integer number which could also be null or undefined. It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer. If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32) |
| `replacements` | `string` | `'_-'` | A string containing replacement characters for "/" and "+". If omitted, default value of '_-' would be used. |

@@ -856,2 +900,14 @@

##### generateRandomString
Re-exports [generateRandomString](#generaterandomstring)
___
##### generateRandomStringQuickly
Re-exports [generateRandomStringQuickly](#generaterandomstringquickly)
___
##### mask

@@ -858,0 +914,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc