mybase 1.2.2 → 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.
Files changed (109) hide show
  1. package/mybase.js.map +1 -0
  2. package/package.json +16 -1
  3. package/ts/funcs/Geoip2Paths.js.map +1 -0
  4. package/ts/funcs/MaxRuntimeHours.js.map +1 -0
  5. package/ts/funcs/asJSON.js.map +1 -0
  6. package/ts/funcs/deepCopy.js.map +1 -0
  7. package/ts/funcs/ensureFolder.js.map +1 -0
  8. package/ts/funcs/fileCacheIsValid.js.map +1 -0
  9. package/ts/funcs/getMysql1.js.map +1 -0
  10. package/ts/funcs/getMysql2.js.map +1 -0
  11. package/ts/funcs/getWeekNumber.js.map +1 -0
  12. package/ts/funcs/hash_sha512.js.map +1 -0
  13. package/ts/funcs/initMysql2Pool.js.map +1 -0
  14. package/ts/funcs/int2ip.js.map +1 -0
  15. package/ts/funcs/ip2int.js.map +1 -0
  16. package/ts/funcs/isLANIp.js.map +1 -0
  17. package/ts/funcs/isLocal.js.map +1 -0
  18. package/ts/funcs/isLoopbackIP.js.map +1 -0
  19. package/ts/funcs/knexConnection.js.map +1 -0
  20. package/ts/funcs/promiseTimeout.js.map +1 -0
  21. package/ts/funcs/randomIP.js.map +1 -0
  22. package/ts/funcs/randomIP6.js.map +1 -0
  23. package/ts/funcs/randomString.js.map +1 -0
  24. package/ts/funcs/randomTCPPort.js.map +1 -0
  25. package/ts/funcs/randomUTFString.js.map +1 -0
  26. package/ts/funcs/utcnow.js.map +1 -0
  27. package/ts/funcs/validEmail.js.map +1 -0
  28. package/ts/funcs/validIp.js.map +1 -0
  29. package/ts/funcs/vaultFill.js.map +1 -0
  30. package/ts/funcs/vaultRead.js.map +1 -0
  31. package/ts/funcs/wait.js.map +1 -0
  32. package/ts/global.js.map +1 -0
  33. package/ts/index.js.map +1 -0
  34. package/ts/models/DateIterator.js.map +1 -0
  35. package/ts/models/IPAddress.js.map +1 -0
  36. package/ts/models/Interfaces.js.map +1 -0
  37. package/ts/models/OTPGenerator.js.map +1 -0
  38. package/ts/models/Timespan.js.map +1 -0
  39. package/ts/models/Unixtime.js.map +1 -0
  40. package/ts/types.js.map +1 -0
  41. package/jest/isLANIp.test.js +0 -36
  42. package/jest/isLoopbackIP.test.js +0 -31
  43. package/jest.config.js +0 -13
  44. package/mybase.test.ts +0 -647
  45. package/mybase.ts +0 -397
  46. package/ts/funcs/Geoip2Paths.test.ts +0 -11
  47. package/ts/funcs/Geoip2Paths.ts +0 -28
  48. package/ts/funcs/MaxRuntimeHours.ts +0 -7
  49. package/ts/funcs/asJSON.test.js +0 -72
  50. package/ts/funcs/asJSON.ts +0 -9
  51. package/ts/funcs/deepCopy.test.ts +0 -108
  52. package/ts/funcs/deepCopy.ts +0 -34
  53. package/ts/funcs/ensureFolder.test.ts +0 -79
  54. package/ts/funcs/ensureFolder.ts +0 -21
  55. package/ts/funcs/fileCacheIsValid.ts +0 -13
  56. package/ts/funcs/getMysql1.ts +0 -41
  57. package/ts/funcs/getMysql2.ts +0 -42
  58. package/ts/funcs/getWeekNumber.test.ts +0 -9
  59. package/ts/funcs/getWeekNumber.ts +0 -31
  60. package/ts/funcs/hash_sha512.ts +0 -6
  61. package/ts/funcs/initMysql2Pool.ts +0 -11
  62. package/ts/funcs/int2ip.test.js +0 -33
  63. package/ts/funcs/int2ip.ts +0 -9
  64. package/ts/funcs/ip2int.test.js +0 -30
  65. package/ts/funcs/ip2int.ts +0 -10
  66. package/ts/funcs/isLANIp.test.ts +0 -58
  67. package/ts/funcs/isLANIp.ts +0 -34
  68. package/ts/funcs/isLocal.test.ts +0 -16
  69. package/ts/funcs/isLocal.ts +0 -5
  70. package/ts/funcs/isLoopbackIP.test.ts +0 -72
  71. package/ts/funcs/isLoopbackIP.ts +0 -30
  72. package/ts/funcs/knexConnection.ts +0 -42
  73. package/ts/funcs/promiseTimeout.test.js +0 -104
  74. package/ts/funcs/promiseTimeout.ts +0 -19
  75. package/ts/funcs/randomIP.test.ts +0 -16
  76. package/ts/funcs/randomIP.ts +0 -10
  77. package/ts/funcs/randomIP6.test.js +0 -18
  78. package/ts/funcs/randomIP6.ts +0 -12
  79. package/ts/funcs/randomString.test.ts +0 -15
  80. package/ts/funcs/randomString.ts +0 -5
  81. package/ts/funcs/randomTCPPort.test.ts +0 -62
  82. package/ts/funcs/randomTCPPort.ts +0 -58
  83. package/ts/funcs/randomUTFString.test.ts +0 -44
  84. package/ts/funcs/randomUTFString.ts +0 -33
  85. package/ts/funcs/utcnow.ts +0 -5
  86. package/ts/funcs/validEmail.test.js +0 -31
  87. package/ts/funcs/validEmail.ts +0 -11
  88. package/ts/funcs/validIp.test.ts +0 -33
  89. package/ts/funcs/validIp.ts +0 -5
  90. package/ts/funcs/vaultFill.ts +0 -89
  91. package/ts/funcs/vaultRead.ts +0 -50
  92. package/ts/funcs/wait.ts +0 -7
  93. package/ts/global.ts +0 -10
  94. package/ts/index.test.ts +0 -7
  95. package/ts/index.ts +0 -39
  96. package/ts/models/DateIterator.test.ts +0 -149
  97. package/ts/models/DateIterator.ts +0 -80
  98. package/ts/models/IPAddress.test.ts +0 -393
  99. package/ts/models/IPAddress.ts +0 -272
  100. package/ts/models/Interfaces.ts +0 -58
  101. package/ts/models/OTPGenerator.test.ts +0 -42
  102. package/ts/models/OTPGenerator.ts +0 -43
  103. package/ts/models/Timespan.ts +0 -80
  104. package/ts/models/Unixtime.test.ts +0 -168
  105. package/ts/models/Unixtime.ts +0 -208
  106. package/ts/types.ts +0 -42
  107. package/tsconfig.jest.json +0 -11
  108. package/tsconfig.json +0 -37
  109. package/types/third-party.d.ts +0 -21
