@kottetall/random 0.0.5 → 0.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.
@@ -1,13 +1,20 @@
1
+ import { HttpCodes } from "../types/random.type";
1
2
  export declare const casing: {
2
3
  readonly LOWER: "lower";
3
4
  readonly UPPER: "upper";
4
5
  };
5
6
  export declare const booleanString: {
6
- readonly TRUE_LOWERCASE: "true";
7
- readonly FALSE_LOWERCASE: "false";
8
- readonly TRUE_UPPERCASE: "TRUE";
9
- readonly FALSE_UPPERCASE: "FALSE";
7
+ readonly TRUE: "true";
8
+ readonly FALSE: "false";
10
9
  };
11
10
  export declare const falsyValues: readonly [null, undefined, false, number, 0, 0, 0n, ""];
12
11
  export declare const truthyValues: readonly [true, {}, readonly [], 42, "0", "false", Date, -42, 12n, 3.14, -3.14, number, number];
12
+ /**
13
+ * Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
14
+ */
15
+ export declare const httpCodes: readonly [100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511];
16
+ /**
17
+ * Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
18
+ */
19
+ export declare const httpCodesDictionary: Record<HttpCodes, string>;
13
20
  //# sourceMappingURL=random.constant.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.constant.d.ts","sourceRoot":"","sources":["../../src/constants/random.constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAEX,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AAEX,eAAO,MAAM,WAAW,yDAUd,CAAC;AAEX,eAAO,MAAM,YAAY,iGAef,CAAC"}
