dff-util 1.0.0
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 +46 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -0
- package/dist/main/const-type.d.ts +28 -0
- package/dist/main/const-type.js +20 -0
- package/dist/main/const-value.d.ts +36 -0
- package/dist/main/const-value.js +43 -0
- package/dist/main/crypto-decrypt.d.ts +1 -0
- package/dist/main/crypto-decrypt.js +28 -0
- package/dist/main/crypto-encrypt.d.ts +1 -0
- package/dist/main/crypto-encrypt.js +35 -0
- package/dist/main/http.d.ts +24 -0
- package/dist/main/http.js +167 -0
- package/dist/main/jwt-util.d.ts +4 -0
- package/dist/main/jwt-util.js +66 -0
- package/dist/main/regexr.d.ts +22 -0
- package/dist/main/regexr.js +45 -0
- package/dist/main/util.d.ts +7 -0
- package/dist/main/util.js +76 -0
- package/package.json +30 -0
- package/tsconfig.json +110 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
## Session Info
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
export type SessionInfo = {
|
|
5
|
+
id: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
mobile?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
role: string;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
exp?: number;
|
|
13
|
+
};
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## ErrorResponse
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
new ErrorResponse(message): {
|
|
20
|
+
status: 0,
|
|
21
|
+
message: 'ERROR',
|
|
22
|
+
data: message
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### util
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
UniqueCode();
|
|
30
|
+
UniqueByType(name, type) => key give Upper case without special char by type
|
|
31
|
+
Key(name) => key give Upper case without special char
|
|
32
|
+
DaysBack(date, addDays, isDays)
|
|
33
|
+
AddDays(date, addDays, isDays)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Crypto encrypt
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
crypto.encrypt(text, key) :: string
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Crypto decrypt
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
crypto.decrypt(text, key) :: string
|
|
46
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './main/util';
|
|
2
|
+
export * from './main/crypto-decrypt';
|
|
3
|
+
export * from './main/crypto-encrypt';
|
|
4
|
+
export * from './main/jwt-util';
|
|
5
|
+
export * from './main/http';
|
|
6
|
+
export * from './main/regexr';
|
|
7
|
+
export * from './main/const-value';
|
|
8
|
+
export * from './main/const-type';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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("./main/util"), exports);
|
|
18
|
+
__exportStar(require("./main/crypto-decrypt"), exports);
|
|
19
|
+
__exportStar(require("./main/crypto-encrypt"), exports);
|
|
20
|
+
__exportStar(require("./main/jwt-util"), exports);
|
|
21
|
+
__exportStar(require("./main/http"), exports);
|
|
22
|
+
__exportStar(require("./main/regexr"), exports);
|
|
23
|
+
__exportStar(require("./main/const-value"), exports);
|
|
24
|
+
__exportStar(require("./main/const-type"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type SessionInfo = {
|
|
2
|
+
id: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
mobile?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
role: string;
|
|
7
|
+
requestId?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
exp?: number;
|
|
10
|
+
};
|
|
11
|
+
export type SessionUser = {
|
|
12
|
+
id: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
mobile?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
role: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const ErrorResponse: (message: string, error?: any) => {
|
|
19
|
+
status: number;
|
|
20
|
+
type: string;
|
|
21
|
+
message: string;
|
|
22
|
+
error: any;
|
|
23
|
+
};
|
|
24
|
+
export declare const SuccessResponse: (data: any) => {
|
|
25
|
+
status: number;
|
|
26
|
+
type: string;
|
|
27
|
+
data: any;
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuccessResponse = exports.ErrorResponse = void 0;
|
|
4
|
+
const ErrorResponse = (message, error) => {
|
|
5
|
+
return {
|
|
6
|
+
status: 0,
|
|
7
|
+
type: 'ERROR',
|
|
8
|
+
message: message,
|
|
9
|
+
error: error,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
exports.ErrorResponse = ErrorResponse;
|
|
13
|
+
const SuccessResponse = (data) => {
|
|
14
|
+
return {
|
|
15
|
+
status: 1,
|
|
16
|
+
type: 'SUCCESS',
|
|
17
|
+
data: data,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.SuccessResponse = SuccessResponse;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const ConstValue: {
|
|
2
|
+
AND: string;
|
|
3
|
+
OR: string;
|
|
4
|
+
NOT: string;
|
|
5
|
+
AT: string;
|
|
6
|
+
HASH: string;
|
|
7
|
+
DOLLAR: string;
|
|
8
|
+
PERCENT: string;
|
|
9
|
+
CARET: string;
|
|
10
|
+
AMPERSAND: string;
|
|
11
|
+
ASTERISK: string;
|
|
12
|
+
TILDE: string;
|
|
13
|
+
COLON: string;
|
|
14
|
+
SEMICOLON: string;
|
|
15
|
+
DOUBLE_QUOTE: string;
|
|
16
|
+
SINGLE_QUOTE: string;
|
|
17
|
+
COMMA: string;
|
|
18
|
+
PERIOD: string;
|
|
19
|
+
SLASH: string;
|
|
20
|
+
QUESTION_MARK: string;
|
|
21
|
+
PLUS: string;
|
|
22
|
+
UNDERSCORE: string;
|
|
23
|
+
HYPHEN: string;
|
|
24
|
+
EQUALS: string;
|
|
25
|
+
BACKSLASH: string;
|
|
26
|
+
PIPE: string;
|
|
27
|
+
SPACE: string;
|
|
28
|
+
EMPTY: string;
|
|
29
|
+
TRUE: string;
|
|
30
|
+
FALSE: string;
|
|
31
|
+
NULL: string;
|
|
32
|
+
UNDEFINED: string;
|
|
33
|
+
STR_AND: string;
|
|
34
|
+
STR_OR: string;
|
|
35
|
+
STR_NOT: string;
|
|
36
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConstValue = void 0;
|
|
4
|
+
exports.ConstValue = {
|
|
5
|
+
// Logical operators
|
|
6
|
+
AND: '&&',
|
|
7
|
+
OR: '||',
|
|
8
|
+
NOT: '!',
|
|
9
|
+
// Common special characters
|
|
10
|
+
AT: '@',
|
|
11
|
+
HASH: '#',
|
|
12
|
+
DOLLAR: '$',
|
|
13
|
+
PERCENT: '%',
|
|
14
|
+
CARET: '^',
|
|
15
|
+
AMPERSAND: '&',
|
|
16
|
+
ASTERISK: '*',
|
|
17
|
+
TILDE: '~',
|
|
18
|
+
COLON: ':',
|
|
19
|
+
SEMICOLON: ';',
|
|
20
|
+
DOUBLE_QUOTE: '"',
|
|
21
|
+
SINGLE_QUOTE: "'",
|
|
22
|
+
COMMA: ',',
|
|
23
|
+
PERIOD: '.',
|
|
24
|
+
SLASH: '/',
|
|
25
|
+
QUESTION_MARK: '?',
|
|
26
|
+
PLUS: '+',
|
|
27
|
+
UNDERSCORE: '_',
|
|
28
|
+
HYPHEN: '-',
|
|
29
|
+
EQUALS: '=',
|
|
30
|
+
BACKSLASH: '\\',
|
|
31
|
+
PIPE: '|',
|
|
32
|
+
// Space
|
|
33
|
+
SPACE: ' ',
|
|
34
|
+
EMPTY: '',
|
|
35
|
+
// Other
|
|
36
|
+
TRUE: 'true',
|
|
37
|
+
FALSE: 'false',
|
|
38
|
+
NULL: 'null',
|
|
39
|
+
UNDEFINED: 'undefined',
|
|
40
|
+
STR_AND: 'AND',
|
|
41
|
+
STR_OR: 'OR',
|
|
42
|
+
STR_NOT: 'NOT',
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Decrypt: (text: string, key: string) => Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Decrypt = void 0;
|
|
13
|
+
const hexStringToArrayBuffer = (hex) => {
|
|
14
|
+
const hexMatches = hex.match(/.{1,2}/g) || [];
|
|
15
|
+
const typedArray = new Uint8Array(hexMatches.map((byte) => parseInt(byte, 16)));
|
|
16
|
+
return typedArray.buffer;
|
|
17
|
+
};
|
|
18
|
+
const Decrypt = (text, key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const [ivHex, dataHex] = text.split(':');
|
|
20
|
+
const iv = hexStringToArrayBuffer(ivHex);
|
|
21
|
+
const data = hexStringToArrayBuffer(dataHex);
|
|
22
|
+
const alg = { name: 'AES-CBC', iv: iv };
|
|
23
|
+
const cryptoKey = yield crypto.subtle.importKey('raw', hexStringToArrayBuffer(key), alg, false, ['decrypt']);
|
|
24
|
+
const decrypted = yield crypto.subtle.decrypt(alg, cryptoKey, data);
|
|
25
|
+
const dec = new TextDecoder();
|
|
26
|
+
return dec.decode(decrypted);
|
|
27
|
+
});
|
|
28
|
+
exports.Decrypt = Decrypt;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Encrypt: (text: string, key: string) => string;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Encrypt = void 0;
|
|
27
|
+
const crypto = __importStar(require("crypto"));
|
|
28
|
+
const Encrypt = (text, key) => {
|
|
29
|
+
const iv = crypto.randomBytes(16);
|
|
30
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key, 'hex'), iv);
|
|
31
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
32
|
+
encrypted += cipher.final('hex');
|
|
33
|
+
return iv.toString('hex') + ':' + encrypted;
|
|
34
|
+
};
|
|
35
|
+
exports.Encrypt = Encrypt;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare enum RespType {
|
|
2
|
+
JSON = "json",
|
|
3
|
+
TEXT = "text",
|
|
4
|
+
BLOB = "blob",
|
|
5
|
+
FORM_DATA = "formData",
|
|
6
|
+
ARRAY_BUFFER = "arrayBuffer"
|
|
7
|
+
}
|
|
8
|
+
export declare const HttpHeaders: {
|
|
9
|
+
'Content-Type': string;
|
|
10
|
+
authorization: null;
|
|
11
|
+
'x-request-id': null;
|
|
12
|
+
};
|
|
13
|
+
export declare class Http {
|
|
14
|
+
static API_BASE_URL: string | undefined;
|
|
15
|
+
static TOKEN_URL: string;
|
|
16
|
+
private static RespData;
|
|
17
|
+
static Get(url: string, params: any, headers: any, type?: RespType): Promise<any>;
|
|
18
|
+
static Post(url: string, data: any, headers: any, type?: RespType): Promise<any>;
|
|
19
|
+
static Put(url: string, data: any, headers: any, type?: RespType): Promise<any>;
|
|
20
|
+
static Delete(url: string, params: any, headers: any, type?: RespType): Promise<any>;
|
|
21
|
+
static Token(sessionInfo: any, key: string, type?: RespType): Promise<any>;
|
|
22
|
+
static Upload(fullUrl: string, file: File, data?: Record<string, any>, headers?: any, type?: RespType): Promise<any>;
|
|
23
|
+
static Download(fullUrl: string, params: any, headers?: any): Promise<Buffer>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Http = exports.HttpHeaders = exports.RespType = void 0;
|
|
13
|
+
var RespType;
|
|
14
|
+
(function (RespType) {
|
|
15
|
+
RespType["JSON"] = "json";
|
|
16
|
+
RespType["TEXT"] = "text";
|
|
17
|
+
RespType["BLOB"] = "blob";
|
|
18
|
+
RespType["FORM_DATA"] = "formData";
|
|
19
|
+
RespType["ARRAY_BUFFER"] = "arrayBuffer";
|
|
20
|
+
})(RespType || (exports.RespType = RespType = {}));
|
|
21
|
+
exports.HttpHeaders = {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
authorization: null,
|
|
24
|
+
'x-request-id': null,
|
|
25
|
+
};
|
|
26
|
+
class Http {
|
|
27
|
+
static RespData(response_1) {
|
|
28
|
+
return __awaiter(this, arguments, void 0, function* (response, type = RespType.JSON) {
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw { status: response.status || 0, statusText: response.statusText || response };
|
|
31
|
+
}
|
|
32
|
+
switch (type) {
|
|
33
|
+
case RespType.JSON:
|
|
34
|
+
return yield (response === null || response === void 0 ? void 0 : response.json());
|
|
35
|
+
case RespType.TEXT:
|
|
36
|
+
return yield (response === null || response === void 0 ? void 0 : response.text());
|
|
37
|
+
case RespType.BLOB:
|
|
38
|
+
return yield (response === null || response === void 0 ? void 0 : response.blob());
|
|
39
|
+
case RespType.FORM_DATA:
|
|
40
|
+
return yield (response === null || response === void 0 ? void 0 : response.formData());
|
|
41
|
+
case RespType.ARRAY_BUFFER:
|
|
42
|
+
return yield (response === null || response === void 0 ? void 0 : response.arrayBuffer());
|
|
43
|
+
case RespType.BLOB:
|
|
44
|
+
return yield (response === null || response === void 0 ? void 0 : response.blob());
|
|
45
|
+
default:
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
static Get(url_1, params_1, headers_1) {
|
|
51
|
+
return __awaiter(this, arguments, void 0, function* (url, params, headers, type = RespType.JSON) {
|
|
52
|
+
url = Http.API_BASE_URL + url;
|
|
53
|
+
const fullUrl = params ? `${url}?${new URLSearchParams(params).toString()}` : url;
|
|
54
|
+
try {
|
|
55
|
+
const requestOptions = { method: 'GET', headers: headers || exports.HttpHeaders };
|
|
56
|
+
const response = yield fetch(fullUrl, requestOptions);
|
|
57
|
+
return yield Http.RespData(response, type);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error('HttpGet error: ', error);
|
|
61
|
+
throw { url: fullUrl, requestId: exports.HttpHeaders['x-request-id'], error: error };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
static Post(url_1, data_1, headers_1) {
|
|
66
|
+
return __awaiter(this, arguments, void 0, function* (url, data, headers, type = RespType.JSON) {
|
|
67
|
+
url = Http.API_BASE_URL + url;
|
|
68
|
+
try {
|
|
69
|
+
const requestOptions = { method: 'POST', body: JSON.stringify(data || {}), headers: headers || exports.HttpHeaders };
|
|
70
|
+
const response = yield fetch(url, requestOptions);
|
|
71
|
+
return yield Http.RespData(response, type);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error('HttpPost error: ', error);
|
|
75
|
+
throw { url: url, requestId: exports.HttpHeaders['x-request-id'], body: data, error: error };
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
static Put(url_1, data_1, headers_1) {
|
|
80
|
+
return __awaiter(this, arguments, void 0, function* (url, data, headers, type = RespType.JSON) {
|
|
81
|
+
url = Http.API_BASE_URL + url;
|
|
82
|
+
try {
|
|
83
|
+
const requestOptions = { method: 'PUT', body: JSON.stringify(data || {}), headers: headers || exports.HttpHeaders };
|
|
84
|
+
const response = yield fetch(url, requestOptions);
|
|
85
|
+
return yield Http.RespData(response, type);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error('HttpPut error: ', error);
|
|
89
|
+
throw { url: url, requestId: exports.HttpHeaders['x-request-id'], body: data, error: error };
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
static Delete(url_1, params_1, headers_1) {
|
|
94
|
+
return __awaiter(this, arguments, void 0, function* (url, params, headers, type = RespType.JSON) {
|
|
95
|
+
url = Http.API_BASE_URL + url;
|
|
96
|
+
const fullUrl = params ? `${url}?${new URLSearchParams(params).toString()}` : url;
|
|
97
|
+
try {
|
|
98
|
+
const requestOptions = { method: 'DELETE', headers: headers || exports.HttpHeaders };
|
|
99
|
+
const response = yield fetch(fullUrl, requestOptions);
|
|
100
|
+
return yield Http.RespData(response, type);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('HttpDelete error: ', error);
|
|
104
|
+
throw { url: fullUrl, requestId: exports.HttpHeaders['x-request-id'], error: error };
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
static Token(sessionInfo_1, key_1) {
|
|
109
|
+
return __awaiter(this, arguments, void 0, function* (sessionInfo, key, type = RespType.TEXT) {
|
|
110
|
+
const url = `${Http.API_BASE_URL}${Http.TOKEN_URL}`;
|
|
111
|
+
const params = { key: key, payload: JSON.stringify(sessionInfo) };
|
|
112
|
+
const fullUrl = `${url}?${new URLSearchParams(params).toString()}`;
|
|
113
|
+
try {
|
|
114
|
+
const requestOptions = { method: 'GET', headers: exports.HttpHeaders };
|
|
115
|
+
const response = yield fetch(fullUrl, requestOptions);
|
|
116
|
+
return yield Http.RespData(response, type);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.error('HttpToken error: ', error);
|
|
120
|
+
throw { url: fullUrl, requestId: exports.HttpHeaders['x-request-id'], error: error };
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
static Upload(fullUrl_1, file_1) {
|
|
125
|
+
return __awaiter(this, arguments, void 0, function* (fullUrl, file, data = {}, headers = exports.HttpHeaders, type = RespType.JSON) {
|
|
126
|
+
const formData = new FormData();
|
|
127
|
+
formData.append('file', file);
|
|
128
|
+
for (const key in data) {
|
|
129
|
+
if (data[key] !== undefined && data[key] !== null) {
|
|
130
|
+
formData.append(key, data[key]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const requestOptions = {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
body: formData,
|
|
137
|
+
headers: Object.assign(Object.assign({}, headers), { 'Content-Type': 'multipart/form-data' }),
|
|
138
|
+
};
|
|
139
|
+
const response = yield fetch(fullUrl, requestOptions);
|
|
140
|
+
return yield Http.RespData(response, type);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error('HttpUpload error: ', error);
|
|
144
|
+
throw { url: fullUrl, requestId: exports.HttpHeaders['x-request-id'], error: error };
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
static Download(fullUrl_1, params_1) {
|
|
149
|
+
return __awaiter(this, arguments, void 0, function* (fullUrl, params, headers = exports.HttpHeaders) {
|
|
150
|
+
fullUrl = params ? `${fullUrl}?${new URLSearchParams(params).toString()}` : fullUrl;
|
|
151
|
+
try {
|
|
152
|
+
const requestOptions = { method: 'GET', headers: headers || exports.HttpHeaders };
|
|
153
|
+
const response = yield fetch(fullUrl, requestOptions);
|
|
154
|
+
const blob = yield response.blob();
|
|
155
|
+
const buffer = Buffer.from(yield blob.arrayBuffer());
|
|
156
|
+
return buffer;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error('HttpDownload error: ', error);
|
|
160
|
+
throw { url: fullUrl, requestId: exports.HttpHeaders['x-request-id'], error: error };
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.Http = Http;
|
|
166
|
+
Http.API_BASE_URL = process.env.API_BASE_URL;
|
|
167
|
+
Http.TOKEN_URL = `/apisix/plugin/jwt/sign`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
export declare const JwtEncode: (data: any, token: string, expiresIn?: number) => string;
|
|
3
|
+
export declare const JwtVerify: (data: any, token: string) => string | jwt.JwtPayload;
|
|
4
|
+
export declare const JwtDecode: (token: any) => string | jwt.JwtPayload | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.JwtDecode = exports.JwtVerify = exports.JwtEncode = void 0;
|
|
27
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
28
|
+
const JwtEncode = (data, token, expiresIn = 86400) => {
|
|
29
|
+
return jwt.sign(data, token, {
|
|
30
|
+
expiresIn: expiresIn,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.JwtEncode = JwtEncode;
|
|
34
|
+
const JwtVerify = (data, token) => {
|
|
35
|
+
if (data) {
|
|
36
|
+
try {
|
|
37
|
+
data = data.replace('jwt ', '').replace('JWT ', '');
|
|
38
|
+
data = data.replace('Bearer ', '').replace('bearer ', '').replace('BEARER', '');
|
|
39
|
+
return jwt.verify(data, token);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
throw { name: 'error', message: 'Token is not valid' };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw { name: 'error', message: 'Auth token is not supplied' };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.JwtVerify = JwtVerify;
|
|
50
|
+
const JwtDecode = (token) => {
|
|
51
|
+
if (token) {
|
|
52
|
+
try {
|
|
53
|
+
token = token.replace('jwt ', '').replace('JWT ', '');
|
|
54
|
+
token = token.replace('Bearer ', '').replace('bearer ', '').replace('BEARER', '');
|
|
55
|
+
return jwt.decode(token);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.log(err);
|
|
59
|
+
throw { name: 'error', message: 'Token is not valid' };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw { name: 'error', message: 'Auth token is not supplied' };
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.JwtDecode = JwtDecode;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const RegExp: {
|
|
2
|
+
NON_ALPHA_NUMERIC: RegExp;
|
|
3
|
+
DIGITS_ONLY: RegExp;
|
|
4
|
+
ALPHABETS_ONLY: RegExp;
|
|
5
|
+
ALPHA_NUMERIC: RegExp;
|
|
6
|
+
EMAIL: RegExp;
|
|
7
|
+
URL: RegExp;
|
|
8
|
+
PHONE_US: RegExp;
|
|
9
|
+
STRONG_PASSWORD: RegExp;
|
|
10
|
+
WHITESPACE: RegExp;
|
|
11
|
+
HTML_TAG: RegExp;
|
|
12
|
+
IPV4: RegExp;
|
|
13
|
+
DATE_YYYY_MM_DD: RegExp;
|
|
14
|
+
TIME_HH_MM: RegExp;
|
|
15
|
+
ISO_DATETIME: RegExp;
|
|
16
|
+
HEX_COLOR: RegExp;
|
|
17
|
+
UUID_V4: RegExp;
|
|
18
|
+
NON_ASCII: RegExp;
|
|
19
|
+
LINE_BREAK: RegExp;
|
|
20
|
+
AMOUNT_DECIMAL: RegExp;
|
|
21
|
+
PERCENTAGE: RegExp;
|
|
22
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegExp = void 0;
|
|
4
|
+
exports.RegExp = {
|
|
5
|
+
// Matches any non-alphanumeric characters
|
|
6
|
+
NON_ALPHA_NUMERIC: /[^\w\s]/g,
|
|
7
|
+
// Matches only numeric digits (0-9)
|
|
8
|
+
DIGITS_ONLY: /^\d+$/,
|
|
9
|
+
// Matches only alphabets (case-insensitive)
|
|
10
|
+
ALPHABETS_ONLY: /^[a-zA-Z]+$/,
|
|
11
|
+
// Matches alphanumeric characters (letters and digits)
|
|
12
|
+
ALPHA_NUMERIC: /^[a-zA-Z0-9]+$/,
|
|
13
|
+
// Matches an email address
|
|
14
|
+
EMAIL: /^[\w.%+-]+@[a-zA-Z\d.-]+\.[a-zA-Z]{2,}$/,
|
|
15
|
+
// Matches a URL
|
|
16
|
+
URL: /^(https?:\/\/)?([\w.-]+)\.([a-z]{2,6}\.?)(\/[\w.-]*)*\/?$/i,
|
|
17
|
+
// Matches a US phone number (formats like (123) 456-7890, 123-456-7890, etc.)
|
|
18
|
+
PHONE_US: /^(\(\d{3}\)\s?|\d{3}[-.\s]?)?\d{3}[-.\s]?\d{4}$/,
|
|
19
|
+
// Matches a password with at least one lowercase, one uppercase, one digit, and one special character
|
|
20
|
+
STRONG_PASSWORD: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$/,
|
|
21
|
+
// Matches whitespace characters
|
|
22
|
+
WHITESPACE: /\s+/g,
|
|
23
|
+
// Matches any HTML tags
|
|
24
|
+
HTML_TAG: /<\/?[\w\s="/.':;#-\/\?]+>/gi,
|
|
25
|
+
// Matches IPv4 addresses
|
|
26
|
+
IPV4: /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/,
|
|
27
|
+
// Matches dates in YYYY-MM-DD format
|
|
28
|
+
DATE_YYYY_MM_DD: /^\d{4}-\d{2}-\d{2}$/,
|
|
29
|
+
// Matches time in HH:MM 24-hour format
|
|
30
|
+
TIME_HH_MM: /^([01]\d|2[0-3]):([0-5]\d)$/,
|
|
31
|
+
// Matches ISO 8601 datetime format (e.g., 2023-08-15T13:45:30Z, 2023-08-15T13:45:30+05:30)
|
|
32
|
+
ISO_DATETIME: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/,
|
|
33
|
+
// Matches a hexadecimal color code
|
|
34
|
+
HEX_COLOR: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
|
|
35
|
+
// Matches a UUID (version 4)
|
|
36
|
+
UUID_V4: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
37
|
+
// Matches non-ASCII characters
|
|
38
|
+
NON_ASCII: /[^\x00-\x7F]/g,
|
|
39
|
+
// Matches line breaks (newlines)
|
|
40
|
+
LINE_BREAK: /\r?\n/g,
|
|
41
|
+
// Matches amounts in decimal format (e.g., 123.45, 0.99, 1000)
|
|
42
|
+
AMOUNT_DECIMAL: /^\d+(\.\d{1,2})?$/,
|
|
43
|
+
// Matches percentages from 0-100 or in decimal format (e.g., 25%, 99.99%, 100, 0.5)
|
|
44
|
+
PERCENTAGE: /^(100(\.0{1,2})?|0|0?\.\d{1,2}|[1-9]?\d(\.\d{1,2})?)%?$/,
|
|
45
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const AppRandomString: (length: number, charset: string) => string;
|
|
2
|
+
export declare const AppUniqueCode: () => string;
|
|
3
|
+
export declare const AppUniqueCodeByType: (name: string, type?: null) => string;
|
|
4
|
+
export declare const AppKey: (name: string) => string | null;
|
|
5
|
+
export declare const AppDaysBack: (date: Date, backValue: number, isDays?: boolean) => Date;
|
|
6
|
+
export declare const AppAddDays: (date: Date, addDays: number, isDays?: boolean) => Date;
|
|
7
|
+
export declare const AppUUID4: () => string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppKey = exports.AppUniqueCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
|
|
4
|
+
const randomstring_1 = require("randomstring");
|
|
5
|
+
const regexr_1 = require("./regexr");
|
|
6
|
+
const AppRandomString = (length, charset) => {
|
|
7
|
+
return (0, randomstring_1.generate)({ length: length, charset: charset });
|
|
8
|
+
};
|
|
9
|
+
exports.AppRandomString = AppRandomString;
|
|
10
|
+
let uniqueId = 0;
|
|
11
|
+
const AppUniqueCode = () => {
|
|
12
|
+
let time = new Date().getTime();
|
|
13
|
+
if (uniqueId == time) {
|
|
14
|
+
while (new Date().getTime() < 1 + time) { }
|
|
15
|
+
time = new Date().getTime();
|
|
16
|
+
}
|
|
17
|
+
uniqueId = time;
|
|
18
|
+
return time.toString(36).toUpperCase();
|
|
19
|
+
};
|
|
20
|
+
exports.AppUniqueCode = AppUniqueCode;
|
|
21
|
+
const AppUniqueCodeByType = (name, type = null) => {
|
|
22
|
+
let str = '';
|
|
23
|
+
if (type) {
|
|
24
|
+
str = type + '_' + name;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
str = name + '_' + (0, exports.AppUniqueCode)();
|
|
28
|
+
}
|
|
29
|
+
str = str.replace(regexr_1.RegExp.NON_ALPHA_NUMERIC, '_');
|
|
30
|
+
str = str.replace(/\s/g, '_');
|
|
31
|
+
str = str.substr(0, 128);
|
|
32
|
+
return str.toUpperCase();
|
|
33
|
+
};
|
|
34
|
+
exports.AppUniqueCodeByType = AppUniqueCodeByType;
|
|
35
|
+
const AppKey = (name) => {
|
|
36
|
+
if (name == null)
|
|
37
|
+
return null;
|
|
38
|
+
let str = '';
|
|
39
|
+
str = name.trim();
|
|
40
|
+
str = str.replace(regexr_1.RegExp.NON_ALPHA_NUMERIC, '_');
|
|
41
|
+
str = str.replace(/\s/g, '_');
|
|
42
|
+
return str.toUpperCase();
|
|
43
|
+
};
|
|
44
|
+
exports.AppKey = AppKey;
|
|
45
|
+
const AppDaysBack = (date, backValue, isDays = true) => {
|
|
46
|
+
date = new Date(date);
|
|
47
|
+
if (isDays) {
|
|
48
|
+
date.setDate(date.getDate() - backValue);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
date.setMilliseconds(date.getMilliseconds() - backValue);
|
|
52
|
+
}
|
|
53
|
+
date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
54
|
+
return date;
|
|
55
|
+
};
|
|
56
|
+
exports.AppDaysBack = AppDaysBack;
|
|
57
|
+
const AppAddDays = (date, addDays, isDays = true) => {
|
|
58
|
+
date = new Date(date);
|
|
59
|
+
if (isDays) {
|
|
60
|
+
date.setDate(date.getDate() + addDays);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
date.setMilliseconds(date.getMilliseconds() + addDays);
|
|
64
|
+
}
|
|
65
|
+
date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
66
|
+
return date;
|
|
67
|
+
};
|
|
68
|
+
exports.AppAddDays = AppAddDays;
|
|
69
|
+
const AppUUID4 = () => {
|
|
70
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
71
|
+
const r = (Math.random() * 16) | 0;
|
|
72
|
+
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
73
|
+
return v.toString(16);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
exports.AppUUID4 = AppUUID4;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dff-util",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"npm",
|
|
13
|
+
"dff",
|
|
14
|
+
"util"
|
|
15
|
+
],
|
|
16
|
+
"author": "DesignForFeature",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"description": "DesignForFeature Utilies",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/jsonwebtoken": "^9.0.6",
|
|
21
|
+
"@types/node": "^20.14.10",
|
|
22
|
+
"@types/randomstring": "^1.3.0",
|
|
23
|
+
"ts-node": "^10.9.2",
|
|
24
|
+
"typescript": "^5.5.3"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"jsonwebtoken": "^9.0.2",
|
|
28
|
+
"randomstring": "1.3.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
43
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
44
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
45
|
+
|
|
46
|
+
/* JavaScript Support */
|
|
47
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
48
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
49
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
|
+
|
|
51
|
+
/* Emit */
|
|
52
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
59
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
62
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
63
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
64
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
65
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
66
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
67
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
68
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
69
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
70
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
71
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
72
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
73
|
+
|
|
74
|
+
/* Interop Constraints */
|
|
75
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
76
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
77
|
+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
78
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
79
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
80
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
81
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
82
|
+
|
|
83
|
+
/* Type Checking */
|
|
84
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
85
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
86
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
87
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
88
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
89
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
90
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
91
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
92
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
93
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
94
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
95
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
96
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
97
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
98
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
99
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
100
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
101
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
102
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
103
|
+
|
|
104
|
+
/* Completeness */
|
|
105
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
106
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
107
|
+
},
|
|
108
|
+
"include": [ "src/**/*" ],
|
|
109
|
+
"exclude": [ "node_modules", "**/*.spec.ts" ]
|
|
110
|
+
}
|