@@ -1,208 +0,0 @@
1
- import { Timespan } from "./Timespan"
2
-
3
- // this will be a class to work with short and long version of unixtime format
4
- export class Unixtime {
5
- private value: Date
6
-
7
-
8
- static EMPTY = new Unixtime(new Date(0))
9
-
10
- static NOW() {
11
- return new Unixtime(Date.now())
12
- }
13
-
14
- static now() {
15
- return new Unixtime(Date.now())
16
- }
17
-
18
- greaterThan(other: Unixtime) {
19
- return this.toLongUnixtime() > other.toLongUnixtime()
20
- }
21
-
22
- isEmpty() {
23
- return this.toLongUnixtime() == 0
24
- }
25
-
26
- lessThan(other: Unixtime) {
27
- return this.toLongUnixtime() < other.toLongUnixtime()
28
- }
29
-
30
- get elapsed():Timespan {
31
- return new Timespan(Date.now() - this.toLongUnixtime())
32
- }
33
-
34
- toJSON() {
35
- return {
36
- __type:'Unixtime',
37
- value:this.toLongUnixtime()
38
- }
39
- }
40
-
41
-
42
- constructor(value: Date | string | number) {
43
- if (typeof value === 'string') {
44
- this.value = new Date(value)
45
- } else if (typeof value === 'number') {
46
- // the number might be short or long form(from nodejs Date.now()
47
- if (value < 10000000000) value *= 1000
48
- else
49
- value = Math.round(value)
50
- // set the value
51
- this.value = new Date(value)
52
- }
53
- else if (value instanceof Date) {
54
- this.value = value
55
- }
56
- else {
57
- throw new Error('Invalid value')
58
- }
59
-
60
- if (isNaN(this.value.getTime())) {
61
- throw new Error('Invalid date')
62
- }
63
- }
64
-
65
- public addTimespan(timespan: Timespan): Unixtime {
66
- this.value = new Date(this.value.getTime() + timespan.miliseconds)
67
- return this
68
- }
69
-
70
- public subtractTimespan(timespan: Timespan): Unixtime {
71
- this.value = new Date(this.value.getTime() - timespan.miliseconds)
72
- return this
73
- }
74
-
75
- public addMiliseconds(miliseconds: number = 1): Unixtime {
76
- this.value = new Date(this.value.getTime() + miliseconds)
77
- return this
78
- }
79
-
80
- public addSeconds(seconds: number = 1): Unixtime {
81
- this.value = new Date(this.value.getTime() + seconds * 1000)
82
- return this
83
- }
84
-
85
- public addMinutes(minutes: number = 1): Unixtime {
86
- this.value = new Date(this.value.getTime() + minutes * 60000)
87
- return this
88
- }
89
-
90
- public addHours(hours: number = 1): Unixtime {
91
- this.value = new Date(this.value.getTime() + hours * 3600000)
92
- return this
93
- }
94
-
95
- public addDays(days: number = 1): Unixtime {
96
- this.value = new Date(this.value.getTime() + days * 86400000)
97
- return this
98
- }
99
-
100
- public addMonths(months: number = 1): Unixtime {
101
- this.value.setUTCMonth(this.value.getMonth() + months)
102
- return this
103
- }
104
-
105
- public addYears(years: number = 1): Unixtime {
106
- this.value.setUTCFullYear(this.year + years)
107
- return this
108
- }
109
-
110
- public yyyymmdd(seperator: string=""): string {
111
- let mm = this.month
112
- let dd = this.day
113
- return [this.value.getFullYear(),
114
- (mm > 9 ? '' : '0') + mm,
115
- (dd > 9 ? '' : '0') + dd,
116
- ].join(seperator)
117
- }
118
-
119
- public yyyymmddhh(seperator: string=""): string {
120
- let mm = this.month
121
- let dd = this.day
122
- let hh = this.hours
123
- return [this.year,
124
- (mm > 9 ? '' : '0') + mm,
125
- (dd > 9 ? '' : '0') + dd,
126
- (hh > 9 ? '' : '0') + hh,
127
- ].join(seperator)
128
- }
129
-
130
- /**
131
- @deprecated use 'day' instead
132
- */
133
- public getDay() : number {return this.value.getUTCDay()}
134
-
135
- get day(): number { return this.value.getUTCDate() }
136
- get month(): number { return this.value.getUTCMonth() + 1 }
137
- get year(): number { return this.value.getUTCFullYear() }
138
- get hours(): number { return this.value.getUTCHours() }
139
- get minutes(): number { return this.value.getUTCMinutes() }
140
- get seconds(): number { return this.value.getUTCSeconds() }
141
-
142
- static from(value: Date | string | number) {
143
- return new Unixtime(value)
144
- }
145
-
146
- public toShortUnixtime(): number {
147
- return Math.round(this.toLongUnixtime() / 1000)
148
- }
149
-
150
- public toLongUnixtime(): number {
151
- return this.value.getTime()
152
- }
153
-
154
- public toDate(): Date {
155
- return this.value
156
- }
157
-
158
- public toISOString(): string {
159
- return this.value.toISOString()
160
- }
161
-
162
- public elapsedSeconds(): number {
163
- return Math.round((Date.now() - this.toLongUnixtime()) / 1000)
164
- }
165
-
166
- public elapsedMinutes(): number {
167
- return Math.round(this.elapsedSeconds() / 60)
168
- }
169
-
170
- clone():Unixtime {
171
- return new Unixtime(this.toLongUnixtime())
172
- }
173
-
174
- /**
175
- * @param max maximum timespan to subtract
176
- * @returns returns random time in the past within given timespan
177
- */
178
- static randomPast(max: Timespan=Timespan.years(1), base: Unixtime=Unixtime.now()): Unixtime {
179
- return base.addSeconds(Math.random()*max.seconds*-1)
180
- }
181
-
182
- /**
183
- * @param max maximum timespan to add
184
- * @returns returns random time in the future within given timespan
185
- */
186
- static randomFuture(max: Timespan=Timespan.years(1), base: Unixtime=Unixtime.now()): Unixtime {
187
- return base.addSeconds(Math.random()*max.seconds)
188
- }
189
-
190
- static fromYYYYMMDD(value: string): Unixtime {
191
- if (value.length != 8) throw new Error('Invalid yyyymmdd value')
192
- let year = parseInt(value.substring(0, 4))
193
- let month = parseInt(value.substring(4, 6)) - 1
194
- let day = parseInt(value.substring(6, 8))
195
- if (isNaN(year) || isNaN(month) || isNaN(day)) throw new Error('Invalid yyyymmdd value')
196
- if (month < 0 || month > 11) throw new Error('Invalid month')
197
- if (day < 1 || day > 31) throw new Error('Invalid day')
198
- return new Unixtime(new Date(Date.UTC(year, month, day)))
199
- }
200
-
201
- static try(value: Date | string | number): Unixtime | null {
202
- try {
203
- return new Unixtime(value)
204
- } catch (e) {
205
- return null
206
- }
207
- }
208
- }
package/ts/types.ts DELETED
@@ -1,42 +0,0 @@
1
- export type UnixtimeShort = number
2
-
3
- //#region mybase
4
- export type MysqlConfig = {
5
- host: string
6
- port?: number
7
- login: string
8
- password: string
9
- db: string
10
- }
11
-
12
- export type MysqlConnection = {
13
- connect: (callback: (err: NodeJS.ErrnoException | null) => void) => void
14
- ping: (callback: (err?: NodeJS.ErrnoException | Error | null) => void) => void
15
- }
16
-
17
- export type MysqlConnector = {
18
- createConnection: (opts: {
19
- host: string
20
- port: number
21
- user: string
22
- password: string
23
- database: string
24
- }) => MysqlConnection
25
- }
26
-
27
- export type VaultClient = {
28
- endpoint?: string
29
- read: (key: string) => Promise<{ data?: unknown }>
30
- }
31
-
32
- export type SqlQueryable = {
33
- query: (q: string, values: unknown[], callback: (err: Error | null, res?: unknown) => void) => void
34
- }
35
-
36
- export type Geoip2PathMap = {
37
- country: string | false
38
- city: string | false
39
- isp: string | false
40
- ct: string | false
41
- }
42
- //#endregion
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": true,
5
- "allowJs": true,
6
- "types": ["jest", "node"],
7
- "noImplicitAny": false
8
- },
9
- "include": ["**/*.test.ts", "mybase.ts", "ts/**/*.ts"],
10
- "exclude": ["node_modules"]
11
- }
package/tsconfig.json DELETED
@@ -1,37 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // "ignoreDeprecations": "6.0",
4
- "target": "es2017",
5
- "experimentalDecorators": true,
6
- "emitDecoratorMetadata": true,
7
- "module": "commonjs",
8
- "moduleResolution" : "Node",
9
- "esModuleInterop": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "strict": true,
12
- "declaration": true, // Generates corresponding .d.ts file
13
- "noImplicitReturns": true, // Report error when not all code paths in function return a value
14
- "noUnusedLocals": true, // Report errors on unused locals
15
- // "noUnusedParameters": true, // Report errors on unused parameters
16
- "noFallthroughCasesInSwitch": true, // Report errors for fallthrough cases in switch statement
17
- // "noUncheckedIndexedAccess": true, // Include 'undefined' in index signature results
18
- "noImplicitAny": true, // Raise error on expressions and declarations with an implied 'any' type
19
- "strictNullChecks": true, // Enable strict null checking
20
- "strictFunctionTypes": true, // Ensure function parameter types match
21
- "strictBindCallApply": true, // Ensure 'bind', 'call', and 'apply' methods match function types
22
- "strictPropertyInitialization": true, // Ensure non-undefined class properties are initialized in the constructor
23
- "alwaysStrict": true, // Parse in strict mode and emit "use strict" for each source file
24
- "sourceMap": true,
25
- "skipLibCheck": true,
26
- "baseUrl": ".",
27
- "paths": {
28
- "@root/*": ["./*"],
29
- "@models/*": ["./models/*"],
30
- "@inc/*": ["./inc/ts/*"]
31
- },
32
- "typeRoots": ["./node_modules/@types", "./types/"]
33
- },
34
- "exclude": [
35
- "**/*.test.ts"
36
- ]
37
- }
@@ -1,21 +0,0 @@
1
- declare module '@7c/validurl' {
2
- function validURL(host: unknown): boolean
3
- export = validURL
4
- }
5
-
6
- declare module 'ip6' {
7
- export function normalize(a: string): string
8
- export function abbreviate(a: string): string
9
- }
10
-
11
- declare module 'aes-js' {
12
- const aesjs: {
13
- utils: {
14
- utf8: { toBytes(s: string): Uint8Array; fromBytes(b: Uint8Array): string }
15
- hex: { fromBytes(b: Uint8Array): string; toBytes(s: string): Uint8Array }
16
- }
17
- padding: { pkcs7: { pad(b: Uint8Array, n: number): Uint8Array; strip(b: Uint8Array): Uint8Array } }
18
- ModeOfOperation: { cbc: new (key: Uint8Array) => { encrypt(b: Uint8Array): Uint8Array; decrypt(b: Uint8Array): Uint8Array } }
19
- }
20
- export = aesjs
21
- }