Skip to content

Commit a4b5c89

Browse files
committed
🐛 setup deno package
0 parents  commit a4b5c89

File tree

10 files changed

+643
-0
lines changed

10 files changed

+643
-0
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- master
7+
tags:
8+
- '!*' # Do not execute on tags
9+
env:
10+
NAME: ${{vars.NAME}}
11+
EMAIL: ${{vars.EMAIL}}
12+
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
13+
GITHUB_TOKEN: ${{secrets.GH_TOKEN}}
14+
FORCE_COLOR: 1
15+
16+
17+
jobs:
18+
test:
19+
strategy:
20+
matrix:
21+
platform: [ubuntu-latest, windows-latest, macOS-latest]
22+
name: Test on ${{matrix.platform}}
23+
runs-on: ${{matrix.platform}}
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: denoland/setup-deno@v2
27+
with:
28+
deno-version: v2.x
29+
- run: deno test
30+
31+
32+
publish:
33+
name: Publish package
34+
needs: [test]
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: write
38+
id-token: write
39+
steps:
40+
- uses: actions/checkout@v4
41+
- run: npx jsr publish

.github/workflows/pr.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: PR
2+
on: [pull_request]
3+
env:
4+
FORCE_COLOR: 1
5+
6+
7+
jobs:
8+
test:
9+
strategy:
10+
matrix:
11+
platform: [ubuntu-latest, windows-latest, macOS-latest]
12+
name: Test on ${{matrix.platform}}
13+
runs-on: ${{matrix.platform}}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: denoland/setup-deno@v2
17+
with:
18+
deno-version: v2.x
19+
- run: deno test

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Generated files
2+
.build/
3+
.docs/
4+
coverage/
5+
*.d.ts
6+
*.map
7+
example.js
8+
index.js
9+
index.?js
10+
11+
# Logs
12+
logs
13+
*.log
14+
15+
16+
*.orig
17+
*.pyc
18+
*.swp
19+
.env
20+
21+
/.cargo_home/
22+
/.idea/
23+
/.vs/
24+
/.vscode/
25+
gclient_config.py_entries
26+
/target/
27+
/std/hash/_wasm/target
28+
/tests/wpt/runner/manifest.json
29+
/third_party/
30+
/tests/napi/node_modules
31+
/tests/napi/build
32+
/tests/napi/third_party_tests/node_modules
33+
34+
# MacOS generated files
35+
.DS_Store
36+
.DS_Store?
37+
38+
# Flamegraphs
39+
/flamebench*.svg
40+
/flamegraph*.svg
41+
42+
# WPT generated cert files
43+
/tests/wpt/runner/certs/index.txt*
44+
/tests/wpt/runner/certs/serial*
45+
46+
/ext/websocket/autobahn/reports
47+
48+
# JUnit files produced by deno test --junit
49+
junit.xml
50+
51+
# Jupyter files
52+
.ipynb_checkpoints/
53+
Untitled*.ipynb
54+
55+
# playwright browser binary cache
56+
/.ms-playwright

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-25 Subhajit Sahu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
**Mathematics** is the classification and study of all possible patterns [(1)]. This package includes common number functions related to querying *about* numbers, *comparing* numbers, *rounding* numbers, performing *rounded division*, performing *modulo* operations, *controlling range* of numbers, performing *arithmetic* operations, obtaining *divisors* of a number (and related operations), getting the number of possible *arrangements* of a set of objects, performing *geometry*-related calculations, performing basic *statistical* analysis, and finding various *statistical means*.
2+
3+
**Natural numbers**: There are 3 different ways of performing the *modulo* operation: [rem], [mod], and [modp]. [gcd]/`HCF` and [lcm] of a list of numbers can be obtained. To calculate the number of ways of *ordering items*, use [factorial]/`P(n, k)`, [binomial]/`C(n, k)`, or [multinomial]/`n!/k₁!k₂!...`.
4+
5+
**Real numbers**: *Range* of a number can be controlled with [constrain], [normalize], or [remap]. Use [lerp] for *linear interpolation* (or extrapolation); [root] for calculating the *n-th root* of a number; and [log] to find the *logarithm* of a number with a given base.
6+
7+
**Geometry**: Perform conversion from [degrees] to [radians] and vice versa. Find the [magnitude] of a vector or [distance] between two points.
8+
9+
**Statistics**: For a list of numbers, we can calculate the [sum], [product], [arithmeticMean]. [median] gives the value lying in the middle when the numbers are sorted, and [modes] gives the values which are repeated most often. The difference between the largest and the smallest values is the [range]. [variance] is a measure of variability of numbers.
10+
11+
[(1)]: https://en.wikipedia.org/wiki/Walter_Warwick_Sawyer
12+
13+
14+
📦 [JSR](https://jsr.io/@nodef/extra-math),
15+
📰 [Docs](https://jsr.io/@nodef/extra-math/doc),
16+
17+
<br>
18+
19+
20+
```javascript
21+
import * as xmath from "jsr:@nodef/extra-math";
22+
23+
xmath.sum(1, 2, 3, 4);
24+
// → 10
25+
26+
xmath.median(1, 7, 8);
27+
// → 7
28+
29+
xmath.variance(1, 2, 3, 4);
30+
// → 1.25
31+
32+
xmath.lcm(2, 3, 4);
33+
// → 12
34+
```
35+
36+
<br>
37+
<br>
38+
39+
40+
## Index
41+
42+
| Name | Description |
43+
| ---- | ---- |
44+
| [floor] | Round down a number to specific precision. |
45+
| [ceil] | Round up a number to specific precision. |
46+
| [round] | Round a number to specific precision. |
47+
| | |
48+
| [floorDiv] | Perform floor-divison of two numbers. |
49+
| [ceilDiv] | Perform ceiling-divison of two numbers. |
50+
| [roundDiv] | Perform rounded-divison of two numbers. |
51+
| | |
52+
| [rem] | Find the remainder of x/y with sign of x (truncated division). |
53+
| [mod] | Find the remainder of x/y with sign of y (floored division). |
54+
| [modp] | Find the remainder of x/y with +ve sign (euclidean division). |
55+
| | |
56+
| [constrain] | Constrain a number within a minimum and a maximum value. |
57+
| [normalize] | Normalize a number from its current range into a value between 0 and 1. |
58+
| [remap] | Re-map a number from one range to another. |
59+
| [lerp] | Linearly interpolate a number between two numbers. |
60+
| | |
61+
| [isPow] | Check if a number is a power-of-n. |
62+
| [prevPow] | Find largest power-of-n less than or equal to given number. |
63+
| [nextPow] | Find smallest power-of-n greater than or equal to given number. |
64+
| | |
65+
| [root] | Find the nth root of a number (ⁿ√). |
66+
| [log] | Find the logarithm of a number with a given base. |
67+
| | |
68+
| [properDivisors] | List all divisors of a number, except itself. |
69+
| [aliquotSum] | Sum all proper divisors of a number. |
70+
| [minPrimeFactor] | Find the least prime number which divides a number. |
71+
| [maxPrimeFactor] | Find the greatest prime number which divides a number. |
72+
| [primeFactors] | Find the prime factors of a number. |
73+
| [primeExponentials] | Find the prime factors and respective exponents of a number. |
74+
| [isPrime] | Check if number is prime. |
75+
| [gcd] | Find the greatest common divisor of numbers. |
76+
| [lcm] | Find the least common multiple of numbers. |
77+
| | |
78+
| [factorial] | Find the factorial of a number. |
79+
| [binomial] | Find the number of ways to choose k elements from a set of n elements. |
80+
| [multinomial] | Find the number of ways to put n objects in m bins (n=sum(kᵢ)). |
81+
| | |
82+
| [degrees] | Convert radians to degrees. |
83+
| [radians] | Convert degrees to radians. |
84+
| [magnitude] | Calculate the magnitude (length) of a vector. |
85+
| [distance] | Calculate the distance between two points. |
86+
| | |
87+
| [sum] | Find the sum of numbers (Σ). |
88+
| [product] | Find the product of numbers (∏). |
89+
| [median] | Find the value separating the higher and lower halves of numbers. |
90+
| [modes] | Find the values that appear most often. |
91+
| [range] | Find the smallest and largest values. |
92+
| [variance] | Find the mean of squared deviation of numbers from its mean. |
93+
| | |
94+
| [arithmeticMean] | Find the average of numbers. |
95+
| [geometricMean] | Find the geometric mean of numbers. |
96+
| [harmonicMean] | Find the harmonic mean of numbers. |
97+
| [quadriaticMean] | Find the quadriatic mean of numbers. |
98+
| [cubicMean] | Find the cubic mean of numbers. |
99+
100+
<br>
101+
<br>
102+
103+
104+
## References
105+
106+
- [An accurate approximation formula for gamma function; Yang, et al. (2018)](https://doi.org/10.1186/s13660-018-1646-6)
107+
- [MathLib by @alawatthe](https://github.com/alawatthe/MathLib)
108+
- [Processing Reference](https://processing.org/reference)
109+
- [Common mathematical functions by cppreference](https://en.cppreference.com/w/cpp/numeric/math)
110+
- [Modulo operation](https://en.wikipedia.org/wiki/Modulo_operation)
111+
- [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm)
112+
- [Least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple)
113+
- [Permutation](https://en.wikipedia.org/wiki/Permutation)
114+
- [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient)
115+
- [Multinomial distribution](https://en.wikipedia.org/wiki/Multinomial_distribution)
116+
- [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/)
117+
118+
<br>
119+
<br>
120+
121+
122+
[![](https://raw.githubusercontent.com/qb40/designs/gh-pages/0/image/11.png)](https://wolfram77.github.io)<br>
123+
[![ORG](https://img.shields.io/badge/org-nodef-green?logo=Org)](https://nodef.github.io)
124+
![](https://ga-beacon.deno.dev/G-RC63DPBH3P:SH3Eq-NoQ9mwgYeHWxu7cw/github.com/nodef/extra-math)
125+
126+
127+
[floor]: https://jsr.io/@nodef/extra-sql/doc/~/floor
128+
[ceil]: https://jsr.io/@nodef/extra-sql/doc/~/ceil
129+
[round]: https://jsr.io/@nodef/extra-sql/doc/~/round
130+
[floorDiv]: https://jsr.io/@nodef/extra-sql/doc/~/floorDiv
131+
[ceilDiv]: https://jsr.io/@nodef/extra-sql/doc/~/ceilDiv
132+
[roundDiv]: https://jsr.io/@nodef/extra-sql/doc/~/roundDiv
133+
[rem]: https://jsr.io/@nodef/extra-sql/doc/~/rem
134+
[mod]: https://jsr.io/@nodef/extra-sql/doc/~/mod
135+
[modp]: https://jsr.io/@nodef/extra-sql/doc/~/modp
136+
[constrain]: https://jsr.io/@nodef/extra-sql/doc/~/constrain
137+
[normalize]: https://jsr.io/@nodef/extra-sql/doc/~/normalize
138+
[remap]: https://jsr.io/@nodef/extra-sql/doc/~/remap
139+
[lerp]: https://jsr.io/@nodef/extra-sql/doc/~/lerp
140+
[isPow]: https://jsr.io/@nodef/extra-sql/doc/~/isPow
141+
[prevPow]: https://jsr.io/@nodef/extra-sql/doc/~/prevPow
142+
[nextPow]: https://jsr.io/@nodef/extra-sql/doc/~/nextPow
143+
[root]: https://jsr.io/@nodef/extra-sql/doc/~/root
144+
[log]: https://jsr.io/@nodef/extra-sql/doc/~/log
145+
[properDivisors]: https://jsr.io/@nodef/extra-sql/doc/~/properDivisors
146+
[aliquotSum]: https://jsr.io/@nodef/extra-sql/doc/~/aliquotSum
147+
[minPrimeFactor]: https://jsr.io/@nodef/extra-sql/doc/~/minPrimeFactor
148+
[maxPrimeFactor]: https://jsr.io/@nodef/extra-sql/doc/~/maxPrimeFactor
149+
[primeFactors]: https://jsr.io/@nodef/extra-sql/doc/~/primeFactors
150+
[primeExponentials]: https://jsr.io/@nodef/extra-sql/doc/~/primeExponentials
151+
[isPrime]: https://jsr.io/@nodef/extra-sql/doc/~/isPrime
152+
[gcd]: https://jsr.io/@nodef/extra-sql/doc/~/gcd
153+
[lcm]: https://jsr.io/@nodef/extra-sql/doc/~/lcm
154+
[factorial]: https://jsr.io/@nodef/extra-sql/doc/~/factorial
155+
[binomial]: https://jsr.io/@nodef/extra-sql/doc/~/binomial
156+
[multinomial]: https://jsr.io/@nodef/extra-sql/doc/~/multinomial
157+
[degrees]: https://jsr.io/@nodef/extra-sql/doc/~/degrees
158+
[radians]: https://jsr.io/@nodef/extra-sql/doc/~/radians
159+
[magnitude]: https://jsr.io/@nodef/extra-sql/doc/~/magnitude
160+
[distance]: https://jsr.io/@nodef/extra-sql/doc/~/distance
161+
[sum]: https://jsr.io/@nodef/extra-sql/doc/~/sum
162+
[product]: https://jsr.io/@nodef/extra-sql/doc/~/product
163+
[median]: https://jsr.io/@nodef/extra-sql/doc/~/median
164+
[modes]: https://jsr.io/@nodef/extra-sql/doc/~/modes
165+
[range]: https://jsr.io/@nodef/extra-sql/doc/~/range
166+
[variance]: https://jsr.io/@nodef/extra-sql/doc/~/variance
167+
[arithmeticMean]: https://jsr.io/@nodef/extra-sql/doc/~/arithmeticMean
168+
[geometricMean]: https://jsr.io/@nodef/extra-sql/doc/~/geometricMean
169+
[harmonicMean]: https://jsr.io/@nodef/extra-sql/doc/~/harmonicMean
170+
[quadriaticMean]: https://jsr.io/@nodef/extra-sql/doc/~/quadriaticMean
171+
[cubicMean]: https://jsr.io/@nodef/extra-sql/doc/~/cubicMean

deno.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@nodef/extra-math",
3+
"version": "0.0.2",
4+
"license": "MIT",
5+
"exports": "./index.ts"
6+
}

deno.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)