nhb-toolbox 4.30.1 → 4.30.10

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/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  All notable changes to the package will be documented here.
6
6
 
7
+ ## [4.30.10] - 2026-05-16
8
+
9
+ - **Added** new *utility types*: `PropertyOptional<T, Keys>` and `PropertyRequired<T, Keys>`.
10
+ - **Fixed** *Chronos plugin method* `round()` not preserving the *metadata* of the *original* instance.
11
+
7
12
  ## [4.30.1] - 2026-04-27
8
13
 
9
14
  - **Updated** *random hex generation* logic in `randomHex` and `uuid` utilities to use `crypto.getRandomValues` for better performance and security when available, with a fallback to `Math.random` for environments where `crypto` is not available.
@@ -56,7 +56,7 @@ const roundPlugin = ($Chronos) => {
56
56
  const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
57
57
  const diffToEnd = Math.abs(endOfWeek.getTime() - date.getTime());
58
58
  const rounded = diffToEnd < diffToStart ? endOfWeek : startOfWeek;
59
- return withOrigin(new $Chronos(rounded), 'round');
59
+ return withOrigin(new $Chronos(rounded), 'round', offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
60
60
  }
61
61
  case 'month': {
62
62
  const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
@@ -317,6 +317,34 @@ export type RangeTuple<T, Min extends number, Max extends number> = $Range<Min,
317
317
  export type ValueOptional<O, K extends keyof O = keyof O> = {
318
318
  [P in keyof O]: P extends K ? O[P] | undefined : O[P];
319
319
  };
320
+ /**
321
+ * Makes selected properties optional while keeping the rest required
322
+ * @remarks By default all properties are optional, same as {@link Partial<T>}
323
+ *
324
+ * @example
325
+ * type A = { name: string; age: number };
326
+ * type B = PropertyOptional<A, 'name'>;
327
+ * // Equivalent to: { name?: string | undefined; age: number }
328
+ *
329
+ * @example
330
+ * type C = PropertyOptional<A>;
331
+ * // Equivalent to: { name?: string | undefined; age?: number | undefined }
332
+ */
333
+ export type PropertyOptional<O, K extends keyof O = keyof O> = Prettify<Omit<O, K> & Partial<Pick<O, K>>>;
334
+ /**
335
+ * Makes selected properties required while keeping the rest unchanged
336
+ * @remarks By default all properties are required, same as {@link Required<T>}
337
+ *
338
+ * @example
339
+ * type A = { name?: string; age: number };
340
+ * type B = PropertyRequired<A, 'name'>;
341
+ * // Equivalent to: { name: string; age: number | undefined }
342
+ *
343
+ * @example
344
+ * type C = PropertyRequired<A>;
345
+ * // Equivalent to: { name: string; age: number }
346
+ */
347
+ export type PropertyRequired<O, K extends keyof O = keyof O> = Prettify<Omit<O, K> & Required<Pick<O, K>>>;
320
348
  export type $Without<T, U> = {
321
349
  [P in Exclude<keyof T, keyof U>]?: never;
322
350
  };
@@ -53,7 +53,7 @@ export const roundPlugin = ($Chronos) => {
53
53
  const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
54
54
  const diffToEnd = Math.abs(endOfWeek.getTime() - date.getTime());
55
55
  const rounded = diffToEnd < diffToStart ? endOfWeek : startOfWeek;
56
- return withOrigin(new $Chronos(rounded), 'round');
56
+ return withOrigin(new $Chronos(rounded), 'round', offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
57
57
  }
58
58
  case 'month': {
59
59
  const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.30.1",
3
+ "version": "4.30.10",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -44,12 +44,12 @@
44
44
  },
45
45
  "license": "Apache-2.0",
46
46
  "devDependencies": {
47
- "@biomejs/biome": "^2.4.12",
47
+ "@biomejs/biome": "^2.4.15",
48
48
  "@types/jest": "^30.0.0",
49
- "@types/node": "^25.6.0",
49
+ "@types/node": "^25.8.0",
50
50
  "husky": "^9.1.7",
51
- "jest": "^30.3.0",
52
- "lint-staged": "^16.4.0",
51
+ "jest": "^30.4.2",
52
+ "lint-staged": "^17.0.4",
53
53
  "nhb-scripts": "^1.9.2",
54
54
  "ts-jest": "^29.4.9",
55
55
  "typescript": "^6.0.3"