mybase 1.1.4 → 1.1.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/package.json +1 -1
- package/ts/funcs/asJSON.d.ts +1 -0
- package/ts/funcs/asJSON.js +13 -0
- package/ts/funcs/fileCacheIsValid.d.ts +1 -0
- package/ts/funcs/hash_sha512.d.ts +1 -0
- package/ts/funcs/promiseTimeout.d.ts +1 -0
- package/ts/funcs/promiseTimeout.js +18 -0
- package/ts/funcs/randomIP.d.ts +1 -0
- package/ts/funcs/randomIP.js +10 -0
- package/ts/funcs/randomIP.test.ts +16 -0
- package/ts/funcs/randomIP.ts +7 -0
- package/ts/funcs/vaultFill.d.ts +2 -0
- package/ts/funcs/vaultRead.d.ts +2 -0
- package/ts/global.d.ts +1 -0
- package/ts/index.d.ts +7 -0
- package/ts/index.js +3 -0
- package/ts/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function asJSON(inputString: string): any | boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asJSON = void 0;
|
|
4
|
+
function asJSON(inputString) {
|
|
5
|
+
if (!inputString || typeof inputString !== 'string')
|
|
6
|
+
return false;
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(inputString);
|
|
9
|
+
}
|
|
10
|
+
catch (_) { }
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
exports.asJSON = asJSON;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fileCacheIsValid(cacheFileName: string, cache_in_minutes?: number): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hash_sha512(plainString: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function promiseTimeout(miliseconds: number, inputPromise: Promise<any>, onTimeout?: any): Promise<any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiseTimeout = void 0;
|
|
4
|
+
function promiseTimeout(miliseconds, inputPromise, onTimeout = 'TIMEDOUT') {
|
|
5
|
+
// Create a promise that rejects in <miliseconds> milliseconds
|
|
6
|
+
let timeout = new Promise((resolve, reject) => {
|
|
7
|
+
let stID = setTimeout(() => {
|
|
8
|
+
clearTimeout(stID);
|
|
9
|
+
reject(onTimeout);
|
|
10
|
+
}, miliseconds);
|
|
11
|
+
});
|
|
12
|
+
// Returns a race between our timeout and the passed in promise
|
|
13
|
+
return Promise.race([
|
|
14
|
+
inputPromise,
|
|
15
|
+
timeout
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
exports.promiseTimeout = promiseTimeout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomIP(): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomIP = void 0;
|
|
4
|
+
function randomIP() {
|
|
5
|
+
function int2ip(ipInt) {
|
|
6
|
+
return ((ipInt >>> 24) + '.' + (ipInt >> 16 & 255) + '.' + (ipInt >> 8 & 255) + '.' + (ipInt & 255));
|
|
7
|
+
}
|
|
8
|
+
return int2ip(Math.random() * Math.pow(2, 32));
|
|
9
|
+
}
|
|
10
|
+
exports.randomIP = randomIP;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { randomIP } from './randomIP';
|
|
2
|
+
|
|
3
|
+
describe('randomIP', () => {
|
|
4
|
+
it('should return a valid IP address', () => {
|
|
5
|
+
for(let i=0; i<1000; i++) {
|
|
6
|
+
const ipAddress = randomIP();
|
|
7
|
+
const ipParts = ipAddress.split('.');
|
|
8
|
+
expect(ipParts.length).toBe(4);
|
|
9
|
+
ipParts.forEach((part) => {
|
|
10
|
+
const partInt = parseInt(part);
|
|
11
|
+
expect(partInt).toBeGreaterThanOrEqual(0);
|
|
12
|
+
expect(partInt).toBeLessThanOrEqual(255);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/ts/global.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare let vault_cache_folder: string;
|
package/ts/index.d.ts
CHANGED
|
@@ -4,3 +4,10 @@ export * from "./funcs/randomString";
|
|
|
4
4
|
export * from "./funcs/utcnow";
|
|
5
5
|
export * from "./funcs/validIp";
|
|
6
6
|
export * from "./funcs/wait";
|
|
7
|
+
export * from "./funcs/fileCacheIsValid";
|
|
8
|
+
export * from "./funcs/hash_sha512";
|
|
9
|
+
export * from "./funcs/vaultRead";
|
|
10
|
+
export * from "./funcs/vaultFill";
|
|
11
|
+
export * from "./funcs/asJSON";
|
|
12
|
+
export * from "./funcs/promiseTimeout";
|
|
13
|
+
export * from "./funcs/randomIP";
|
package/ts/index.js
CHANGED
|
@@ -24,3 +24,6 @@ __exportStar(require("./funcs/fileCacheIsValid"), exports);
|
|
|
24
24
|
__exportStar(require("./funcs/hash_sha512"), exports);
|
|
25
25
|
__exportStar(require("./funcs/vaultRead"), exports);
|
|
26
26
|
__exportStar(require("./funcs/vaultFill"), exports);
|
|
27
|
+
__exportStar(require("./funcs/asJSON"), exports);
|
|
28
|
+
__exportStar(require("./funcs/promiseTimeout"), exports);
|
|
29
|
+
__exportStar(require("./funcs/randomIP"), exports);
|
package/ts/index.ts
CHANGED