@nr1e/commons 0.0.3-alpha.0 → 0.0.3-alpha.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.
- package/bitsnbytes/b64.d.ts +39 -0
- package/bitsnbytes/b64.js +137 -0
- package/bitsnbytes/b64.js.map +1 -0
- package/bitsnbytes/index.d.ts +1 -0
- package/bitsnbytes/index.js +18 -0
- package/bitsnbytes/index.js.map +1 -0
- package/errors/errors.d.ts +18 -0
- package/errors/errors.js +26 -1
- package/errors/errors.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const BASE64_CHARS: Uint8Array;
|
|
2
|
+
export declare const URL_MODIFIED_BASE64_CHARS: Uint8Array;
|
|
3
|
+
export declare const YUI_BASE64_CHARS: Uint8Array;
|
|
4
|
+
export type Base64CharSet = 'b64' | 'url' | 'yui';
|
|
5
|
+
export interface Base64Options {
|
|
6
|
+
readonly fromIndex?: number;
|
|
7
|
+
readonly toIndex?: number;
|
|
8
|
+
readonly b64chars?: Uint8Array | Base64CharSet;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns a base64 character set and validates one if passed in.
|
|
12
|
+
*
|
|
13
|
+
* @param b64chars a base64 character set
|
|
14
|
+
*/
|
|
15
|
+
export declare function b64Charset(b64chars?: Uint8Array | Base64CharSet): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Base64 encodes a series of bytes.
|
|
18
|
+
*
|
|
19
|
+
* @param buf Bytes to encode
|
|
20
|
+
* @param opts Encoding options
|
|
21
|
+
* @return a base64 string
|
|
22
|
+
*/
|
|
23
|
+
export declare function tob64(buf: Uint8Array, opts?: Base64Options): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Base64 encodes a series of bytes to a string.
|
|
26
|
+
*
|
|
27
|
+
* @param buf Bytes to encode
|
|
28
|
+
* @param opts Encoding options
|
|
29
|
+
* @return a base64 string
|
|
30
|
+
*/
|
|
31
|
+
export declare function tob64s(buf: Uint8Array, opts?: Base64Options): string;
|
|
32
|
+
/**
|
|
33
|
+
* Base64 encodes a string to a string.
|
|
34
|
+
*
|
|
35
|
+
* @param str String to encode
|
|
36
|
+
* @param opts Encoding options
|
|
37
|
+
* @return a base64 string
|
|
38
|
+
*/
|
|
39
|
+
export declare function stob64s(str: string, opts?: Base64Options): string;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stob64s = exports.tob64s = exports.tob64 = exports.b64Charset = exports.YUI_BASE64_CHARS = exports.URL_MODIFIED_BASE64_CHARS = exports.BASE64_CHARS = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
8
|
+
const decoder = new TextDecoder();
|
|
9
|
+
exports.BASE64_CHARS = new Uint8Array([
|
|
10
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
11
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
12
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
13
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
14
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, 0x3d,
|
|
15
|
+
]);
|
|
16
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
17
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
18
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
19
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
20
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '='
|
|
21
|
+
exports.URL_MODIFIED_BASE64_CHARS = new Uint8Array([
|
|
22
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
23
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
24
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
25
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
26
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2d, 0x5f,
|
|
27
|
+
]);
|
|
28
|
+
// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
29
|
+
// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
30
|
+
// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
31
|
+
// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
32
|
+
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
|
|
33
|
+
exports.YUI_BASE64_CHARS = new Uint8Array([
|
|
34
|
+
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
|
|
35
|
+
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,
|
|
36
|
+
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
|
|
37
|
+
0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
|
|
38
|
+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2e, 0x5f, 0x2d,
|
|
39
|
+
]);
|
|
40
|
+
/**
|
|
41
|
+
* Returns a base64 character set and validates one if passed in.
|
|
42
|
+
*
|
|
43
|
+
* @param b64chars a base64 character set
|
|
44
|
+
*/
|
|
45
|
+
function b64Charset(b64chars) {
|
|
46
|
+
if (b64chars === undefined || b64chars === null) {
|
|
47
|
+
return exports.BASE64_CHARS;
|
|
48
|
+
}
|
|
49
|
+
if (b64chars instanceof Uint8Array) {
|
|
50
|
+
if (b64chars.length !== 65 && b64chars.length !== 64) {
|
|
51
|
+
throw new errors_1.IllegalArgumentError('b64chars', 'Base 64 character sets must be 64 or 65 characters.');
|
|
52
|
+
}
|
|
53
|
+
return b64chars;
|
|
54
|
+
}
|
|
55
|
+
switch (b64chars) {
|
|
56
|
+
case 'b64':
|
|
57
|
+
return exports.BASE64_CHARS;
|
|
58
|
+
case 'url':
|
|
59
|
+
return exports.URL_MODIFIED_BASE64_CHARS;
|
|
60
|
+
case 'yui':
|
|
61
|
+
return exports.YUI_BASE64_CHARS;
|
|
62
|
+
default:
|
|
63
|
+
throw new errors_1.IllegalArgumentError('b64chars', `Invalid base64 character set '${b64chars}'`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.b64Charset = b64Charset;
|
|
67
|
+
/**
|
|
68
|
+
* Base64 encodes a series of bytes.
|
|
69
|
+
*
|
|
70
|
+
* @param buf Bytes to encode
|
|
71
|
+
* @param opts Encoding options
|
|
72
|
+
* @return a base64 string
|
|
73
|
+
*/
|
|
74
|
+
function tob64(buf, opts) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const b64chars = b64Charset(opts === null || opts === void 0 ? void 0 : opts.b64chars);
|
|
77
|
+
const toIndex = (_a = opts === null || opts === void 0 ? void 0 : opts.toIndex) !== null && _a !== void 0 ? _a : buf.length;
|
|
78
|
+
const fromIndex = (_b = opts === null || opts === void 0 ? void 0 : opts.fromIndex) !== null && _b !== void 0 ? _b : 0;
|
|
79
|
+
// every 3 bytes is 4 characters in padded base64 (6 bits per char)
|
|
80
|
+
const num = toIndex - fromIndex;
|
|
81
|
+
const numc = b64chars.length === 65
|
|
82
|
+
? ((num + 2 - ((num + 2) % 3)) / 3) * 4 // padded
|
|
83
|
+
: (num * 8) / 6 + ((num * 8) % 6 !== 0 ? 1 : 0); // not padded
|
|
84
|
+
const b64 = new Uint8Array(numc);
|
|
85
|
+
let n = 0;
|
|
86
|
+
for (let i = 0; i < toIndex; i += 3) {
|
|
87
|
+
const v = ((buf[i] & 0xff) << 16) |
|
|
88
|
+
(i + 1 < toIndex ? (buf[i + 1] & 0xff) << 8 : 0) |
|
|
89
|
+
(i + 2 < toIndex ? buf[i + 2] & 0xff : 0);
|
|
90
|
+
b64[n++] = b64chars[(v >>> 18) & 0x3f];
|
|
91
|
+
b64[n++] = b64chars[(v >>> 12) & 0x3f];
|
|
92
|
+
switch (toIndex - i // calculate bytes remaining to be processed
|
|
93
|
+
) {
|
|
94
|
+
case 1: // 0 bytes left to process
|
|
95
|
+
if (b64chars.length === 65) {
|
|
96
|
+
b64[n++] = b64chars[64];
|
|
97
|
+
b64[n++] = b64chars[64];
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case 2: // 1 byte left to process
|
|
101
|
+
b64[n++] = b64chars[(v >>> 6) & 0x3f];
|
|
102
|
+
if (b64chars.length === 65) {
|
|
103
|
+
b64[n++] = b64chars[64];
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
b64[n++] = b64chars[(v >>> 6) & 0x3f];
|
|
108
|
+
b64[n++] = b64chars[v & 0x3f];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return b64;
|
|
113
|
+
}
|
|
114
|
+
exports.tob64 = tob64;
|
|
115
|
+
/**
|
|
116
|
+
* Base64 encodes a series of bytes to a string.
|
|
117
|
+
*
|
|
118
|
+
* @param buf Bytes to encode
|
|
119
|
+
* @param opts Encoding options
|
|
120
|
+
* @return a base64 string
|
|
121
|
+
*/
|
|
122
|
+
function tob64s(buf, opts) {
|
|
123
|
+
return decoder.decode(tob64(buf, opts));
|
|
124
|
+
}
|
|
125
|
+
exports.tob64s = tob64s;
|
|
126
|
+
/**
|
|
127
|
+
* Base64 encodes a string to a string.
|
|
128
|
+
*
|
|
129
|
+
* @param str String to encode
|
|
130
|
+
* @param opts Encoding options
|
|
131
|
+
* @return a base64 string
|
|
132
|
+
*/
|
|
133
|
+
function stob64s(str, opts) {
|
|
134
|
+
return tob64s(encoder.encode(str), opts);
|
|
135
|
+
}
|
|
136
|
+
exports.stob64s = stob64s;
|
|
137
|
+
//# sourceMappingURL=b64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"b64.js","sourceRoot":"","sources":["b64.ts"],"names":[],"mappings":";;;AAAA,sCAA+C;AAE/C,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAErB,QAAA,YAAY,GAAe,IAAI,UAAU,CAAC;IACrD,IAAI,EAAE,IAAI,EAAE,I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@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./b64"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB"}
|
package/errors/errors.d.ts
CHANGED
|
@@ -2,9 +2,14 @@ import { HttpStatusCode } from '../http';
|
|
|
2
2
|
interface IError {
|
|
3
3
|
stack?: string;
|
|
4
4
|
name?: string;
|
|
5
|
+
argName?: string;
|
|
5
6
|
message?: string;
|
|
6
7
|
statusCode?: HttpStatusCode | number;
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* An extended version of Error that includes an HttpStatusCode.
|
|
11
|
+
* This can be useful in middleware error handlers to determine http status codes to return to the client.
|
|
12
|
+
*/
|
|
8
13
|
export interface HttpError extends Error {
|
|
9
14
|
statusCode: HttpStatusCode | number;
|
|
10
15
|
}
|
|
@@ -119,5 +124,18 @@ export declare class NotImplementedError extends Error implements HttpError {
|
|
|
119
124
|
readonly expose = true;
|
|
120
125
|
constructor(message?: string);
|
|
121
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the given parameter is a IllegalArgumentError.
|
|
129
|
+
*
|
|
130
|
+
* @param e the parameter to check
|
|
131
|
+
*/
|
|
132
|
+
export declare function isIllegalArgumentError(e?: IError | null): e is IllegalArgumentError;
|
|
133
|
+
/**
|
|
134
|
+
* Thrown when an illegal argument is passed to a function.
|
|
135
|
+
*/
|
|
136
|
+
export declare class IllegalArgumentError extends Error {
|
|
137
|
+
readonly argName: string;
|
|
138
|
+
constructor(argName: string, message?: string);
|
|
139
|
+
}
|
|
122
140
|
export declare function toError(code: number | HttpStatusCode, message?: string): Error;
|
|
123
141
|
export {};
|
package/errors/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toError = exports.NotImplementedError = exports.isNotImplementedError = exports.UnsupportedMediaTypeError = exports.isUnsupportedMediaTypeError = exports.ConflictError = exports.isConflictError = exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = exports.isHttpError = void 0;
|
|
3
|
+
exports.toError = exports.IllegalArgumentError = exports.isIllegalArgumentError = exports.NotImplementedError = exports.isNotImplementedError = exports.UnsupportedMediaTypeError = exports.isUnsupportedMediaTypeError = exports.ConflictError = exports.isConflictError = exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = exports.isHttpError = void 0;
|
|
4
4
|
const http_1 = require("../http");
|
|
5
5
|
/**
|
|
6
6
|
* Checks if the given parameter is an HttpError.
|
|
@@ -214,6 +214,31 @@ class NotImplementedError extends Error {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
exports.NotImplementedError = NotImplementedError;
|
|
217
|
+
/**
|
|
218
|
+
* Checks if the given parameter is a IllegalArgumentError.
|
|
219
|
+
*
|
|
220
|
+
* @param e the parameter to check
|
|
221
|
+
*/
|
|
222
|
+
function isIllegalArgumentError(e) {
|
|
223
|
+
return !!(e &&
|
|
224
|
+
e.stack &&
|
|
225
|
+
e.argName &&
|
|
226
|
+
e.message &&
|
|
227
|
+
e.name === 'IllegalArgumentError');
|
|
228
|
+
}
|
|
229
|
+
exports.isIllegalArgumentError = isIllegalArgumentError;
|
|
230
|
+
/**
|
|
231
|
+
* Thrown when an illegal argument is passed to a function.
|
|
232
|
+
*/
|
|
233
|
+
class IllegalArgumentError extends Error {
|
|
234
|
+
constructor(argName, message) {
|
|
235
|
+
message = message !== null && message !== void 0 ? message : `Illegal argument ${argName}`;
|
|
236
|
+
super(message);
|
|
237
|
+
this.argName = argName;
|
|
238
|
+
this.name = 'IllegalArgumentError';
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.IllegalArgumentError = IllegalArgumentError;
|
|
217
242
|
function toError(code, message) {
|
|
218
243
|
switch (code) {
|
|
219
244
|
case http_1.HttpStatusCode.NOT_FOUND:
|
package/errors/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;AAkBvC;;;;GAIG;AACH,SAAgB,WAAW,CAAC,CAAiB;IAC3C,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AACjE,CAAC;AAFD,kCAEC;AAED;;;;GAIG;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AC,SAAS;YAC3B,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QACrC,KAAK,qBAAc,CAAC,WAAW;YAC7B,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QACtC,KAAK,qBAAc,CAAC,qBAAqB;YACvC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,qBAAc,CAAC,QAAQ;YAC1B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACpC,KAAK,qBAAc,CAAC,sBAAsB;YACxC,OAAO,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAChD,KAAK,qBAAc,CAAC,eAAe;YACjC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C;YACE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,0BAsBC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lang = exports.http = exports.errors = exports.validator = void 0;
|
|
3
|
+
exports.bitsnbytes = exports.lang = exports.http = exports.errors = exports.validator = void 0;
|
|
4
4
|
exports.validator = require("./validator");
|
|
5
5
|
exports.errors = require("./errors");
|
|
6
6
|
exports.http = require("./http");
|
|
7
7
|
exports.lang = require("./lang");
|
|
8
|
+
exports.bitsnbytes = require("./bitsnbytes");
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,qCAAmC;AACnC,iCAA+B;AAC/B,iCAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,qCAAmC;AACnC,iCAA+B;AAC/B,iCAA+B;AAC/B,6CAA2C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nr1e/commons",
|
|
3
3
|
"description": "Provides common patterns for validation",
|
|
4
|
-
"version": "0.0.3-alpha.
|
|
4
|
+
"version": "0.0.3-alpha.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"author": "NR1E, Inc.",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"./http": "./http/index.js",
|
|
35
35
|
"./errors": "./errors/index.js",
|
|
36
36
|
"./validator": "./validator/index.js",
|
|
37
|
-
"./lang": "./lang/index.js"
|
|
37
|
+
"./lang": "./lang/index.js",
|
|
38
|
+
"./bitsnbytes": "./bitsnbytes/index.js"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "tsc",
|