@punks/backend-core 0.0.34 → 0.0.36

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.
@@ -1,4 +1,9 @@
1
+ export type TimeUnit = "years" | "months" | "days" | "hours" | "minutes" | "seconds" | "milliseconds";
1
2
  export declare const addTime: (date: Date, offset: {
2
3
  value: number;
3
- unit: "years" | "months" | "days" | "hours" | "minutes" | "seconds";
4
+ unit: TimeUnit;
5
+ }) => Date;
6
+ export declare const subtractTime: (date: Date, offset: {
7
+ value: number;
8
+ unit: TimeUnit;
4
9
  }) => Date;
@@ -1,5 +1,5 @@
1
1
  export * from "./array";
2
- export { addTime } from "./dates";
2
+ export { addTime, subtractTime, TimeUnit } from "./dates";
3
3
  export { CsvColumnDefinition as ColumnDefinition, CsvBuildOptions, csvBuild, csvParse, } from "./csv";
4
4
  export { getDirectoryFilePaths } from "./files";
5
5
  export { joinPath, splitPath, ensureDirectory, getDirectoryPath } from "./paths";
@@ -6,3 +6,4 @@ export declare const buildObject: <T>(...props: {
6
6
  key: string;
7
7
  value: any;
8
8
  }[]) => T;
9
+ export declare const mergeDeep: <T>(a: any, b: any) => T;
package/dist/esm/index.js CHANGED
@@ -136,9 +136,18 @@ const addTime = (date, offset) => {
136
136
  case "seconds":
137
137
  newDate.setSeconds(date.getSeconds() + value);
138
138
  break;
139
+ case "milliseconds":
140
+ newDate.setMilliseconds(date.getMilliseconds() + value);
141
+ break;
139
142
  }
140
143
  return newDate;
141
144
  };
145
+ const subtractTime = (date, offset) => {
146
+ return addTime(date, {
147
+ value: -offset.value,
148
+ unit: offset.unit,
149
+ });
150
+ };
142
151
 
143
152
  const DEFAULT_DELIMITER = ";";
144
153
  const splitRows = (data) => {
@@ -263,6 +272,21 @@ const buildObject = (...props) => {
263
272
  }
264
273
  return out;
265
274
  };
275
+ const mergeDeep = (a, b) => {
276
+ const c = { ...(a ?? {}) };
277
+ for (const key in b ?? {}) {
278
+ if (b.hasOwnProperty(key)) {
279
+ const value = b[key];
280
+ if (typeof value === "object" && !Array.isArray(value)) {
281
+ c[key] = mergeDeep(c[key] ?? {}, value);
282
+ }
283
+ else {
284
+ c[key] = value;
285
+ }
286
+ }
287
+ }
288
+ return c;
289
+ };
266
290
 
267
291
  const pluralize = (word) => {
268
292
  return word.endsWith("s") ? `${word}es` : `${word}s`;
@@ -28481,5 +28505,5 @@ Log.enabled = true;
28481
28505
  Log.level = LogLevel.Debug;
28482
28506
  Log.metaSerialization = MetaSerializationType.None;
28483
28507
 
28484
- export { ExcelKeyTransform, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, mapOrThrow, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
28508
+ export { ExcelKeyTransform, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, mapOrThrow, mergeDeep, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, subtractTime, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
28485
28509
  //# sourceMappingURL=index.js.map