@naturalcycles/nodejs-lib 13.24.0 → 13.25.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.
@@ -34,7 +34,7 @@ function csvStringParse(str, cfg = {}) {
34
34
  }
35
35
  exports.csvStringParse = csvStringParse;
36
36
  function csvStringToArray(str) {
37
- const objPattern = new RegExp('(,|\\r?\\n|\\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\\r\\n]*))', 'gi');
37
+ const objPattern = new RegExp(String.raw `(,|\r?\n|\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\r\n]*))`, 'gi');
38
38
  let matches;
39
39
  const arr = [[]];
40
40
  while ((matches = objPattern.exec(str))) {
@@ -130,7 +130,7 @@ class SlackService {
130
130
  }
131
131
  exports.SlackService = SlackService;
132
132
  function slackDefaultMessagePrefixHook(msg) {
133
- const tokens = [(0, js_lib_1.localTimeNow)().toPretty()];
133
+ const tokens = [js_lib_1.localTime.now().toPretty()];
134
134
  const { ctx } = msg;
135
135
  // AppEngine-specific decoration
136
136
  if (GAE && ctx && typeof ctx === 'object' && typeof ctx.header === 'function') {
@@ -103,7 +103,7 @@ class ProgressLogger {
103
103
  if (perHour > 900) {
104
104
  perHour = Math.round(perHour / 1000) + 'K';
105
105
  }
106
- logger.log(`${(0, colors_1.dimGrey)((0, js_lib_1.localTimeNow)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(this.started))} so far to process ${(0, colors_1.yellow)(batchedProgress)} rows, ~${(0, colors_1.yellow)(perHour)}/hour`);
106
+ logger.log(`${(0, colors_1.dimGrey)(js_lib_1.localTime.now().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(this.started))} so far to process ${(0, colors_1.yellow)(batchedProgress)} rows, ~${(0, colors_1.yellow)(perHour)}/hour`);
107
107
  }
108
108
  else if (final) {
109
109
  logger.log(`${(0, colors_1.boldWhite)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(this.started))} to process ${(0, colors_1.yellow)(batchedProgress)} rows with total RPS of ${(0, colors_1.yellow)(rpsTotal)}`);
@@ -5,7 +5,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const fs2_1 = require("../fs/fs2");
6
6
  const git_util_1 = require("./git.util");
7
7
  function generateBuildInfo(opt = {}) {
8
- const now = (0, js_lib_1.localTimeOrNow)(opt.overrideTimestamp);
8
+ const now = js_lib_1.localTime.orNow(opt.overrideTimestamp);
9
9
  const ts = now.unix();
10
10
  const rev = (0, git_util_1.gitCurrentCommitSha)();
11
11
  const branchName = (0, git_util_1.gitCurrentBranchName)();
@@ -91,5 +91,6 @@ export declare const SEM_VER_REGEX: RegExp;
91
91
  export declare const semVerSchema: StringSchema<string>;
92
92
  export declare const userAgentSchema: StringSchema<string>;
93
93
  export declare const utcOffsetSchema: NumberSchema<number>;
94
+ export declare const ianaTimezoneSchema: StringSchema<string>;
94
95
  export declare const ipAddressSchema: StringSchema<string>;
95
96
  export declare const baseDBEntitySchema: ObjectSchema<BaseDBEntity>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
3
+ exports.baseDBEntitySchema = exports.ipAddressSchema = exports.ianaTimezoneSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const joi_extensions_1 = require("./joi.extensions");
6
6
  exports.booleanSchema = joi_extensions_1.Joi.boolean();
@@ -124,6 +124,11 @@ exports.utcOffsetSchema = exports.numberSchema
124
124
  .min(-14 * 60)
125
125
  .max(14 * 60)
126
126
  .dividable(15);
127
+ exports.ianaTimezoneSchema = exports.stringSchema
128
+ .valid(...Intl.supportedValuesOf('timeZone'))
129
+ .messages({
130
+ 'any.only': `must be a valid IANA timezone string`,
131
+ });
127
132
  exports.ipAddressSchema = exports.stringSchema.ip();
128
133
  exports.baseDBEntitySchema = objectSchema({
129
134
  id: exports.stringSchema.optional(),
@@ -95,7 +95,7 @@ function getTodayStrPlus15() {
95
95
  return todayStrPlusCached;
96
96
  }
97
97
  lastCheckedPlus = now;
98
- return (todayStrPlusCached = (0, js_lib_1.localTimeNow)().plus(15, 'hour').toISODate());
98
+ return (todayStrPlusCached = js_lib_1.localTime.now().plus(15, 'hour').toISODate());
99
99
  }
100
100
  function getTodayStrMinus15() {
101
101
  const now = Date.now();
@@ -104,5 +104,5 @@ function getTodayStrMinus15() {
104
104
  return todayStrMinusCached;
105
105
  }
106
106
  lastCheckedMinus = now;
107
- return (todayStrMinusCached = (0, js_lib_1.localTimeNow)().plus(-15, 'hour').toISODate());
107
+ return (todayStrMinusCached = js_lib_1.localTime.now().plus(-15, 'hour').toISODate());
108
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.24.0",
3
+ "version": "13.25.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "docs-serve": "vuepress dev docs",
@@ -34,7 +34,7 @@
34
34
  "yargs": "^17.0.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@naturalcycles/bench-lib": "^2.0.0",
37
+ "@naturalcycles/bench-lib": "^3.0.0",
38
38
  "@naturalcycles/dev-lib": "^13.0.0",
39
39
  "@types/node": "^20.1.0",
40
40
  "@types/yargs": "^16.0.0",
@@ -56,7 +56,10 @@ export function csvStringParse<T extends AnyObject = any>(
56
56
  }
57
57
 
58
58
  export function csvStringToArray(str: string): string[][] {
59
- const objPattern = new RegExp('(,|\\r?\\n|\\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\\r\\n]*))', 'gi')
59
+ const objPattern = new RegExp(
60
+ String.raw`(,|\r?\n|\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\r\n]*))`,
61
+ 'gi',
62
+ )
60
63
  let matches: RegExpExecArray | null
61
64
  const arr: any[][] = [[]]
62
65
 
@@ -6,7 +6,7 @@ import {
6
6
  CommonLogLevel,
7
7
  Fetcher,
8
8
  getFetcher,
9
- localTimeNow,
9
+ localTime,
10
10
  PQueue,
11
11
  } from '@naturalcycles/js-lib'
12
12
  import { _inspect, InspectAnyOptions } from '..'
@@ -180,7 +180,7 @@ export class SlackService<CTX = any> {
180
180
  }
181
181
 
182
182
  export function slackDefaultMessagePrefixHook(msg: SlackMessage): string[] {
183
- const tokens = [localTimeNow().toPretty()]
183
+ const tokens = [localTime.now().toPretty()]
184
184
  const { ctx } = msg
185
185
 
186
186
  // AppEngine-specific decoration
@@ -4,7 +4,7 @@ import {
4
4
  _since,
5
5
  AnyObject,
6
6
  CommonLogger,
7
- localTimeNow,
7
+ localTime,
8
8
  SimpleMovingAverage,
9
9
  UnixTimestampMillisNumber,
10
10
  } from '@naturalcycles/js-lib'
@@ -294,7 +294,7 @@ export class ProgressLogger<T> implements Disposable {
294
294
  }
295
295
 
296
296
  logger.log(
297
- `${dimGrey(localTimeNow().toPretty())} ${white(metric)} took ${yellow(
297
+ `${dimGrey(localTime.now().toPretty())} ${white(metric)} took ${yellow(
298
298
  _since(this.started),
299
299
  )} so far to process ${yellow(batchedProgress)} rows, ~${yellow(perHour)}/hour`,
300
300
  )
@@ -2,7 +2,7 @@ import {
2
2
  _filterUndefinedValues,
3
3
  AnyObject,
4
4
  BuildInfo,
5
- localTimeOrNow,
5
+ localTime,
6
6
  UnixTimestampNumber,
7
7
  } from '@naturalcycles/js-lib'
8
8
  import { fs2 } from '../fs/fs2'
@@ -21,7 +21,7 @@ export interface GenerateBuildInfoOptions {
21
21
  }
22
22
 
23
23
  export function generateBuildInfo(opt: GenerateBuildInfoOptions = {}): BuildInfo {
24
- const now = localTimeOrNow(opt.overrideTimestamp)
24
+ const now = localTime.orNow(opt.overrideTimestamp)
25
25
  const ts = now.unix()
26
26
 
27
27
  const rev = gitCurrentCommitSha()
@@ -156,6 +156,12 @@ export const utcOffsetSchema = numberSchema
156
156
  .max(14 * 60)
157
157
  .dividable(15)
158
158
 
159
+ export const ianaTimezoneSchema = stringSchema
160
+ .valid(...Intl.supportedValuesOf('timeZone'))
161
+ .messages({
162
+ 'any.only': `must be a valid IANA timezone string`,
163
+ })
164
+
159
165
  export const ipAddressSchema = stringSchema.ip()
160
166
 
161
167
  export const baseDBEntitySchema: ObjectSchema<BaseDBEntity> = objectSchema<BaseDBEntity>({
@@ -1,4 +1,4 @@
1
- import { localTimeNow } from '@naturalcycles/js-lib'
1
+ import { localTime } from '@naturalcycles/js-lib'
2
2
  import Joi, { Extension, StringSchema as JoiStringSchema } from 'joi'
3
3
 
4
4
  export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
@@ -111,7 +111,7 @@ function getTodayStrPlus15(): string {
111
111
  }
112
112
 
113
113
  lastCheckedPlus = now
114
- return (todayStrPlusCached = localTimeNow().plus(15, 'hour').toISODate())
114
+ return (todayStrPlusCached = localTime.now().plus(15, 'hour').toISODate())
115
115
  }
116
116
 
117
117
  function getTodayStrMinus15(): string {
@@ -122,5 +122,5 @@ function getTodayStrMinus15(): string {
122
122
  }
123
123
 
124
124
  lastCheckedMinus = now
125
- return (todayStrMinusCached = localTimeNow().plus(-15, 'hour').toISODate())
125
+ return (todayStrMinusCached = localTime.now().plus(-15, 'hour').toISODate())
126
126
  }