@bgord/tools 0.1.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/rounding.service.d.ts +17 -0
- package/dist/rounding.service.js +26 -0
- package/package.json +32 -0
- package/src/index.ts +1 -0
- package/src/rounding.service.ts +31 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./rounding.service";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./rounding.service";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare abstract class RoundingStrategy {
|
|
2
|
+
abstract round(value: number): number;
|
|
3
|
+
}
|
|
4
|
+
export declare class RoundToNearest extends RoundingStrategy {
|
|
5
|
+
round(value: number): number;
|
|
6
|
+
}
|
|
7
|
+
export declare class RoundUp extends RoundingStrategy {
|
|
8
|
+
round(value: number): number;
|
|
9
|
+
}
|
|
10
|
+
export declare class RoundDown extends RoundingStrategy {
|
|
11
|
+
round(value: number): number;
|
|
12
|
+
}
|
|
13
|
+
export declare class RoundToDecimal extends RoundingStrategy {
|
|
14
|
+
private readonly decimals;
|
|
15
|
+
constructor(decimals: number);
|
|
16
|
+
round(value: number): number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class RoundingStrategy {
|
|
2
|
+
}
|
|
3
|
+
export class RoundToNearest extends RoundingStrategy {
|
|
4
|
+
round(value) {
|
|
5
|
+
return Math.round(value);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class RoundUp extends RoundingStrategy {
|
|
9
|
+
round(value) {
|
|
10
|
+
return Math.ceil(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class RoundDown extends RoundingStrategy {
|
|
14
|
+
round(value) {
|
|
15
|
+
return Math.floor(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class RoundToDecimal extends RoundingStrategy {
|
|
19
|
+
constructor(decimals) {
|
|
20
|
+
super();
|
|
21
|
+
this.decimals = decimals;
|
|
22
|
+
}
|
|
23
|
+
round(value) {
|
|
24
|
+
return Number.parseFloat(value.toFixed(this.decimals));
|
|
25
|
+
}
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bgord/tools",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Bartosz Gordon",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist", "src"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc --build",
|
|
18
|
+
"preinstall": "bunx only-allow bun"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@biomejs/biome": "1.9.4",
|
|
22
|
+
"@commitlint/cli": "19.8.1",
|
|
23
|
+
"@commitlint/config-conventional": "19.8.1",
|
|
24
|
+
"cspell": "9.0.2",
|
|
25
|
+
"lefthook": "1.11.4",
|
|
26
|
+
"only-allow": "1.2.1",
|
|
27
|
+
"shellcheck": "3.1.0",
|
|
28
|
+
"typescript": "5.8.3",
|
|
29
|
+
"vitest": "3.1.4"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false
|
|
32
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./rounding.service";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export abstract class RoundingStrategy {
|
|
2
|
+
abstract round(value: number): number;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export class RoundToNearest extends RoundingStrategy {
|
|
6
|
+
round(value: number): number {
|
|
7
|
+
return Math.round(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class RoundUp extends RoundingStrategy {
|
|
12
|
+
round(value: number): number {
|
|
13
|
+
return Math.ceil(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class RoundDown extends RoundingStrategy {
|
|
18
|
+
round(value: number): number {
|
|
19
|
+
return Math.floor(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class RoundToDecimal extends RoundingStrategy {
|
|
24
|
+
constructor(private readonly decimals: number) {
|
|
25
|
+
super();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
round(value: number): number {
|
|
29
|
+
return Number.parseFloat(value.toFixed(this.decimals));
|
|
30
|
+
}
|
|
31
|
+
}
|