calqulate 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/LICENSE +25 -0
- package/README.md +105 -0
- package/calculus/derivative.js +5 -0
- package/calculus/integrate.js +11 -0
- package/fp/compose.js +5 -0
- package/fp/curry.js +9 -0
- package/fp/filterAsync.js +6 -0
- package/fp/mapAsync.js +5 -0
- package/geometry/distance.js +5 -0
- package/geometry/polygonArea.js +10 -0
- package/geometry/rotatePoint.js +8 -0
- package/index.d.ts +16 -0
- package/index.js +31 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
<<<<<<< HEAD
|
|
4
|
+
Copyright (c) 2026 Kartik Subramaniam
|
|
5
|
+
=======
|
|
6
|
+
Copyright (c) 2026 Kartik
|
|
7
|
+
>>>>>>> 979e1b48d355dd6d6dafe50b2cc1c2e21988a077
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# calqulate
|
|
2
|
+
|
|
3
|
+
A modular JavaScript library providing **functional programming helpers**, **async utilities**, **geometry functions**, and **calculus helpers**. Written in plain JavaScript with **TypeScript type definitions** for autocomplete and type checking.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## **Installation**
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install calqulate
|
|
11
|
+
or with Yarn:
|
|
12
|
+
|
|
13
|
+
yarn add calqulate
|
|
14
|
+
Importing
|
|
15
|
+
// CommonJS
|
|
16
|
+
const {
|
|
17
|
+
curry,
|
|
18
|
+
compose,
|
|
19
|
+
mapAsync,
|
|
20
|
+
filterAsync,
|
|
21
|
+
distance,
|
|
22
|
+
rotatePoint,
|
|
23
|
+
polygonArea,
|
|
24
|
+
derivative,
|
|
25
|
+
integrate
|
|
26
|
+
} = require('calqulate');
|
|
27
|
+
|
|
28
|
+
// ES Modules
|
|
29
|
+
import {
|
|
30
|
+
curry,
|
|
31
|
+
compose,
|
|
32
|
+
mapAsync,
|
|
33
|
+
filterAsync,
|
|
34
|
+
distance,
|
|
35
|
+
rotatePoint,
|
|
36
|
+
polygonArea,
|
|
37
|
+
derivative,
|
|
38
|
+
integrate
|
|
39
|
+
} from 'calqulate';
|
|
40
|
+
Functional Programming Helpers
|
|
41
|
+
curry(fn)
|
|
42
|
+
Transforms a function into a curried version.
|
|
43
|
+
|
|
44
|
+
const add = (a, b) => a + b;
|
|
45
|
+
const curriedAdd = curry(add);
|
|
46
|
+
console.log(curriedAdd(2)(3)); // 5
|
|
47
|
+
compose(...fns)
|
|
48
|
+
Compose multiple functions (right to left).
|
|
49
|
+
|
|
50
|
+
const double = x => x * 2;
|
|
51
|
+
const increment = x => x + 1;
|
|
52
|
+
const fn = compose(double, increment);
|
|
53
|
+
console.log(fn(3)); // 8
|
|
54
|
+
mapAsync(arr, fn)
|
|
55
|
+
Map an array asynchronously.
|
|
56
|
+
|
|
57
|
+
await mapAsync([1, 2, 3], async x => x * 2); // [2, 4, 6]
|
|
58
|
+
filterAsync(arr, fn)
|
|
59
|
+
Filter an array asynchronously.
|
|
60
|
+
|
|
61
|
+
await filterAsync([1, 2, 3, 4], async x => x % 2 === 0); // [2, 4]
|
|
62
|
+
Geometry Helpers
|
|
63
|
+
distance(p1, p2)
|
|
64
|
+
Calculate Euclidean distance between two points.
|
|
65
|
+
|
|
66
|
+
const p1 = { x: 0, y: 0 };
|
|
67
|
+
const p2 = { x: 3, y: 4 };
|
|
68
|
+
console.log(distance(p1, p2)); // 5
|
|
69
|
+
rotatePoint(p, angle)
|
|
70
|
+
Rotate a point around the origin by an angle (radians).
|
|
71
|
+
|
|
72
|
+
console.log(rotatePoint({ x: 1, y: 0 }, Math.PI / 2)); // { x: 0, y: 1 }
|
|
73
|
+
polygonArea(points)
|
|
74
|
+
Compute the area of a polygon given its vertices.
|
|
75
|
+
|
|
76
|
+
const square = [
|
|
77
|
+
{ x: 0, y: 0 },
|
|
78
|
+
{ x: 0, y: 2 },
|
|
79
|
+
{ x: 2, y: 2 },
|
|
80
|
+
{ x: 2, y: 0 }
|
|
81
|
+
];
|
|
82
|
+
console.log(polygonArea(square)); // 4
|
|
83
|
+
Calculus Helpers
|
|
84
|
+
derivative(f, x, h?)
|
|
85
|
+
Compute the numerical derivative of a function at a point.
|
|
86
|
+
|
|
87
|
+
const f = x => x ** 2;
|
|
88
|
+
console.log(derivative(f, 3)); // 6
|
|
89
|
+
integrate(f, a, b, n?)
|
|
90
|
+
Compute the numerical integral of a function between a and b.
|
|
91
|
+
|
|
92
|
+
const f = x => x ** 2;
|
|
93
|
+
console.log(integrate(f, 0, 2)); // ≈ 2.6667
|
|
94
|
+
TypeScript Support
|
|
95
|
+
All functions have TypeScript definitions. Example:
|
|
96
|
+
|
|
97
|
+
import { distance, Point } from 'calqulate';
|
|
98
|
+
|
|
99
|
+
const a: Point = { x: 0, y: 0 };
|
|
100
|
+
const b: Point = { x: 1, y: 1 };
|
|
101
|
+
const d: number = distance(a, b);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
# Contributing
|
|
105
|
+
Contributions are welcome! Please open an issue or a pull request.
|
package/fp/compose.js
ADDED
package/fp/curry.js
ADDED
package/fp/mapAsync.js
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// FP
|
|
2
|
+
export function curry<Args extends any[], R>(fn: (...args: Args) => R): (...args: Partial<Args>) => any;
|
|
3
|
+
export function compose<T>(...fns: Array<(arg: T) => T>): (arg: T) => T;
|
|
4
|
+
export function mapAsync<T, R>(arr: T[], fn: (item: T) => Promise<R> | R): Promise<R[]>;
|
|
5
|
+
export function filterAsync<T>(arr: T[], fn: (item: T) => Promise<boolean> | boolean): Promise<T[]>;
|
|
6
|
+
|
|
7
|
+
// Geometry
|
|
8
|
+
export interface Point { x: number; y: number; }
|
|
9
|
+
export function distance(p1: Point, p2: Point): number;
|
|
10
|
+
export function rotatePoint(p: Point, angle: number): Point;
|
|
11
|
+
export function polygonArea(points: Point[]): number;
|
|
12
|
+
|
|
13
|
+
// Calculus
|
|
14
|
+
export type MathFunction = (x: number) => number;
|
|
15
|
+
export function derivative(f: MathFunction, x: number, h?: number): number;
|
|
16
|
+
export function integrate(f: MathFunction, a: number, b: number, n?: number): number;
|
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// FP
|
|
2
|
+
const { curry } = require('./fp/curry');
|
|
3
|
+
const { compose } = require('./fp/compose');
|
|
4
|
+
const { mapAsync } = require('./fp/mapAsync');
|
|
5
|
+
const { filterAsync } = require('./fp/filterAsync');
|
|
6
|
+
|
|
7
|
+
// Geometry
|
|
8
|
+
const { distance } = require('./geometry/distance');
|
|
9
|
+
const { rotatePoint } = require('./geometry/rotatePoint');
|
|
10
|
+
const { polygonArea } = require('./geometry/polygonArea');
|
|
11
|
+
|
|
12
|
+
// Calculus
|
|
13
|
+
const { derivative } = require('./calculus/derivative');
|
|
14
|
+
const { integrate } = require('./calculus/integrate');
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
// FP
|
|
18
|
+
curry,
|
|
19
|
+
compose,
|
|
20
|
+
mapAsync,
|
|
21
|
+
filterAsync,
|
|
22
|
+
|
|
23
|
+
// Geometry
|
|
24
|
+
distance,
|
|
25
|
+
rotatePoint,
|
|
26
|
+
polygonArea,
|
|
27
|
+
|
|
28
|
+
// Calculus
|
|
29
|
+
derivative,
|
|
30
|
+
integrate
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "calqulate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A modular JS library for FP, async, geometry, and calculus helpers",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"No tests yet\""
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"javascript",
|
|
12
|
+
"functional-programming",
|
|
13
|
+
"fp",
|
|
14
|
+
"async",
|
|
15
|
+
"geometry",
|
|
16
|
+
"calculus",
|
|
17
|
+
"math",
|
|
18
|
+
"utilities",
|
|
19
|
+
"helpers"
|
|
20
|
+
],
|
|
21
|
+
"author": "Kartik Subramaniam",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.2.2"
|
|
25
|
+
}
|
|
26
|
+
}
|