@swissgeo/numbers 1.0.0-beta.2 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +89 -0
  2. package/package.json +11 -17
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @swissgeo/numbers
2
+
3
+ Number manipulation and formatting utilities for SWISSGEO projects.
4
+
5
+ ## Overview
6
+
7
+ This package provides a collection of utility functions for working with numbers, including rounding, formatting with Swiss locale, calculating circular means, and other common mathematical operations used within the SWISSGEO ecosystem.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @swissgeo/numbers
13
+ ```
14
+
15
+ ## Features
16
+
17
+ - **Rounding & Comparison**: `round`, `closest`, `isNumber`.
18
+ - **Formatting**: `format` (Swiss locale), `formatThousand` with custom separators.
19
+ - **Math & Utilities**: `randomIntBetween`, `wrapDegrees`, `circularMean`.
20
+ - **Validation**: `isTimestampYYYYMMDD`.
21
+
22
+ ## Usage
23
+
24
+ ### Basic Usage
25
+
26
+ The default export provides access to all utility functions.
27
+
28
+ ```typescript
29
+ import { round, isNumber } from '@swissgeo/numbers'
30
+
31
+ const rounded = round(1.2345, 2) // 1.23
32
+ const isNum = isNumber('123') // true
33
+ ```
34
+
35
+ ### Rounding and Closest Value
36
+
37
+ ```typescript
38
+ import { round, closest } from '@swissgeo/numbers'
39
+
40
+ // Rounding to 2 decimal places
41
+ round(10.556, 2) // 10.56
42
+
43
+ // Finding the closest value in a list
44
+ closest(15, [10, 20, 30]) // 20
45
+ ```
46
+
47
+ ### Formatting
48
+
49
+ The `format` function uses the `de-CH` locale convention (using `'` as a thousands separator).
50
+
51
+ ```typescript
52
+ import { format, formatThousand } from '@swissgeo/numbers'
53
+
54
+ // Swiss formatting (thousands separator is ')
55
+ format(1234.567) // "1'234.57"
56
+
57
+ // Custom thousand separator
58
+ formatThousand(1000000, ' ') // "1 000 000"
59
+ ```
60
+
61
+ ### Circular Mean and Degrees
62
+
63
+ Useful for handling angles and rotations.
64
+
65
+ ```typescript
66
+ import { wrapDegrees, circularMean } from '@swissgeo/numbers'
67
+
68
+ // Wrap angle to [-360, 360] range
69
+ wrapDegrees(370) // 10
70
+
71
+ // Compute circular mean of radians
72
+ circularMean([0, Math.PI / 2]) // 0.785398... (Math.PI / 4)
73
+ ```
74
+
75
+ ### Random Integers
76
+
77
+ ```typescript
78
+ import { randomIntBetween } from '@swissgeo/numbers'
79
+
80
+ const random = randomIntBetween(1, 10) // Random integer between 1 and 10 (inclusive)
81
+ ```
82
+
83
+ ## License
84
+
85
+ BSD-3-Clause
86
+
87
+ ## Repository
88
+
89
+ [https://github.com/geoadmin/web-mapviewer](https://github.com/geoadmin/web-mapviewer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swissgeo/numbers",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0",
4
4
  "description": "Numbers utils for SWISSGEO projects.",
5
5
  "license": "BSD-3-Clause",
6
6
  "type": "module",
@@ -15,25 +15,19 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@swissgeo/log": "1.0.0-beta.2"
18
+ "@swissgeo/log": "1.0.0"
19
19
  },
20
20
  "devDependencies": {
21
- "@microsoft/api-extractor": "^7.55.0",
22
- "@prettier/plugin-xml": "^3.4.2",
21
+ "@microsoft/api-extractor": "^7.55.2",
23
22
  "@types/chai": "^5.2.3",
24
- "chai": "^6.2.1",
25
- "eslint": "^9.39.1",
26
- "prettier": "^3.6.2",
27
- "prettier-plugin-jsdoc": "^1.5.0",
28
- "prettier-plugin-packagejson": "^2.5.19",
29
- "prettier-plugin-tailwindcss": "^0.7.1",
23
+ "chai": "^6.2.2",
24
+ "eslint": "^9.39.2",
30
25
  "typescript": "^5.9.3",
31
26
  "unplugin-dts": "1.0.0-beta.6",
32
- "vite": "^7.2.2",
33
- "vitest": "^4.0.8",
34
- "@swissgeo/config-eslint": "1.0.0-beta.2",
35
- "@swissgeo/config-typescript": "1.0.0-beta.2",
36
- "@swissgeo/config-prettier": "1.0.0-beta.2"
27
+ "vite": "7.2.2",
28
+ "vitest": "^4.0.16",
29
+ "@swissgeo/config-eslint": "1.0.0",
30
+ "@swissgeo/config-typescript": "1.0.0"
37
31
  },
38
32
  "scripts": {
39
33
  "build": "pnpm run type-check && pnpm run generate-types && vite build",
@@ -45,8 +39,8 @@
45
39
  "generate-types": "tsc --declaration",
46
40
  "lint": "eslint --fix",
47
41
  "lint:no-fix": "eslint",
48
- "test:unit": "vitest --run --mode development --environment jsdom",
49
- "test:unit:watch": "vitest --mode development --environment jsdom",
42
+ "test:unit": "vitest run",
43
+ "test:unit:watch": "vitest watch",
50
44
  "type-check": "tsc -p tsconfig.json"
51
45
  }
52
46
  }