typeshi 1.6.0 → 1.7.2

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.
@@ -176,19 +176,4 @@ export declare function existingPathArgument(source: string, arg2: string | {
176
176
  * @returns **`bracketedString`** `string`
177
177
  */
178
178
  export declare const bracketed: (s: string) => string;
179
- declare const validate: {
180
- stringArgument: typeof stringArgument;
181
- multipleStringArguments: typeof multipleStringArguments;
182
- numericStringArgument: typeof numericStringArgument;
183
- booleanArgument: typeof booleanArgument;
184
- numberArgument: typeof numberArgument;
185
- arrayArgument: typeof arrayArgument;
186
- enumArgument: typeof enumArgument;
187
- objectArgument: typeof objectArgument;
188
- functionArgument: typeof functionArgument;
189
- existingPathArgument: typeof existingPathArgument;
190
- existingDirectoryArgument: typeof existingDirectoryArgument;
191
- existingFileArgument: typeof existingFileArgument;
192
- multipleExistingFileArguments: typeof multipleExistingFileArguments;
193
- };
194
- export default validate;
179
+ export {};
@@ -813,19 +813,19 @@ function getSourceString(fileName, func, funcInfo, startLine, endLine) {
813
813
  // isEnumArgumentOptions,
814
814
  // isEnumObject,
815
815
  // isObjectArgumentOptions,
816
- const validate = {
817
- stringArgument,
818
- multipleStringArguments,
819
- numericStringArgument,
820
- booleanArgument,
821
- numberArgument,
822
- arrayArgument,
823
- enumArgument,
824
- objectArgument,
825
- functionArgument,
826
- existingPathArgument,
827
- existingDirectoryArgument,
828
- existingFileArgument,
829
- multipleExistingFileArguments
830
- };
831
- exports.default = validate;
816
+ // const validate = {
817
+ // stringArgument,
818
+ // multipleStringArguments,
819
+ // numericStringArgument,
820
+ // booleanArgument,
821
+ // numberArgument,
822
+ // arrayArgument,
823
+ // enumArgument,
824
+ // objectArgument,
825
+ // functionArgument,
826
+ // existingPathArgument,
827
+ // existingDirectoryArgument,
828
+ // existingFileArgument,
829
+ // multipleExistingFileArguments
830
+ // }
831
+ // export default validate;
@@ -95,25 +95,33 @@ export declare function getCurrentPacificTime(): string;
95
95
  */
96
96
  export declare function toPacificTime(initialDateString: string): string;
97
97
  export declare const Milliseconds: {
98
- from: {
99
- hours: (n: number) => number;
100
- minutes: (n: number) => number;
101
- seconds: (n: number) => number;
98
+ readonly from: {
99
+ readonly hours: (n: number) => number;
100
+ readonly minutes: (n: number) => number;
101
+ readonly seconds: (n: number) => number;
102
102
  /**
103
103
  * @param d `Date` object
104
104
  * @returns `number` milliseconds since epoch
105
105
  */
106
- date: (d: Date) => number;
106
+ readonly date: (d: Date) => number;
107
+ readonly localeString: (s: string) => number | null;
107
108
  };
108
- to: {
109
- hours: (n: number) => number;
110
- minutes: (n: number) => number;
111
- seconds: (n: number) => number;
109
+ readonly to: {
110
+ readonly hours: (n: number) => number;
111
+ readonly minutes: (n: number) => number;
112
+ readonly seconds: (n: number) => number;
112
113
  /**
113
114
  * interprets `n` as milliseconds since epoch
114
115
  * @param n `number` milliseconds
115
116
  * @returns `Date` object
116
117
  */
117
- date: (n: number) => Date;
118
+ readonly date: (n: number) => Date;
119
+ /**
120
+ * @param n `number` milliseconds since epoch
121
+ * @param locale `string` default = `'en-US'`
122
+ * @param timeZone `string` default = `'America/Los_Angeles'`
123
+ * @returns `string` locale date string
124
+ */
125
+ readonly localeString: (n: number, locale?: string, timeZone?: string) => string;
118
126
  };
119
127
  };
@@ -217,6 +217,16 @@ exports.Milliseconds = {
217
217
  */
218
218
  date: (d) => {
219
219
  return d.getTime();
220
+ },
221
+ localeString: (s) => {
222
+ try {
223
+ const date = parseLocaleStringToDate(s);
224
+ return date.getTime();
225
+ }
226
+ catch (error) {
227
+ console.error(error);
228
+ return null;
229
+ }
220
230
  }
221
231
  },
222
232
  to: {
@@ -236,6 +246,16 @@ exports.Milliseconds = {
236
246
  */
237
247
  date: (n) => {
238
248
  return new Date(n);
249
+ },
250
+ /**
251
+ * @param n `number` milliseconds since epoch
252
+ * @param locale `string` default = `'en-US'`
253
+ * @param timeZone `string` default = `'America/Los_Angeles'`
254
+ * @returns `string` locale date string
255
+ */
256
+ localeString: (n, locale = exports.DEFAULT_LOCALE, timeZone = exports.DEFAULT_TIMEZONE) => {
257
+ const date = new Date(n);
258
+ return date.toLocaleString(locale, { timeZone });
239
259
  }
240
260
  },
241
261
  };
@@ -70,13 +70,11 @@ const stream_1 = require("stream");
70
70
  const csv_parser_1 = __importDefault(require("csv-parser"));
71
71
  const xlsx_1 = __importDefault(require("xlsx"));
72
72
  const regex_1 = require("../regex");
73
- const misc_1 = require("../regex/misc");
74
73
  const config_1 = require("../../config");
75
74
  const types_1 = require("./types");
76
75
  const typeValidation_1 = require("../typeValidation");
77
76
  const validate = __importStar(require("../argumentValidation"));
78
77
  const logging_1 = require("./logging");
79
- const F = (0, misc_1.extractFileName)(__filename);
80
78
  /** for testing if `pathString (value)` points to an existing directory */
81
79
  function isDirectory(value) {
82
80
  return ((0, typeValidation_1.isNonEmptyString)(value)
@@ -119,7 +117,7 @@ exports.readJsonSync = readJsonFileAsObject;
119
117
  * - JSON data as an object
120
118
  */
121
119
  function readJsonFileAsObject(filePath) {
122
- const source = (0, logging_1.getSourceString)(F, readJsonFileAsObject.name);
120
+ const source = (0, logging_1.getSourceString)(__filename, readJsonFileAsObject.name);
123
121
  try {
124
122
  filePath = coerceFileExtension(filePath, 'json');
125
123
  const data = fs_1.default.readFileSync(filePath, 'utf8');
@@ -140,7 +138,7 @@ function readJsonFileAsObject(filePath) {
140
138
  * @returns **`validatedFilePath`** `string`
141
139
  */
142
140
  function coerceFileExtension(filePath, expectedExtension) {
143
- validate.multipleStringArguments(`reading.coerceFileExtension`, { filePath, expectedExtension });
141
+ validate.multipleStringArguments((0, logging_1.getSourceString)(__filename, coerceFileExtension.name), { filePath, expectedExtension });
144
142
  expectedExtension = expectedExtension.replace(/\./, '');
145
143
  if (filePath.endsWith(`.${expectedExtension}`)) {
146
144
  return filePath;
@@ -165,7 +163,7 @@ function coerceFileExtension(filePath, expectedExtension) {
165
163
  * @returns **`concatenatedRows`** `Promise<Record<string, any>[]>`
166
164
  */
167
165
  async function concatenateFiles(arg1, sheetName = 'Sheet1', requiredHeaders = [], strictRequirement = true, targetExtensions = ['.csv', '.tsv', '.xlsx']) {
168
- const source = (0, logging_1.getSourceString)(F, concatenateFiles.name);
166
+ const source = (0, logging_1.getSourceString)(__filename, concatenateFiles.name);
169
167
  validate.stringArgument(source, { sheetName });
170
168
  validate.arrayArgument(source, { targetExtensions, isNonEmptyString: typeValidation_1.isNonEmptyString });
171
169
  let files;
@@ -433,7 +431,7 @@ async function getOneToOneDictionary(arg1, keyColumn, valueColumn, keyOptions, v
433
431
  * @returns **`values`** `Promise<Array<string>>` - sorted array of values (as strings) from the specified column.
434
432
  */
435
433
  async function getColumnValues(arg1, columnName, cleaner, allowDuplicates = false) {
436
- const source = `[reading.getColumnValues()]`;
434
+ const source = (0, logging_1.getSourceString)(__filename, getColumnValues.name);
437
435
  validate.stringArgument(source, { columnName });
438
436
  validate.booleanArgument(source, { allowDuplicates });
439
437
  if (cleaner)
@@ -485,7 +483,7 @@ async function getIndexedColumnValues(arg1, columnName, cleaner) {
485
483
  * @returns **`rows`** `Promise<Record<string, any>[]>`
486
484
  */
487
485
  async function handleFileArgument(arg1, invocationSource, requiredHeaders = [], sheetName) {
488
- const source = (0, logging_1.getSourceString)(F, handleFileArgument.name);
486
+ const source = (0, logging_1.getSourceString)(__filename, handleFileArgument.name);
489
487
  validate.stringArgument(source, { invocationSource });
490
488
  validate.arrayArgument(source, { requiredHeaders, isNonEmptyString: typeValidation_1.isNonEmptyString }, true);
491
489
  let rows = [];
@@ -532,7 +530,7 @@ async function handleFileArgument(arg1, invocationSource, requiredHeaders = [],
532
530
  * @returns **`targetFiles`** `string[]` array of full file paths
533
531
  */
534
532
  function getDirectoryFiles(dir, ...targetExtensions) {
535
- const source = (0, logging_1.getSourceString)(F, getDirectoryFiles.name);
533
+ const source = (0, logging_1.getSourceString)(__filename, getDirectoryFiles.name);
536
534
  validate.existingPathArgument(source, { dir });
537
535
  validate.arrayArgument(source, { targetExtensions, isNonEmptyString: typeValidation_1.isNonEmptyString }, true);
538
536
  // ensure all target extensions start with period
@@ -557,7 +555,7 @@ function getDirectoryFiles(dir, ...targetExtensions) {
557
555
  * @returns **`dict`** `Promise<Record<string, string[]>>`
558
556
  */
559
557
  async function getOneToManyDictionary(dataSource, keyColumn, valueColumn, keyOptions, valueOptions, sheetName) {
560
- const source = (0, logging_1.getSourceString)(F, getOneToManyDictionary.name);
558
+ const source = (0, logging_1.getSourceString)(__filename, getOneToManyDictionary.name);
561
559
  validate.multipleStringArguments(source, { keyColumn, valueColumn });
562
560
  if (keyOptions)
563
561
  validate.objectArgument(source, { keyOptions, isCleanStringOptions: regex_1.isCleanStringOptions });
@@ -1130,7 +1128,7 @@ async function extractTargetRows(
1130
1128
  * - `Record<string, any>[]` -> array of rows
1131
1129
  * */
1132
1130
  rowSource, targetColumn, targetValues, extractor, extractorArgs) {
1133
- const source = (0, logging_1.getSourceString)(F, extractTargetRows.name);
1131
+ const source = (0, logging_1.getSourceString)(__filename, extractTargetRows.name);
1134
1132
  if (!(0, typeValidation_1.isNonEmptyString)(rowSource) && !(0, typeValidation_1.isNonEmptyArray)(rowSource)) {
1135
1133
  throw new Error([`${source} Invalid param 'rowSource'`,
1136
1134
  `Expected rowSource: string | Record<string, any>[]`,
@@ -29,7 +29,7 @@ export declare const writeJsonSync: typeof writeObjectToJsonSync;
29
29
  */
30
30
  export declare function indentedStringify(data: Record<string, any> | string, indent?: number, spaces?: number): string;
31
31
  /**
32
- * @returns **`timestamp`** `string` = `(${MM}-${DD})_(${HH}-${mm}.${ss}.${ms})`
32
+ * @returns **`timestamp`** `string` = `(${MM}-${DD})_(${HH}.${mm}.${ss}.${ms})`
33
33
  */
34
34
  export declare function getFileNameTimestamp(): string;
35
35
  /**
@@ -135,7 +135,7 @@ function indentedStringify(data, indent = 0, spaces = 4) {
135
135
  return jsonString;
136
136
  }
137
137
  /**
138
- * @returns **`timestamp`** `string` = `(${MM}-${DD})_(${HH}-${mm}.${ss}.${ms})`
138
+ * @returns **`timestamp`** `string` = `(${MM}-${DD})_(${HH}.${mm}.${ss}.${ms})`
139
139
  */
140
140
  function getFileNameTimestamp() {
141
141
  const now = new Date();
@@ -145,7 +145,7 @@ function getFileNameTimestamp() {
145
145
  const mm = String(now.getMinutes()).padStart(2, '0');
146
146
  const ss = String(now.getSeconds()).padStart(2, '0');
147
147
  const ms = String(now.getMilliseconds()).padStart(3, '0');
148
- return `(${MM}-${DD})_(${HH}-${mm}.${ss}.${ms})`;
148
+ return `(${MM}-${DD})_(${HH}.${mm}.${ss}.${ms})`;
149
149
  }
150
150
  /**
151
151
  * @param listData `Record<string, Array<string>>` map col names to col values
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeshi",
3
- "version": "1.6.0",
3
+ "version": "1.7.2",
4
4
  "description": "TypeScript utility modules",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",