@swissgeo/numbers 1.0.0-rc.1 → 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.
- package/README.md +89 -0
- package/package.json +11 -11
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
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Numbers utils for SWISSGEO projects.",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
@@ -15,19 +15,19 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@swissgeo/log": "1.0.0
|
|
18
|
+
"@swissgeo/log": "1.0.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@microsoft/api-extractor": "^7.55.
|
|
21
|
+
"@microsoft/api-extractor": "^7.55.2",
|
|
22
22
|
"@types/chai": "^5.2.3",
|
|
23
|
-
"chai": "^6.2.
|
|
24
|
-
"eslint": "^9.39.
|
|
23
|
+
"chai": "^6.2.2",
|
|
24
|
+
"eslint": "^9.39.2",
|
|
25
25
|
"typescript": "^5.9.3",
|
|
26
26
|
"unplugin-dts": "1.0.0-beta.6",
|
|
27
|
-
"vite": "
|
|
28
|
-
"vitest": "^4.0.
|
|
29
|
-
"@swissgeo/config-eslint": "1.0.0
|
|
30
|
-
"@swissgeo/config-typescript": "1.0.0
|
|
27
|
+
"vite": "7.2.2",
|
|
28
|
+
"vitest": "^4.0.16",
|
|
29
|
+
"@swissgeo/config-eslint": "1.0.0",
|
|
30
|
+
"@swissgeo/config-typescript": "1.0.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "pnpm run type-check && pnpm run generate-types && vite build",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"generate-types": "tsc --declaration",
|
|
40
40
|
"lint": "eslint --fix",
|
|
41
41
|
"lint:no-fix": "eslint",
|
|
42
|
-
"test:unit": "vitest
|
|
43
|
-
"test:unit:watch": "vitest
|
|
42
|
+
"test:unit": "vitest run",
|
|
43
|
+
"test:unit:watch": "vitest watch",
|
|
44
44
|
"type-check": "tsc -p tsconfig.json"
|
|
45
45
|
}
|
|
46
46
|
}
|