@kottetall/random 0.0.1

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.
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.alphabetUppercase = exports.alphabetLowercase = void 0;
4
+ exports.alphabetLowercase = [
5
+ "a",
6
+ "b",
7
+ "c",
8
+ "d",
9
+ "e",
10
+ "f",
11
+ "g",
12
+ "h",
13
+ "i",
14
+ "j",
15
+ "k",
16
+ "l",
17
+ "m",
18
+ "n",
19
+ "o",
20
+ "p",
21
+ "q",
22
+ "r",
23
+ "s",
24
+ "t",
25
+ "u",
26
+ "v",
27
+ "w",
28
+ "x",
29
+ "y",
30
+ "z",
31
+ "å",
32
+ "ä",
33
+ "ö",
34
+ ];
35
+ exports.alphabetUppercase = exports.alphabetLowercase.map((letter) => letter.toUpperCase());
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Random = void 0;
4
+ const chars_constant_1 = require("./constants/chars.constant");
5
+ class Random {
6
+ static intBetween(min, max) {
7
+ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
8
+ const minCeiled = Math.ceil(min);
9
+ const maxFloored = Math.floor(max);
10
+ return Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled);
11
+ }
12
+ static boolean() {
13
+ return Math.random() < 0.5;
14
+ }
15
+ static fromArray(source) {
16
+ const maxIndex = source.length - 1;
17
+ const randomIndex = Random.intBetween(0, maxIndex);
18
+ return source[randomIndex];
19
+ }
20
+ static letter(casing) {
21
+ const source = [];
22
+ if (casing === "LOWERCASE" || casing === "ALL") {
23
+ source.push(...chars_constant_1.alphabetLowercase);
24
+ }
25
+ if (casing === "UPPERCASE" || casing === "ALL") {
26
+ source.push(...chars_constant_1.alphabetUppercase);
27
+ }
28
+ return Random.fromArray(source);
29
+ }
30
+ }
31
+ exports.Random = Random;
@@ -0,0 +1,3 @@
1
+ export declare const alphabetLowercase: readonly ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "å", "ä", "ö"];
2
+ export declare const alphabetUppercase: string[];
3
+ //# sourceMappingURL=chars.constant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chars.constant.d.ts","sourceRoot":"","sources":["../../../src/constants/chars.constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,4JA8BpB,CAAC;AAEX,eAAO,MAAM,iBAAiB,UAE7B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare class Random {
2
+ static intBetween(min: number, max: number): number;
3
+ static boolean(): boolean;
4
+ static fromArray<T>(source: T[]): T;
5
+ static letter(casing: "ALL" | "UPPERCASE" | "LOWERCASE"): string;
6
+ }
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,qBAAa,MAAM;IACjB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAO1C,MAAM,CAAC,OAAO;IAId,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC;IAMnC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,WAAW,GAAG,WAAW;CAWxD"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@kottetall/random",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "clean": "del-cli ./lib",
10
+ "build": "npm run clean && tsc -p ./tsconfig.json",
11
+ "prepack": "npm run build"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/kottetall/random.git"
16
+ },
17
+ "keywords": [],
18
+ "author": "",
19
+ "license": "ISC",
20
+ "type": "commonjs",
21
+ "bugs": {
22
+ "url": "https://github.com/kottetall/random/issues"
23
+ },
24
+ "homepage": "https://github.com/kottetall/random#readme",
25
+ "files": [
26
+ "lib/**/*"
27
+ ],
28
+ "devDependencies": {
29
+ "del-cli": "^7.0.0",
30
+ "typescript": "^5.9.3"
31
+ }
32
+ }