@leancodepl/api-date-utils 8.4.0 → 8.5.1

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/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @leancodepl/api-date-utils
2
+
3
+ Utilities for parsing and working with API date types.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @leancodepl/api-date-utils
9
+ # or
10
+ yarn add @leancodepl/api-date-utils
11
+ ```
12
+
13
+ ## API
14
+
15
+ ### `parseApiTimeSpan(timespan)`
16
+
17
+ Parses ApiTimeSpan string into structured time components.
18
+
19
+ **Parameters:**
20
+
21
+ - `timespan: ApiTimeSpan` - The ApiTimeSpan string to parse
22
+
23
+ **Returns:** Object with sign and time component values
24
+
25
+ ## Usage Examples
26
+
27
+ ### Basic Parsing
28
+
29
+ ```typescript
30
+ import { parseApiTimeSpan } from "@leancodepl/api-date-utils"
31
+
32
+ const result = parseApiTimeSpan("1.23:45:67.890")
33
+ console.log(result.values.hours) // 23
34
+ console.log(result.values.days) // 1
35
+ console.log(result.sign) // undefined (positive)
36
+ ```
37
+
38
+ ### Negative TimeSpan
39
+
40
+ ```typescript
41
+ import { parseApiTimeSpan } from "@leancodepl/api-date-utils"
42
+
43
+ const result = parseApiTimeSpan("-2.10:30:45.123")
44
+ console.log(result.sign) // '-'
45
+ console.log(result.values.days) // 2
46
+ console.log(result.values.hours) // 10
47
+ console.log(result.values.minutes) // 30
48
+ console.log(result.values.milliseconds) // 123
49
+ ```
50
+
51
+ ### Duration Calculations
52
+
53
+ ```typescript
54
+ import { parseApiTimeSpan } from "@leancodepl/api-date-utils"
55
+
56
+ const calculateTotalMilliseconds = (timespan: ApiTimeSpan) => {
57
+ const parsed = parseApiTimeSpan(timespan)
58
+ const { days, hours, minutes, seconds, milliseconds } = parsed.values
59
+
60
+ const total = days * 86400000 + hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds
61
+
62
+ return parsed.sign === "-" ? -total : total
63
+ }
64
+ ```
package/index.cjs.js CHANGED
@@ -1,7 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  const parseIntMatched = (value)=>parseInt(value != null ? value : "0");
4
- function parseApiTimeSpan(timespan) {
4
+ /**
5
+ * Parses ApiTimeSpan string into structured time components.
6
+ *
7
+ * Extracts sign, days, hours, minutes, seconds, and milliseconds from
8
+ * ApiTimeSpan string format using regex pattern matching.
9
+ *
10
+ * @param timespan - The ApiTimeSpan string to parse
11
+ * @returns Object with sign and time component values
12
+ * @example
13
+ * ```typescript
14
+ * const result = parseApiTimeSpan('1.23:45:67.890');
15
+ * console.log(result.values.hours); // 23
16
+ * ```
17
+ */ function parseApiTimeSpan(timespan) {
5
18
  /**
6
19
  * This regex returns tuple of matched strings (either of string type or undefined) and default match function parameters
7
20
  * following [timeSpan, sign, days, hours, minutes, seconds, milliseconds, index of search at which the result was found, input (search string), groups] schema
package/index.esm.js CHANGED
@@ -1,5 +1,18 @@
1
1
  const parseIntMatched = (value)=>parseInt(value != null ? value : "0");
2
- function parseApiTimeSpan(timespan) {
2
+ /**
3
+ * Parses ApiTimeSpan string into structured time components.
4
+ *
5
+ * Extracts sign, days, hours, minutes, seconds, and milliseconds from
6
+ * ApiTimeSpan string format using regex pattern matching.
7
+ *
8
+ * @param timespan - The ApiTimeSpan string to parse
9
+ * @returns Object with sign and time component values
10
+ * @example
11
+ * ```typescript
12
+ * const result = parseApiTimeSpan('1.23:45:67.890');
13
+ * console.log(result.values.hours); // 23
14
+ * ```
15
+ */ function parseApiTimeSpan(timespan) {
3
16
  /**
4
17
  * This regex returns tuple of matched strings (either of string type or undefined) and default match function parameters
5
18
  * following [timeSpan, sign, days, hours, minutes, seconds, milliseconds, index of search at which the result was found, input (search string), groups] schema
package/package.json CHANGED
@@ -1,20 +1,52 @@
1
1
  {
2
2
  "name": "@leancodepl/api-date-utils",
3
- "version": "8.4.0",
3
+ "version": "8.5.1",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
- "@leancodepl/api-date": "8.4.0"
6
+ "@leancodepl/api-date": "8.5.1"
7
7
  },
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "registry": "https://registry.npmjs.org/"
11
+ },
12
+ "engines": {
13
+ "node": ">=18.0.0"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/leancodepl/js_corelibrary.git",
18
+ "directory": "packages/cqrs-clients/custom-types/date/api-date-utils"
19
+ },
20
+ "homepage": "https://github.com/leancodepl/js_corelibrary",
21
+ "bugs": {
22
+ "url": "https://github.com/leancodepl/js_corelibrary/issues"
23
+ },
24
+ "description": "Utility functions for API date parsing and validation",
25
+ "keywords": [
26
+ "date",
27
+ "parsing",
28
+ "validation",
29
+ "api",
30
+ "utilities",
31
+ "typescript",
32
+ "javascript",
33
+ "leancode"
34
+ ],
35
+ "author": {
36
+ "name": "LeanCode",
37
+ "url": "https://leancode.co"
38
+ },
39
+ "sideEffects": false,
8
40
  "exports": {
9
41
  "./package.json": "./package.json",
10
42
  ".": {
11
43
  "module": "./index.esm.js",
12
- "types": "./index.esm.d.ts",
44
+ "types": "./index.d.ts",
13
45
  "import": "./index.cjs.mjs",
14
46
  "default": "./index.cjs.js"
15
47
  }
16
48
  },
17
49
  "module": "./index.esm.js",
18
50
  "main": "./index.cjs.js",
19
- "types": "./index.esm.d.ts"
51
+ "types": "./index.d.ts"
20
52
  }
@@ -1,4 +1,18 @@
1
1
  import type { ApiTimeSpan } from "@leancodepl/api-date";
2
+ /**
3
+ * Parses ApiTimeSpan string into structured time components.
4
+ *
5
+ * Extracts sign, days, hours, minutes, seconds, and milliseconds from
6
+ * ApiTimeSpan string format using regex pattern matching.
7
+ *
8
+ * @param timespan - The ApiTimeSpan string to parse
9
+ * @returns Object with sign and time component values
10
+ * @example
11
+ * ```typescript
12
+ * const result = parseApiTimeSpan('1.23:45:67.890');
13
+ * console.log(result.values.hours); // 23
14
+ * ```
15
+ */
2
16
  export declare function parseApiTimeSpan(timespan: ApiTimeSpan): {
3
17
  sign: any;
4
18
  values: {
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
File without changes