1
+ {"version":3,"file":"random.constant.d.ts","sourceRoot":"","sources":["../../src/constants/random.constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAEX,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX,eAAO,MAAM,WAAW,yDAUd,CAAC;AAEX,eAAO,MAAM,YAAY,iGAef,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS,sUAMZ,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAgEhD,CAAC"}
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.truthyValues = exports.falsyValues = exports.booleanString = exports.casing = void 0;
3
+ exports.httpCodesDictionary = exports.httpCodes = exports.truthyValues = exports.falsyValues = exports.booleanString = exports.casing = void 0;
4
4
  exports.casing = {
5
5
  LOWER: "lower",
6
6
  UPPER: "upper",
7
7
  };
8
8
  exports.booleanString = {
9
- TRUE_LOWERCASE: "true",
10
- FALSE_LOWERCASE: "false",
11
- TRUE_UPPERCASE: "TRUE",
12
- FALSE_UPPERCASE: "FALSE",
9
+ TRUE: "true",
10
+ FALSE: "false",
13
11
  };
14
12
  exports.falsyValues = [
15
13
  // Based on https://developer.mozilla.org/en-US/docs/Glossary/Falsy
@@ -38,3 +36,81 @@ exports.truthyValues = [
38
36
  Infinity,
39
37
  -Infinity,
40
38
  ];
39
+ /**
40
+ * Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
41
+ */
42
+ exports.httpCodes = [
43
+ 100, 101, 102, 103, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300,
44
+ 301, 302, 303, 304, 305, 306, 307, 308, 400, 401, 402, 403, 404, 405, 406,
45
+ 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 421, 422, 423,
46
+ 424, 425, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507,
47
+ 508, 510, 511,
48
+ ];
49
+ /**
50
+ * Based of https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status
51
+ */
52
+ exports.httpCodesDictionary = {
53
+ 100: "Continue",
54
+ 101: "Switching Protocols",
55
+ 102: "Processing Deprecated",
56
+ 103: "Early Hints",
57
+ 200: "OK",
58
+ 201: "Created",
59
+ 202: "Accepted",
60
+ 203: "Non-Authoritative Information",
61
+ 204: "No Content",
62
+ 205: "Reset Content",
63
+ 206: "Partial Content",
64
+ 207: "Multi-Status",
65
+ 208: "Already Reported",
66
+ 226: "IM Used",
67
+ 300: "Multiple Choices",
68
+ 301: "Moved Permanently",
69
+ 302: "Found",
70
+ 303: "See Other",
71
+ 304: "Not Modified",
72
+ 305: "Use Proxy",
73
+ 306: "unused",
74
+ 307: "Temporary Redirect",
75
+ 308: "Permanent Redirect",
76
+ 400: "Bad Request",
77
+ 401: "Unauthorized",
78
+ 402: "Payment Required",
79
+ 403: "Forbidden",
80
+ 404: "Not Found",
81
+ 405: "Method Not Allowed",
82
+ 406: "Not Acceptable",
83
+ 407: "Proxy Authentication Required",
84
+ 408: "Request Timeout",
85
+ 409: "Conflict",
86
+ 410: "Gone",
87
+ 411: "Length Required",
88
+ 412: "Precondition Failed",
89
+ 413: "Content Too Large",
90
+ 414: "URI Too Long",
91
+ 415: "Unsupported Media Type",
92
+ 416: "Range Not Satisfiable",
93
+ 417: "Expectation Failed",
94
+ 418: "I'm a teapot",
95
+ 421: "Misdirected Request",
96
+ 422: "Unprocessable Content",
97
+ 423: "Locked",
98
+ 424: "Failed Dependency",
99
+ 425: "Too Early Experimental",
100
+ 426: "Upgrade Required",
101
+ 428: "Precondition Required",
102
+ 429: "Too Many Requests",
103
+ 431: "Request Header Fields Too Large",
104
+ 451: "Unavailable For Legal Reasons",
105
+ 500: "Internal Server Error",
106
+ 501: "Not Implemented",
107
+ 502: "Bad Gateway",
108
+ 503: "Service Unavailable",
109
+ 504: "Gateway Timeout",
110
+ 505: "HTTP Version Not Supported",
111
+ 506: "Variant Also Negotiates",
112
+ 507: "Insufficient Storage",
113
+ 508: "Loop Detected",
114
+ 510: "Not Extended",
115
+ 511: "Network Authentication Required",
116
+ };
@@ -0,0 +1,8 @@
1
+ export declare const millis: {
2
+ readonly MILLI: 1;
3
+ readonly SECOND: 1000;
4
+ readonly MINUTE: number;
5
+ readonly HOUR: number;
6
+ readonly DAY: number;
7
+ };
8
+ //# sourceMappingURL=time.constant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.constant.d.ts","sourceRoot":"","sources":["../../src/constants/time.constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;CAMT,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.millis = void 0;
4
+ exports.millis = {
5
+ MILLI: 1,
6
+ SECOND: 1000,
7
+ MINUTE: 1000 * 60,
8
+ HOUR: 1000 * 60 * 60,
9
+ DAY: 1000 * 60 * 60 * 24,
10
+ };
package/lib/index.d.ts CHANGED
@@ -81,5 +81,27 @@ export declare class Random {
81
81
  * @returns
82
82
  */
83
83
  static fullName(nameGender?: Gender): string;
84
+ /**
85
+ * Get a http code i.e 200, 400
86
+ * @returns
87
+ */
88
+ static httpStatusCode(): 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
89
+ /**
90
+ * Get a http status i.e Created, Accepted
91
+ * @returns
92
+ */
93
+ static httpStatus(): string;
94
+ /**
95
+ * Returns a specific time as a localeTimeString
96
+ * @returns
97
+ */
98
+ static time(): string;
99
+ /**
100
+ * Returns a date (and time) within the given range
101
+ * @param min - first date in range
102
+ * @param max - last date in range
103
+ * @returns
104
+ */
105
+ static date(min: Date, max: Date): Date;
84
106
  }
85
107
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAiB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,MAAM;IACjB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAY1C,MAAM,CAAC,OAAO;IAId;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,MAAM;IAQ3C;;;OAGG;IACH,MAAM,CAAC,UAAU;IAIjB;;;OAGG;IACH,MAAM,CAAC,KAAK;IAIZ;;;OAGG;IACH,MAAM,CAAC,MAAM;IAIb;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC;IAMnC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAK/D;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM;IAYnC;;;OAGG;IACH,MAAM,CAAC,IAAI;IAIX;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,kBAAkB,EAAE,MAAM,EAC1B,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI;IAk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AAE,MAAM,EACrB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI;IAkBP;;;;;;OAMG;WACU,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAS7D;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM;IAepC;;;OAGG;IACH,MAAM,CAAC,QAAQ;IAIf;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;IAInC;;;OAGG;IACH,MAAM,CAAC,cAAc;IAIrB;;;OAGG;IACH,MAAM,CAAC,UAAU;IAKjB;;;OAGG;IACH,MAAM,CAAC,IAAI;IAKX;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;CAUjC"}
package/lib/index.js CHANGED
@@ -4,6 +4,7 @@ exports.Random = void 0;
4
4
  const chars_constant_1 = require("./constants/chars.constant");
5
5
  const random_constant_1 = require("./constants/random.constant");
6
6
  const name_constant_1 = require("./constants/name.constant");
7
+ const time_constant_1 = require("./constants/time.constant");
7
8
  class Random {
8
9
  static intBetween(min, max) {
9
10
  // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
@@ -27,9 +28,7 @@ class Random {
27
28
  static booleanString(booleanCasing) {
28
29
  if (!booleanCasing)
29
30
  booleanCasing = random_constant_1.casing.LOWER;
30
- const result = Random.boolean()
31
- ? random_constant_1.booleanString.TRUE_LOWERCASE
32
- : random_constant_1.booleanString.FALSE_UPPERCASE;
31
+ const result = Random.boolean() ? random_constant_1.booleanString.TRUE : random_constant_1.booleanString.FALSE;
33
32
  return booleanCasing === random_constant_1.casing.LOWER ? result : result.toUpperCase();
34
33
  }
35
34
  /**
@@ -164,5 +163,43 @@ class Random {
164
163
  static fullName(nameGender) {
165
164
  return `${Random.firstName(nameGender)} ${Random.lastName()}`;
166
165
  }
166
+ /**
167
+ * Get a http code i.e 200, 400
168
+ * @returns
169
+ */
170
+ static httpStatusCode() {
171
+ return Random.fromArray([...random_constant_1.httpCodes]);
172
+ }
173
+ /**
174
+ * Get a http status i.e Created, Accepted
175
+ * @returns
176
+ */
177
+ static httpStatus() {
178
+ const randomStatusCode = Random.httpStatusCode();
179
+ return random_constant_1.httpCodesDictionary[randomStatusCode];
180
+ }
181
+ /**
182
+ * Returns a specific time as a localeTimeString
183
+ * @returns
184
+ */
185
+ static time() {
186
+ const randomMillis = Random.intBetween(0, time_constant_1.millis.DAY);
187
+ return new Date(randomMillis).toLocaleTimeString();
188
+ }
189
+ /**
190
+ * Returns a date (and time) within the given range
191
+ * @param min - first date in range
192
+ * @param max - last date in range
193
+ * @returns
194
+ */
195
+ static date(min, max) {
196
+ if (max.getTime() < min.getTime()) {
197
+ const oldMin = min;
198
+ min = max;
199
+ max = oldMin;
200
+ }
201
+ const randomDate = Random.intBetween(min.getTime(), max.getTime());
202
+ return new Date(randomDate);
203
+ }
167
204
  }
168
205
  exports.Random = Random;
@@ -1,4 +1,5 @@
1
- import { booleanString, casing } from "../constants/random.constant";
1
+ import { booleanString, casing, httpCodes } from "../constants/random.constant";
2
2
  export type Casing = (typeof casing)[keyof typeof casing];
3
3
  export type BooleanString = (typeof booleanString)[keyof typeof booleanString];
4
+ export type HttpCodes = (typeof httpCodes)[number];
4
5
  //# sourceMappingURL=random.type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.type.d.ts","sourceRoot":"","sources":["../../src/types/random.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC"}
1
+ {"version":3,"file":"random.type.d.ts","sourceRoot":"","sources":["../../src/types/random.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEhF,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kottetall/random",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -22,13 +22,14 @@
22
22
  "helpers",
23
23
  "javascript",
24
24
  "node",
25
- "array",
26
- "object",
27
25
  "picker",
28
26
  "random-picker",
29
27
  "random-value",
30
28
  "test data",
31
- "mock data"
29
+ "mock data",
30
+ "mock",
31
+ "random data generation",
32
+ "random name"
32
33
  ],
33
34
  "author": "",
34
35
  "license": "ISC",