randomcryp 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # randomcryp
2
2
 
3
- A cryptographically secure, feature rich, zero dependency, lightweight and browser friendly random number generator library. Only ~3KB in size.
3
+ A cryptographically secure, feature rich, zero dependency, lightweight and browser friendly random number generator library. Only ~4KB in size.
4
4
  Uses [Crypto.getRandomValues()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) to get its randomness.
5
5
  The spelling is random-creep in case you are wondering.
6
6
 
@@ -57,4 +57,5 @@ rangeInt(1, 10); // 7
57
57
  | **`safeInt(): number`** | Generates a random integer between `Number.MIN_SAFE_INTEGER` (inclusive) and `Number.MAX_SAFE_INTEGER` (inclusive). +0 and -0 both can be generated. 54 bits precision. Not recommended for genral usage. | `safeInt()` → `-5802548511349229` |
58
58
  | **`ifloat(): number`** | Generates a random number between `-1` (inclusive) and `1` (inclusive). Uses `safeInt()` and thus not recommended. | `ifloat()` → `-0.6076475248861822` |
59
59
 
60
- License, BSD-3-Clause
60
+ © 2025, Md. Touhidur Rahman
61
+ License: BSD-3-Clause.
package/dist/index.d.ts CHANGED
@@ -1,129 +1,32 @@
1
- declare module "lib/uSafeInt" {
2
- /**
3
- * Generates a random integer
4
- * between 0 (inclusive) and {@link Number.MAX_SAFE_INTEGER} (inclusive)
5
- * with 53 bits precission.
6
- **/
7
- export const uSafeInt: () => number;
8
- }
9
- declare module "lib/bool" {
10
- /**
11
- * Generates a boolean value randomly.
12
- * true and false are equally likely.
13
- **/
14
- export const bool: () => boolean;
15
- }
16
- declare module "lib/boolean" {
17
- export { bool as boolean } from "lib/bool";
18
- }
19
- declare module "lib/float" {
20
- /**
21
- * Generates a random number between 0 (inclusive) and 1 (exclusive).
22
- * with 53 bits precission.
23
- **/
24
- export const float: () => number;
25
- }
26
- declare module "lib/choice" {
27
- /**
28
- * Randomly choose an element from an array-like object.
29
- * @returns undefined if the array is empty.
30
- * @returns a random element from the array if at least one element is present.
31
- * @example choice([1, 2, 3]) // 2
32
- */
33
- export const choice: <E>(choices: ArrayLike<E>) => E | undefined;
34
- }
35
- declare module "lib/safeInt" {
36
- /**
37
- * Generates a random integer
38
- * between {@link Number.MIN_SAFE_INTEGER} (inclusive) and {@link Number.MAX_SAFE_INTEGER} (inclusive).
39
- * +0 and -0 can both appear, and technically 54 bit in precision but not recommended for general usage.
40
- *
41
- * Use {@link uSafeInt} for instead.
42
- **/
43
- export const safeInt: () => number;
44
- }
45
- declare module "lib/ifloat" {
46
- /**
47
- * Generates a random number between -1 (inclusive) and 1 (inclusive).
48
- * Uses {@link safeInt} and thus not recommended for general usage also.
49
- *
50
- * Should be somewhat better for calculating PI.
51
- **/
52
- export const ifloat: () => number;
53
- }
54
- declare module "lib/percentage" {
55
- /**
56
- * Generates true with the probability of the percentage value given.
57
- * @example percentage(20) // should return true 20% of the time and false 80% of the time.
58
- **/
59
- export const percentage: (input: number) => boolean;
60
- }
61
- declare module "lib/pick" {
62
- export { choice as pick } from "lib/choice";
63
- }
64
- declare module "lib/rangeInt" {
65
- /**
66
- * Generates a random number integer
67
- * between given `min` (inclusive) and `max` (inclusive).
68
- * Throws if `min` > `max`.
69
- *
70
- * @example rangeInt(1, 100) // 35
71
- */
72
- export const rangeInt: (min: number, max: number) => number;
73
- }
74
- declare module "lib/randInt" {
75
- export { rangeInt as randInt } from "lib/rangeInt";
76
- }
77
- declare module "lib/random" {
78
- export { float as random } from "lib/float";
79
- }
80
- declare module "lib/range" {
81
- /**
82
- * Generates a random number (not integer)
83
- * between given `min` (inclusive) and `max` (exclusive).
84
- * Throws if `min` > `max`.
85
- *
86
- * @example range(1, 10) // 2.4802525465053487
87
- */
88
- export const range: (min: number, max: number) => number;
89
- }
90
- declare module "lib/shuffle" {
91
- /**
92
- * Randomly shuffles the elements of an array ***in place***. The original array is modified.
93
- */
94
- export const shuffle: <E>(array: Array<E>) => Array<E>;
95
- }
96
- declare module "index" {
97
- import { bool } from "lib/bool";
98
- import { boolean } from "lib/boolean";
99
- import { choice } from "lib/choice";
100
- import { float } from "lib/float";
101
- import { ifloat } from "lib/ifloat";
102
- import { percentage } from "lib/percentage";
103
- import { pick } from "lib/pick";
104
- import { randInt } from "lib/randInt";
105
- import { random } from "lib/random";
106
- import { range } from "lib/range";
107
- import { rangeInt } from "lib/rangeInt";
108
- import { safeInt } from "lib/safeInt";
109
- import { shuffle } from "lib/shuffle";
110
- import { uSafeInt } from "lib/uSafeInt";
111
- export { bool, boolean, choice, float, ifloat, percentage, pick, randInt, random, range, rangeInt, safeInt, shuffle, uSafeInt, };
112
- const _default: {
113
- bool: () => boolean;
114
- boolean: () => boolean;
115
- choice: <E>(choices: ArrayLike<E>) => E | undefined;
116
- float: () => number;
117
- ifloat: () => number;
118
- percentage: (input: number) => boolean;
119
- pick: <E>(choices: ArrayLike<E>) => E | undefined;
120
- randInt: (min: number, max: number) => number;
121
- random: () => number;
122
- range: (min: number, max: number) => number;
123
- rangeInt: (min: number, max: number) => number;
124
- safeInt: () => number;
125
- shuffle: <E>(array: Array<E>) => Array<E>;
126
- uSafeInt: () => number;
127
- };
128
- export default _default;
129
- }
1
+ import { bool } from "./lib/bool";
2
+ import { boolean } from "./lib/boolean";
3
+ import { choice } from "./lib/choice";
4
+ import { float } from "./lib/float";
5
+ import { ifloat } from "./lib/ifloat";
6
+ import { percentage } from "./lib/percentage";
7
+ import { pick } from "./lib/pick";
8
+ import { randInt } from "./lib/randInt";
9
+ import { random } from "./lib/random";
10
+ import { range } from "./lib/range";
11
+ import { rangeInt } from "./lib/rangeInt";
12
+ import { safeInt } from "./lib/safeInt";
13
+ import { shuffle } from "./lib/shuffle";
14
+ import { uSafeInt } from "./lib/uSafeInt";
15
+ export { bool, boolean, choice, float, ifloat, percentage, pick, randInt, random, range, rangeInt, safeInt, shuffle, uSafeInt, };
16
+ declare const _default: {
17
+ bool: () => boolean;
18
+ boolean: () => boolean;
19
+ choice: <E>(choices: ArrayLike<E>) => E | undefined;
20
+ float: () => number;
21
+ ifloat: () => number;
22
+ percentage: (input: number) => boolean;
23
+ pick: <E>(choices: ArrayLike<E>) => E | undefined;
24
+ randInt: (min: number, max: number) => number;
25
+ random: () => number;
26
+ range: (min: number, max: number) => number;
27
+ rangeInt: (min: number, max: number) => number;
28
+ safeInt: () => number;
29
+ shuffle: <E>(array: Array<E>) => Array<E>;
30
+ uSafeInt: () => number;
31
+ };
32
+ export default _default;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generates a boolean value randomly.
3
+ * true and false are equally likely.
4
+ **/
5
+ export declare const bool: () => boolean;
@@ -0,0 +1 @@
1
+ export { bool as boolean } from "./bool";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Randomly choose an element from an array-like object.
3
+ * @returns undefined if the array is empty.
4
+ * @returns a random element from the array if at least one element is present.
5
+ * @example choice([1, 2, 3]) // 2
6
+ */
7
+ export declare const choice: <E>(choices: ArrayLike<E>) => E | undefined;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generates a random number between 0 (inclusive) and 1 (exclusive).
3
+ * with 53 bits precission.
4
+ **/
5
+ export declare const float: () => number;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generates a random number between -1 (inclusive) and 1 (inclusive).
3
+ * Uses {@link safeInt} and thus not recommended for general usage also.
4
+ *
5
+ * Should be somewhat better for calculating PI.
6
+ **/
7
+ export declare const ifloat: () => number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generates true with the probability of the percentage value given.
3
+ * @example percentage(20) // should return true 20% of the time and false 80% of the time.
4
+ **/
5
+ export declare const percentage: (input: number) => boolean;
@@ -0,0 +1 @@
1
+ export { choice as pick } from "./choice";
@@ -0,0 +1 @@
1
+ export { rangeInt as randInt } from "./rangeInt";
@@ -0,0 +1 @@
1
+ export { float as random } from "./float";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates a random number (not integer)
3
+ * between given `min` (inclusive) and `max` (exclusive).
4
+ * Throws if `min` > `max`.
5
+ *
6
+ * @example range(1, 10) // 2.4802525465053487
7
+ */
8
+ export declare const range: (min: number, max: number) => number;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates a random number integer
3
+ * between given `min` (inclusive) and `max` (inclusive).
4
+ * Throws if `min` > `max`.
5
+ *
6
+ * @example rangeInt(1, 100) // 35
7
+ */
8
+ export declare const rangeInt: (min: number, max: number) => number;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates a random integer
3
+ * between {@link Number.MIN_SAFE_INTEGER} (inclusive) and {@link Number.MAX_SAFE_INTEGER} (inclusive).
4
+ * +0 and -0 can both appear, and technically 54 bit in precision but not recommended for general usage.
5
+ *
6
+ * Use {@link uSafeInt} for instead.
7
+ **/
8
+ export declare const safeInt: () => number;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Randomly shuffles the elements of an array ***in place***. The original array is modified.
3
+ */
4
+ export declare const shuffle: <E>(array: Array<E>) => Array<E>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates a random integer
3
+ * between 0 (inclusive) and {@link Number.MAX_SAFE_INTEGER} (inclusive)
4
+ * with 53 bits precission.
5
+ **/
6
+ export declare const uSafeInt: () => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "randomcryp",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "A cryptographically secure, feature rich, zero dependency and browser friendly random number generator library.",
6
6
  "author": {
@@ -12,6 +12,7 @@
12
12
  "bugs": "https://github.com/touhidurrr/randomcryp/issues",
13
13
  "funding": "https://buymeacoffee.com/touhidurrr",
14
14
  "main": "dist/index.js",
15
+ "module": "dist/index.js",
15
16
  "types": "dist/index.d.ts",
16
17
  "scripts": {
17
18
  "format": "prettier --write .",
@@ -21,5 +22,32 @@
21
22
  "@types/bun": "^1.2.5",
22
23
  "prettier": "^3.5.3",
23
24
  "typescript": "^5.8.2"
24
- }
25
+ },
26
+ "keywords": [
27
+ "cryptographically-secure",
28
+ "random-number-generator",
29
+ "rng",
30
+ "zero-dependency",
31
+ "lightweight",
32
+ "browser-friendly",
33
+ "typescript",
34
+ "cross-platform",
35
+ "secure-random",
36
+ "web-crypto",
37
+ "crypto",
38
+ "javascript-library",
39
+ "random-utilities",
40
+ "array-shuffling",
41
+ "random-boolean",
42
+ "random-choice",
43
+ "percentage-generator",
44
+ "range-generator",
45
+ "safe-integer",
46
+ "open-source",
47
+ "deno",
48
+ "bun",
49
+ "nodejs",
50
+ "crypto-getrandomvalues",
51
+ "browser"
52
+ ]
25
53
  }