mybase 1.1.53 → 1.2.3
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/ip6addr.d.ts +10 -1
- package/mybase.d.ts +57 -0
- package/mybase.js +401 -684
- package/mybase.js.map +1 -0
- package/package.json +18 -2
- package/ts/funcs/Geoip2Paths.js +7 -5
- package/ts/funcs/Geoip2Paths.js.map +1 -0
- package/ts/funcs/MaxRuntimeHours.js.map +1 -0
- package/ts/funcs/asJSON.d.ts +1 -1
- package/ts/funcs/asJSON.js +6 -4
- package/ts/funcs/asJSON.js.map +1 -0
- package/ts/funcs/deepCopy.js.map +1 -0
- package/ts/funcs/ensureFolder.js.map +1 -0
- package/ts/funcs/fileCacheIsValid.js.map +1 -0
- package/ts/funcs/getMysql1.js.map +1 -0
- package/ts/funcs/getMysql2.js.map +1 -0
- package/ts/funcs/getWeekNumber.js.map +1 -0
- package/ts/funcs/hash_sha512.d.ts +1 -1
- package/ts/funcs/hash_sha512.js +4 -4
- package/ts/funcs/hash_sha512.js.map +1 -0
- package/ts/funcs/initMysql2Pool.js.map +1 -0
- package/ts/funcs/int2ip.js.map +1 -0
- package/ts/funcs/ip2int.js.map +1 -0
- package/ts/funcs/isLANIp.d.ts +2 -3
- package/ts/funcs/isLANIp.js +14 -15
- package/ts/funcs/isLANIp.js.map +1 -0
- package/ts/funcs/isLocal.js.map +1 -0
- package/ts/funcs/isLoopbackIP.d.ts +2 -3
- package/ts/funcs/isLoopbackIP.js +15 -16
- package/ts/funcs/isLoopbackIP.js.map +1 -0
- package/ts/funcs/knexConnection.js.map +1 -0
- package/ts/funcs/promiseTimeout.js.map +1 -0
- package/ts/funcs/randomIP.js.map +1 -0
- package/ts/funcs/randomIP6.js.map +1 -0
- package/ts/funcs/randomString.js.map +1 -0
- package/ts/funcs/randomTCPPort.js.map +1 -0
- package/ts/funcs/randomUTFString.js.map +1 -0
- package/ts/funcs/utcnow.js.map +1 -0
- package/ts/funcs/validEmail.d.ts +1 -1
- package/ts/funcs/validEmail.js +0 -3
- package/ts/funcs/validEmail.js.map +1 -0
- package/ts/funcs/validIp.js.map +1 -0
- package/ts/funcs/vaultFill.js +1 -1
- package/ts/funcs/vaultFill.js.map +1 -0
- package/ts/funcs/vaultRead.js +9 -3
- package/ts/funcs/vaultRead.js.map +1 -0
- package/ts/funcs/wait.js.map +1 -0
- package/ts/global.js.map +1 -0
- package/ts/index.js.map +1 -0
- package/ts/models/DateIterator.js.map +1 -0
- package/ts/models/IPAddress.d.ts +13 -13
- package/ts/models/IPAddress.js.map +1 -0
- package/ts/models/Interfaces.js.map +1 -0
- package/ts/models/OTPGenerator.js.map +1 -0
- package/ts/models/Timespan.js.map +1 -0
- package/ts/models/Unixtime.js.map +1 -0
- package/ts/types.d.ts +35 -0
- package/ts/types.js +1 -0
- package/ts/types.js.map +1 -0
- package/jest/isLANIp.test.js +0 -36
- package/jest/isLoopbackIP.test.js +0 -31
- package/jest.config.js +0 -7
- package/ts/funcs/Geoip2Paths.test.ts +0 -11
- package/ts/funcs/Geoip2Paths.ts +0 -26
- package/ts/funcs/MaxRuntimeHours.ts +0 -7
- package/ts/funcs/asJSON.test.js +0 -72
- package/ts/funcs/asJSON.ts +0 -6
- package/ts/funcs/deepCopy.test.ts +0 -108
- package/ts/funcs/deepCopy.ts +0 -34
- package/ts/funcs/ensureFolder.test.ts +0 -79
- package/ts/funcs/ensureFolder.ts +0 -21
- package/ts/funcs/fileCacheIsValid.ts +0 -13
- package/ts/funcs/getMysql1.ts +0 -41
- package/ts/funcs/getMysql2.ts +0 -42
- package/ts/funcs/getWeekNumber.test.ts +0 -9
- package/ts/funcs/getWeekNumber.ts +0 -31
- package/ts/funcs/hash_sha512.ts +0 -7
- package/ts/funcs/initMysql2Pool.ts +0 -11
- package/ts/funcs/int2ip.test.js +0 -33
- package/ts/funcs/int2ip.ts +0 -9
- package/ts/funcs/ip2int.test.js +0 -30
- package/ts/funcs/ip2int.ts +0 -10
- package/ts/funcs/isLANIp.test.ts +0 -59
- package/ts/funcs/isLANIp.ts +0 -37
- package/ts/funcs/isLocal.test.ts +0 -16
- package/ts/funcs/isLocal.ts +0 -5
- package/ts/funcs/isLoopbackIP.test.ts +0 -72
- package/ts/funcs/isLoopbackIP.ts +0 -32
- package/ts/funcs/knexConnection.ts +0 -42
- package/ts/funcs/promiseTimeout.test.js +0 -104
- package/ts/funcs/promiseTimeout.ts +0 -19
- package/ts/funcs/randomIP.test.ts +0 -16
- package/ts/funcs/randomIP.ts +0 -10
- package/ts/funcs/randomIP6.test.js +0 -18
- package/ts/funcs/randomIP6.ts +0 -12
- package/ts/funcs/randomString.test.ts +0 -15
- package/ts/funcs/randomString.ts +0 -5
- package/ts/funcs/randomTCPPort.test.ts +0 -62
- package/ts/funcs/randomTCPPort.ts +0 -58
- package/ts/funcs/randomUTFString.test.ts +0 -44
- package/ts/funcs/randomUTFString.ts +0 -33
- package/ts/funcs/utcnow.ts +0 -5
- package/ts/funcs/validEmail.test.js +0 -31
- package/ts/funcs/validEmail.ts +0 -13
- package/ts/funcs/validIp.test.ts +0 -33
- package/ts/funcs/validIp.ts +0 -5
- package/ts/funcs/vaultFill.ts +0 -89
- package/ts/funcs/vaultRead.ts +0 -45
- package/ts/funcs/wait.ts +0 -7
- package/ts/global.ts +0 -10
- package/ts/index.test.ts +0 -7
- package/ts/index.ts +0 -39
- package/ts/models/DateIterator.test.ts +0 -149
- package/ts/models/DateIterator.ts +0 -80
- package/ts/models/IPAddress.test.ts +0 -393
- package/ts/models/IPAddress.ts +0 -272
- package/ts/models/Interfaces.ts +0 -58
- package/ts/models/OTPGenerator.test.ts +0 -42
- package/ts/models/OTPGenerator.ts +0 -43
- package/ts/models/Timespan.ts +0 -80
- package/ts/models/Unixtime.test.ts +0 -168
- package/ts/models/Unixtime.ts +0 -208
- package/ts/types.ts +0 -1
- package/tsconfig.json +0 -36
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Unixtime.js","sourceRoot":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
|
5
|
+
login: string;
|
|
6
|
+
password: string;
|
|
7
|
+
db: string;
|
|
8
|
+
};
|
|
9
|
+
export type MysqlConnection = {
|
|
10
|
+
connect: (callback: (err: NodeJS.ErrnoException | null) => void) => void;
|
|
11
|
+
ping: (callback: (err?: NodeJS.ErrnoException | Error | null) => void) => void;
|
|
12
|
+
};
|
|
13
|
+
export type MysqlConnector = {
|
|
14
|
+
createConnection: (opts: {
|
|
15
|
+
host: string;
|
|
16
|
+
port: number;
|
|
17
|
+
user: string;
|
|
18
|
+
password: string;
|
|
19
|
+
database: string;
|
|
20
|
+
}) => MysqlConnection;
|
|
21
|
+
};
|
|
22
|
+
export type VaultClient = {
|
|
23
|
+
endpoint?: string;
|
|
24
|
+
read: (key: string) => Promise<{
|
|
25
|
+
data?: unknown;
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
28
|
+
export type SqlQueryable = {
|
|
29
|
+
query: (q: string, values: unknown[], callback: (err: Error | null, res?: unknown) => void) => void;
|
|
30
|
+
};
|
|
31
|
+
export type Geoip2PathMap = {
|
|
32
|
+
country: string | false;
|
|
33
|
+
city: string | false;
|
|
34
|
+
isp: string | false;
|
|
35
|
+
ct: string | false;
|
|
36
|
+
};
|
package/ts/types.js
CHANGED
package/ts/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":";;AAyCA,YAAY"}
|
package/jest/isLANIp.test.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const { isLANIp } = require('./../mybase');
|
|
2
|
-
|
|
3
|
-
test('should return true for private IPv4', () => {
|
|
4
|
-
const ip = '192.168.1.1';
|
|
5
|
-
expect(isLANIp(ip)).toBe(true);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('should return true for private IPv6', () => {
|
|
9
|
-
const ip = 'fd00::';
|
|
10
|
-
expect(isLANIp(ip)).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('should return null for public IPv4', () => {
|
|
14
|
-
const ip = '8.8.8.8';
|
|
15
|
-
expect(isLANIp(ip)).toBe(null);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('should return null for public IPv6', () => {
|
|
19
|
-
const ip = '2001:4860:4860::8888';
|
|
20
|
-
expect(isLANIp(ip)).toBe(null);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('should return false for invalid IP', () => {
|
|
24
|
-
const ip = 'invalid';
|
|
25
|
-
expect(isLANIp(ip)).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('should return false for invalid IP', () => {
|
|
29
|
-
const ip = '1.2.3';
|
|
30
|
-
expect(isLANIp(ip)).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('should return null for non private IPv6', () => {
|
|
34
|
-
const ip = '::2';
|
|
35
|
-
expect(isLANIp(ip)).toBe(null);
|
|
36
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const { isLoopbackIP } = require('./../mybase') // adjust the path to mybase.js
|
|
2
|
-
|
|
3
|
-
test('should return true for local IPv4', () => {
|
|
4
|
-
const ip = '127.0.0.1'
|
|
5
|
-
expect(isLoopbackIP(ip)).toBe(true)
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test('should return true for local IPv4', () => {
|
|
9
|
-
const ip = '127.127.127.127'
|
|
10
|
-
expect(isLoopbackIP(ip)).toBe(true)
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('should return true for local IPv6', () => {
|
|
14
|
-
const ip = '::1'
|
|
15
|
-
expect(isLoopbackIP(ip)).toBe(true)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('should return null for non-local IPv4', () => {
|
|
19
|
-
const ip = '8.8.8.8'
|
|
20
|
-
expect(isLoopbackIP(ip)).toBe(null)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('should return null for non-local IPv6', () => {
|
|
24
|
-
const ip = '2001:4860:4860::8888'
|
|
25
|
-
expect(isLoopbackIP(ip)).toBe(null)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('should return false for invalid IP', () => {
|
|
29
|
-
const ip = 'invalid'
|
|
30
|
-
expect(isLoopbackIP(ip)).toBe(false)
|
|
31
|
-
})
|
package/jest.config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Geoip2Paths } from './Geoip2Paths'
|
|
2
|
-
import * as fs from 'fs'
|
|
3
|
-
|
|
4
|
-
describe('Geoip2Paths', () => {
|
|
5
|
-
it('should return a valid path', () => {
|
|
6
|
-
const paths = Geoip2Paths()
|
|
7
|
-
expect(paths).toHaveProperty('country')
|
|
8
|
-
expect(typeof paths.country).toBe('string')
|
|
9
|
-
expect(fs.existsSync(paths.country as string)).toBe(true)
|
|
10
|
-
})
|
|
11
|
-
})
|
package/ts/funcs/Geoip2Paths.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
|
|
4
|
-
export type Geoip2Paths = {
|
|
5
|
-
country:string|false,
|
|
6
|
-
city:string|false,
|
|
7
|
-
isp:string|false,
|
|
8
|
-
ct:string|false,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export function Geoip2Paths() :Geoip2Paths {
|
|
13
|
-
function firstExisting(paths:Array<string>) : string|false {
|
|
14
|
-
if (Array.isArray(paths))
|
|
15
|
-
for(let fpath of paths)
|
|
16
|
-
if (fs.existsSync(fpath)) return fpath
|
|
17
|
-
return false
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
country:firstExisting(['/opt/geoip2/GeoIP2-Country.mmdb','/usr/local/var/GeoIP/GeoIP2-Country.mmdb','/var/lib/GeoIP/GeoIP2-Country.mmdb','/usr/share/GeoIP/GeoIP2-Country.mmdb',path.join(__dirname, 'assets/GeoIP2-Country.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-Country.mmdb')]),
|
|
22
|
-
city:firstExisting(['/opt/geoip2/GeoIP2-City.mmdb','/usr/local/var/GeoIP/GeoIP2-City.mmdb','/var/lib/GeoIP/GeoIP2-City.mmdb','/usr/share/GeoIP/GeoIP2-City.mmdb',path.join(__dirname, 'assets/GeoIP2-City.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-City.mmdb')]),
|
|
23
|
-
isp:firstExisting(['/opt/geoip2/GeoIP2-ISP.mmdb','/usr/local/var/GeoIP/GeoIP2-ISP.mmdb','/var/lib/GeoIP/GeoIP2-ISP.mmdb','/usr/share/GeoIP/GeoIP2-ISP.mmdb',path.join(__dirname, 'assets/GeoIP2-ISP.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-ISP.mmdb')]),
|
|
24
|
-
ct:firstExisting(['/opt/geoip2/GeoIP2-Connection-Type.mmdb','/usr/local/var/GeoIP/GeoIP2-Connection-Type.mmdb','/var/lib/GeoIP/GeoIP2-Connection-Type.mmdb','/usr/share/GeoIP/GeoIP2-Connection-Type.mmdb',path.join(__dirname, 'assets/GeoIP2-Connection-Type.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-Connection-Type.mmdb')]),
|
|
25
|
-
}
|
|
26
|
-
}
|
package/ts/funcs/asJSON.test.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const { asJSON } = require('./asJSON')
|
|
2
|
-
|
|
3
|
-
describe('asJSON', () => {
|
|
4
|
-
// Returns parsed JSON object when valid JSON string is passed as input.
|
|
5
|
-
it('should return parsed JSON object when valid JSON string is passed as input', () => {
|
|
6
|
-
const inputString = '{"name": "John", "age": 30}';
|
|
7
|
-
const expectedOutput = { name: "John", age: 30 };
|
|
8
|
-
const result = asJSON(inputString);
|
|
9
|
-
expect(result).toEqual(expectedOutput);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
// Returns false when empty string is passed as input.
|
|
13
|
-
it('should return false when empty string is passed as input', () => {
|
|
14
|
-
const inputString = "";
|
|
15
|
-
const expectedOutput = false;
|
|
16
|
-
const result = asJSON(inputString);
|
|
17
|
-
expect(result).toEqual(expectedOutput);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Returns false when non-string input is passed.
|
|
21
|
-
it('should return false when non-string input is passed', () => {
|
|
22
|
-
const inputString = 123;
|
|
23
|
-
const expectedOutput = false;
|
|
24
|
-
const result = asJSON(inputString);
|
|
25
|
-
expect(result).toEqual(expectedOutput);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// Returns false when null is passed as input.
|
|
29
|
-
it('should return false when null is passed as input', () => {
|
|
30
|
-
const inputString = null;
|
|
31
|
-
const expectedOutput = false;
|
|
32
|
-
const result = asJSON(inputString);
|
|
33
|
-
expect(result).toEqual(expectedOutput);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Returns false when undefined is passed as input.
|
|
37
|
-
it('should return false when undefined is passed as input', () => {
|
|
38
|
-
const inputString = undefined;
|
|
39
|
-
const expectedOutput = false;
|
|
40
|
-
const result = asJSON(inputString);
|
|
41
|
-
expect(result).toEqual(expectedOutput);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Returns false when NaN is passed as input.
|
|
45
|
-
it('should return false when NaN is passed as input', () => {
|
|
46
|
-
const inputString = NaN;
|
|
47
|
-
const expectedOutput = false;
|
|
48
|
-
const result = asJSON(inputString);
|
|
49
|
-
expect(result).toEqual(expectedOutput);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Returns false when invalid JSON string is passed as input.
|
|
53
|
-
it('should return false when invalid JSON string is passed as input', () => {
|
|
54
|
-
const inputString = 'invalid json';
|
|
55
|
-
const result = asJSON(inputString);
|
|
56
|
-
expect(result).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Returns false when Infinity is passed as input.
|
|
60
|
-
it('should return false when Infinity is passed as input', () => {
|
|
61
|
-
const inputString = 'Infinity';
|
|
62
|
-
const result = asJSON(inputString);
|
|
63
|
-
expect(result).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Returns false when input string contains a single quote.
|
|
67
|
-
it('should return false when input string contains a single quote', () => {
|
|
68
|
-
const inputString = "{'name': 'John'}";
|
|
69
|
-
const result = asJSON(inputString);
|
|
70
|
-
expect(result).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
});
|
package/ts/funcs/asJSON.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Unixtime } from "../models/Unixtime";
|
|
2
|
-
import { deepCopy } from "./deepCopy"
|
|
3
|
-
|
|
4
|
-
describe('deepCopy', () => {
|
|
5
|
-
it('deep-copies plain objects', () => {
|
|
6
|
-
const src = { a: 1, b: { c: 2 } };
|
|
7
|
-
const copy = deepCopy(src) as typeof src;
|
|
8
|
-
|
|
9
|
-
expect(copy).toEqual(src);
|
|
10
|
-
expect(copy).not.toBe(src);
|
|
11
|
-
|
|
12
|
-
copy.b.c = 3;
|
|
13
|
-
expect(src.b.c).toBe(2); // original stays intact
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
it('Date objects are copied as Date objects', () => {
|
|
18
|
-
const src = { date: new Date() }
|
|
19
|
-
const copy = deepCopy(src) as typeof src
|
|
20
|
-
expect(copy.date).toBeInstanceOf(Date)
|
|
21
|
-
expect(copy.date).not.toBe(src.date)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('deep-copies arrays', () => {
|
|
25
|
-
const src = [1, [2, 3]];
|
|
26
|
-
const copy = deepCopy(src) as typeof src;
|
|
27
|
-
|
|
28
|
-
expect(copy).toEqual(src);
|
|
29
|
-
//@ts-ignore
|
|
30
|
-
copy[1][0] = 99;
|
|
31
|
-
//@ts-ignore
|
|
32
|
-
expect(src[1][0]).toBe(2);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns primitives unchanged', () => {
|
|
36
|
-
expect(deepCopy(42 as any)).toBe(42);
|
|
37
|
-
expect(deepCopy('hello' as any)).toBe('hello');
|
|
38
|
-
expect(deepCopy(null as any)).toBeNull();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should handle circular references', () => {
|
|
42
|
-
const obj: any = { a: 1 };
|
|
43
|
-
obj.self = obj;
|
|
44
|
-
const copy = deepCopy(obj);
|
|
45
|
-
expect(copy).toEqual({ a: 1, self: copy });
|
|
46
|
-
expect(copy.self).toBe(copy);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should preserve prototype chain', () => {
|
|
50
|
-
class MyClass { x = 1; }
|
|
51
|
-
const obj = new MyClass();
|
|
52
|
-
const copy = deepCopy(obj);
|
|
53
|
-
expect(copy).toBeInstanceOf(MyClass);
|
|
54
|
-
expect(copy.x).toBe(1);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('changing Date at src should not change copy', () => {
|
|
58
|
-
const src = { a: new Date("2024-05-05"), b: { c: 2 } };
|
|
59
|
-
const copy = deepCopy(src) as typeof src;
|
|
60
|
-
expect(copy).toEqual(src);
|
|
61
|
-
expect(copy).not.toBe(src);
|
|
62
|
-
src.a.setFullYear(2025)
|
|
63
|
-
expect(src.a.getFullYear()).toBe(2025)
|
|
64
|
-
expect(copy.a.getFullYear()).toBe(2024)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('changing src integer should not change copy', () => {
|
|
68
|
-
const src = { a: 1, b: { c: 2 } };
|
|
69
|
-
const copy = deepCopy(src) as typeof src;
|
|
70
|
-
expect(copy).toEqual(src);
|
|
71
|
-
expect(copy).not.toBe(src);
|
|
72
|
-
src.a = 2
|
|
73
|
-
expect(src.a).toBe(2)
|
|
74
|
-
expect(copy.a).toBe(1)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('changing src string should not change copy', () => {
|
|
78
|
-
const src = { a: "hello", b: { c: 2 } };
|
|
79
|
-
const copy = deepCopy(src) as typeof src;
|
|
80
|
-
expect(copy).toEqual(src);
|
|
81
|
-
expect(copy).not.toBe(src);
|
|
82
|
-
src.a = "world"
|
|
83
|
-
expect(src.a).toBe("world")
|
|
84
|
-
expect(copy.a).toBe("hello")
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('changing src boolean should not change copy', () => {
|
|
88
|
-
const src = { a: true, b: { c: 2 } };
|
|
89
|
-
const copy = deepCopy(src) as typeof src;
|
|
90
|
-
expect(copy).toEqual(src);
|
|
91
|
-
expect(copy).not.toBe(src);
|
|
92
|
-
src.a = false
|
|
93
|
-
expect(src.a).toBe(false)
|
|
94
|
-
expect(copy.a).toBe(true)
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('changing src Unixtime should not change copy', () => {
|
|
99
|
-
const src = { a: new Unixtime("2024-05-02"), b: { c: 2 } };
|
|
100
|
-
const copy = deepCopy(src) as typeof src;
|
|
101
|
-
expect(copy).toEqual(src);
|
|
102
|
-
expect(copy).not.toBe(src);
|
|
103
|
-
src.a.addYears(-1)
|
|
104
|
-
expect(src.a.toDate().getFullYear()).toBe(2023)
|
|
105
|
-
expect(copy.a.toDate().getFullYear()).toBe(2024)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
});
|
package/ts/funcs/deepCopy.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export function deepCopy<T>(obj: T, visited = new WeakMap()): T {
|
|
2
|
-
// Handle null and non-objects
|
|
3
|
-
if (obj === null || typeof obj !== 'object') {
|
|
4
|
-
return obj;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// Handle circular references
|
|
8
|
-
if (visited.has(obj)) {
|
|
9
|
-
return visited.get(obj);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Handle Date
|
|
13
|
-
if (obj instanceof Date) {
|
|
14
|
-
return new Date(obj.getTime()) as any;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Handle Array
|
|
18
|
-
if (Array.isArray(obj)) {
|
|
19
|
-
const copy: any[] = [];
|
|
20
|
-
visited.set(obj, copy);
|
|
21
|
-
obj.forEach((item, i) => {
|
|
22
|
-
copy[i] = deepCopy(item, visited);
|
|
23
|
-
});
|
|
24
|
-
return copy as T;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Handle Object
|
|
28
|
-
const copy = Object.create(Object.getPrototypeOf(obj));
|
|
29
|
-
visited.set(obj, copy);
|
|
30
|
-
for (const key of Object.keys(obj)) {
|
|
31
|
-
copy[key] = deepCopy((obj as any)[key], visited);
|
|
32
|
-
}
|
|
33
|
-
return copy;
|
|
34
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ensureFolder } from './ensureFolder'
|
|
2
|
-
import * as fs from 'fs'
|
|
3
|
-
import { wait } from '../index'
|
|
4
|
-
|
|
5
|
-
describe('ensureFolder', () => {
|
|
6
|
-
let folderPath: string
|
|
7
|
-
let filePath: string
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
folderPath = `/tmp/ensureFolder.test.${Date.now()}`
|
|
11
|
-
filePath = `/tmp/ensureFolder.test.${Date.now()}.file`
|
|
12
|
-
await wait(1/1000)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should create a folder if it does not exist and return the folder path', () => {
|
|
16
|
-
const folder = ensureFolder(folderPath)
|
|
17
|
-
expect(folder).toBe(folderPath)
|
|
18
|
-
expect(fs.existsSync(folderPath)).toBe(true)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should throw an error if the folder path exists and is not a folder', () => {
|
|
22
|
-
fs.writeFileSync(filePath, 'test')
|
|
23
|
-
expect(() => ensureFolder(filePath)).toThrow('exists and is not a folder')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('creating same folder twice should return the same folder path', () => {
|
|
27
|
-
expect(ensureFolder(folderPath)).toBe(folderPath)
|
|
28
|
-
expect(fs.existsSync(folderPath)).toBe(true)
|
|
29
|
-
expect(ensureFolder(folderPath)).toBe(folderPath)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('we should be able to create recursively a folders and default to recursive mode', () => {
|
|
33
|
-
let sfolder= ensureFolder(`${folderPath}/subfolder/subsubfolder`)
|
|
34
|
-
expect(sfolder).toBe(`${folderPath}/subfolder/subsubfolder`)
|
|
35
|
-
if (sfolder) expect(fs.existsSync(sfolder)).toBe(true)
|
|
36
|
-
// test creating 10 recursive folders
|
|
37
|
-
for(let i=0;i<10;i++) {
|
|
38
|
-
sfolder= `${sfolder}/subsubsubfolder${i}`
|
|
39
|
-
expect(ensureFolder(sfolder)).toBe(sfolder)
|
|
40
|
-
if (sfolder) expect(fs.existsSync(sfolder)).toBe(true)
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('we should not be able to disable recursive mode', () => {
|
|
45
|
-
expect(ensureFolder(`${folderPath}/subfolder/subsubfolder`, { recursive: false })).toBe(`${folderPath}/subfolder/subsubfolder`)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('we should be able to create a folder with a custom mode', () => {
|
|
49
|
-
let sfolder= ensureFolder(`${folderPath}/subfolder/subsubfolder`, { mode: 0o700 })
|
|
50
|
-
expect(sfolder).toBe(`${folderPath}/subfolder/subsubfolder`)
|
|
51
|
-
if (sfolder) expect(fs.existsSync(sfolder)).toBe(true)
|
|
52
|
-
expect(fs.statSync(sfolder).mode & 0o777).toBe(0o700);
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('try to create a file where we do not have write permissions should throw an error', () => {
|
|
56
|
-
expect(() => ensureFolder('/dev/ensureFolder.test.file')).toThrow()
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should throw an error if folder path is empty', () => {
|
|
60
|
-
expect(() => ensureFolder('')).toThrow();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should throw an error if folder path is null or undefined or array or object', () => {
|
|
64
|
-
expect(() => ensureFolder(null as unknown as string)).toThrow();
|
|
65
|
-
expect(() => ensureFolder(undefined as unknown as string)).toThrow();
|
|
66
|
-
expect(() => ensureFolder([] as unknown as string)).toThrow();
|
|
67
|
-
expect(() => ensureFolder({} as unknown as string)).toThrow();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should not change the permissions of an existing folder', () => {
|
|
71
|
-
fs.mkdirSync(folderPath, { mode: 0o755 });
|
|
72
|
-
ensureFolder(folderPath, { mode: 0o700 });
|
|
73
|
-
expect(fs.statSync(folderPath).mode & 0o777).toBe(0o755);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should throw error for invalid mode value', () => {
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
})
|
package/ts/funcs/ensureFolder.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import debug from 'debug'
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import { MakeDirectoryOptions } from 'fs';
|
|
4
|
-
const dbg = debug('_mybase:ensureFolder')
|
|
5
|
-
|
|
6
|
-
export function ensureFolder(folderPath: string, options?: MakeDirectoryOptions | null) : string {
|
|
7
|
-
options = options || {}
|
|
8
|
-
options.recursive = true
|
|
9
|
-
dbg('ensureFolder()', folderPath)
|
|
10
|
-
if (fs.existsSync(folderPath)) {
|
|
11
|
-
if (!fs.lstatSync(folderPath).isDirectory()) {
|
|
12
|
-
dbg(`${folderPath} exists and is not a folder`)
|
|
13
|
-
throw new Error(`${folderPath} exists and is not a folder`);
|
|
14
|
-
}
|
|
15
|
-
dbg(`${folderPath} exists and is a folder`)
|
|
16
|
-
return folderPath
|
|
17
|
-
}
|
|
18
|
-
dbg(`creating ${folderPath}`,options)
|
|
19
|
-
fs.mkdirSync(folderPath, options)
|
|
20
|
-
return folderPath
|
|
21
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs'
|
|
2
|
-
|
|
3
|
-
export function fileCacheIsValid(cacheFileName : string, cache_in_minutes = 60) : boolean {
|
|
4
|
-
if (fs.existsSync(cacheFileName)) {
|
|
5
|
-
const stat = fs.statSync(cacheFileName)
|
|
6
|
-
const mtime = new Date(stat.mtime).getTime()
|
|
7
|
-
if (Date.now() - mtime < cache_in_minutes * 60 * 1000) {
|
|
8
|
-
// cache is still valid
|
|
9
|
-
return true
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false
|
|
13
|
-
}
|
package/ts/funcs/getMysql1.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as mysql1 from "mysql"
|
|
2
|
-
import { MysqlError } from "mysql"
|
|
3
|
-
import debug from "debug"
|
|
4
|
-
const dbg = debug("getMysql1")
|
|
5
|
-
|
|
6
|
-
export type Mysql1ServerConfiguration = {
|
|
7
|
-
host: string,
|
|
8
|
-
port: number,
|
|
9
|
-
login: string,
|
|
10
|
-
password: string,
|
|
11
|
-
db: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getMysql1(config: Mysql1ServerConfiguration, pingInterval: number = 0) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const mysql_client = mysql1.createConnection({
|
|
17
|
-
host: config.host,
|
|
18
|
-
port: config.port ? config.port : 3306,
|
|
19
|
-
user: config.login,
|
|
20
|
-
password: config.password,
|
|
21
|
-
database: config.db
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
mysql_client.connect((err:MysqlError, res) => {
|
|
25
|
-
if (err) {
|
|
26
|
-
dbg(`mysql connection has failed to ${config.host}@${config.db}`, err)
|
|
27
|
-
return reject(err)
|
|
28
|
-
}
|
|
29
|
-
dbg(`mysql connection has been established to ${config.host}@${config.db}`)
|
|
30
|
-
// install a pinger every 30 seconds to keep the connection alive
|
|
31
|
-
if (pingInterval > 0)
|
|
32
|
-
setInterval(() => {
|
|
33
|
-
mysql_client.ping(function (err:MysqlError) {
|
|
34
|
-
if (err) return console.log(`could not ping mysql ${config.host}@${config.db}`, err.code)
|
|
35
|
-
dbg(`mysql ${config.host}@${config.db} is pinging properly`)
|
|
36
|
-
})
|
|
37
|
-
}, pingInterval)
|
|
38
|
-
resolve(mysql_client)
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
}
|
package/ts/funcs/getMysql2.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as mysql2 from "mysql2"
|
|
2
|
-
import { QueryError,Connection } from "mysql2"
|
|
3
|
-
import debug from "debug"
|
|
4
|
-
const dbg = debug("getMysql2")
|
|
5
|
-
|
|
6
|
-
export type Mysql2ServerConfiguration = {
|
|
7
|
-
host: string,
|
|
8
|
-
port: number,
|
|
9
|
-
login: string,
|
|
10
|
-
password: string,
|
|
11
|
-
db: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getMysql2(config: Mysql2ServerConfiguration, pingInterval: number = 0):Promise<Connection> {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const mysql_client = mysql2.createConnection({
|
|
17
|
-
host: config.host,
|
|
18
|
-
port: config.port ? config.port : 3306,
|
|
19
|
-
user: config.login,
|
|
20
|
-
password: config.password,
|
|
21
|
-
database: config.db
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
mysql_client.connect((err: QueryError | null) => {
|
|
25
|
-
if (err) {
|
|
26
|
-
dbg(`mysql connection has failed to ${config.host}@${config.db}`, err)
|
|
27
|
-
return reject(err)
|
|
28
|
-
}
|
|
29
|
-
dbg(`mysql connection has been established to ${config.host}@${config.db}`)
|
|
30
|
-
// install a pinger every 30 seconds to keep the connection alive
|
|
31
|
-
if (pingInterval > 0)
|
|
32
|
-
setInterval(() => {
|
|
33
|
-
mysql_client.ping(function (err:QueryError | null) {
|
|
34
|
-
if (err)
|
|
35
|
-
return console.log(`could not ping mysql ${config.host}@${config.db}`, err.code)
|
|
36
|
-
dbg(`mysql ${config.host}@${config.db} is pinging properly`)
|
|
37
|
-
})
|
|
38
|
-
}, pingInterval)
|
|
39
|
-
resolve(mysql_client)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { getWeekNumber } from './getWeekNumber'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe('getWeekNumber', () => {
|
|
5
|
-
it('should return the correct week number', () => {
|
|
6
|
-
expect(getWeekNumber(new Date('2012-01-01'))).toBe(52)
|
|
7
|
-
expect(getWeekNumber(new Date('2014-12-30'))).toBe(1)
|
|
8
|
-
})
|
|
9
|
-
})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// credit: https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
|
|
2
|
-
/* For a given date, get the ISO week number
|
|
3
|
-
|
|
4
|
-
Based on information at:
|
|
5
|
-
|
|
6
|
-
THIS PAGE (DOMAIN EVEN) DOESN'T EXIST ANYMORE UNFORTUNATELY
|
|
7
|
-
http://www.merlyn.demon.co.uk/weekcalc.htm#WNR
|
|
8
|
-
|
|
9
|
-
Algorithm is to find nearest thursday, it's year
|
|
10
|
-
is the year of the week number. Then get weeks
|
|
11
|
-
between that date and the first day of that year.
|
|
12
|
-
|
|
13
|
-
Note that dates in one year can be weeks of previous
|
|
14
|
-
or next year, overlap is up to 3 days.
|
|
15
|
-
|
|
16
|
-
e.g. 2014/12/29 is Monday in week 1 of 2015
|
|
17
|
-
2012/1/1 is Sunday in week 52 of 2011
|
|
18
|
-
*/
|
|
19
|
-
export function getWeekNumber(d: Date = new Date()): number {
|
|
20
|
-
// Copy date so don't modify original
|
|
21
|
-
const date = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
|
|
22
|
-
// Set to nearest Thursday: current date + 4 - current day number
|
|
23
|
-
// Make Sunday's day number 7
|
|
24
|
-
date.setUTCDate(date.getUTCDate() + 4 - (date.getUTCDay() || 7));
|
|
25
|
-
// Get first day of year
|
|
26
|
-
const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
|
|
27
|
-
// Calculate full weeks to nearest Thursday
|
|
28
|
-
const weekNo = Math.ceil(((date.getTime() - yearStart.getTime()) / 86400000 + 1) / 7);
|
|
29
|
-
// Return the week number
|
|
30
|
-
return weekNo;
|
|
31
|
-
}
|