lite-math 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/.eslintrc.json +19 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +51 -0
- package/LICENSE +21 -0
- package/README.md +213 -0
- package/app/globals.css +125 -0
- package/app/layout.tsx +27 -0
- package/app/page.tsx +7 -0
- package/components/theme-provider.tsx +11 -0
- package/components/ui/accordion.tsx +66 -0
- package/components/ui/alert-dialog.tsx +157 -0
- package/components/ui/alert.tsx +66 -0
- package/components/ui/aspect-ratio.tsx +11 -0
- package/components/ui/avatar.tsx +53 -0
- package/components/ui/badge.tsx +46 -0
- package/components/ui/breadcrumb.tsx +109 -0
- package/components/ui/button-group.tsx +83 -0
- package/components/ui/button.tsx +60 -0
- package/components/ui/calendar.tsx +213 -0
- package/components/ui/card.tsx +92 -0
- package/components/ui/carousel.tsx +241 -0
- package/components/ui/chart.tsx +353 -0
- package/components/ui/checkbox.tsx +32 -0
- package/components/ui/collapsible.tsx +33 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/context-menu.tsx +252 -0
- package/components/ui/dialog.tsx +143 -0
- package/components/ui/drawer.tsx +135 -0
- package/components/ui/dropdown-menu.tsx +257 -0
- package/components/ui/empty.tsx +104 -0
- package/components/ui/field.tsx +244 -0
- package/components/ui/form.tsx +167 -0
- package/components/ui/hover-card.tsx +44 -0
- package/components/ui/input-group.tsx +169 -0
- package/components/ui/input-otp.tsx +77 -0
- package/components/ui/input.tsx +21 -0
- package/components/ui/item.tsx +193 -0
- package/components/ui/kbd.tsx +28 -0
- package/components/ui/label.tsx +24 -0
- package/components/ui/menubar.tsx +276 -0
- package/components/ui/navigation-menu.tsx +166 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +48 -0
- package/components/ui/progress.tsx +31 -0
- package/components/ui/radio-group.tsx +45 -0
- package/components/ui/resizable.tsx +56 -0
- package/components/ui/scroll-area.tsx +58 -0
- package/components/ui/select.tsx +185 -0
- package/components/ui/separator.tsx +28 -0
- package/components/ui/sheet.tsx +139 -0
- package/components/ui/sidebar.tsx +726 -0
- package/components/ui/skeleton.tsx +13 -0
- package/components/ui/slider.tsx +63 -0
- package/components/ui/sonner.tsx +25 -0
- package/components/ui/spinner.tsx +16 -0
- package/components/ui/switch.tsx +31 -0
- package/components/ui/table.tsx +116 -0
- package/components/ui/tabs.tsx +66 -0
- package/components/ui/textarea.tsx +18 -0
- package/components/ui/toast.tsx +129 -0
- package/components/ui/toaster.tsx +35 -0
- package/components/ui/toggle-group.tsx +73 -0
- package/components/ui/toggle.tsx +47 -0
- package/components/ui/tooltip.tsx +61 -0
- package/components/ui/use-mobile.tsx +19 -0
- package/components/ui/use-toast.ts +191 -0
- package/components.json +21 -0
- package/dist/advanced/cube-root.d.ts +2 -0
- package/dist/advanced/cube-root.d.ts.map +1 -0
- package/dist/advanced/cube-root.js +4 -0
- package/dist/advanced/cube-root.js.map +1 -0
- package/dist/advanced/factorial.d.ts +2 -0
- package/dist/advanced/factorial.d.ts.map +1 -0
- package/dist/advanced/factorial.js +11 -0
- package/dist/advanced/factorial.js.map +1 -0
- package/dist/advanced/fibonacci.d.ts +2 -0
- package/dist/advanced/fibonacci.d.ts.map +1 -0
- package/dist/advanced/fibonacci.js +15 -0
- package/dist/advanced/fibonacci.js.map +1 -0
- package/dist/advanced/gcd.d.ts +2 -0
- package/dist/advanced/gcd.d.ts.map +1 -0
- package/dist/advanced/gcd.js +10 -0
- package/dist/advanced/gcd.js.map +1 -0
- package/dist/advanced/lcm.d.ts +2 -0
- package/dist/advanced/lcm.d.ts.map +1 -0
- package/dist/advanced/lcm.js +13 -0
- package/dist/advanced/lcm.js.map +1 -0
- package/dist/advanced/power.d.ts +2 -0
- package/dist/advanced/power.d.ts.map +1 -0
- package/dist/advanced/power.js +4 -0
- package/dist/advanced/power.js.map +1 -0
- package/dist/advanced/prime-check.d.ts +2 -0
- package/dist/advanced/prime-check.d.ts.map +1 -0
- package/dist/advanced/prime-check.js +14 -0
- package/dist/advanced/prime-check.js.map +1 -0
- package/dist/advanced/prime-list.d.ts +2 -0
- package/dist/advanced/prime-list.d.ts.map +1 -0
- package/dist/advanced/prime-list.js +14 -0
- package/dist/advanced/prime-list.js.map +1 -0
- package/dist/advanced/sqrt.d.ts +2 -0
- package/dist/advanced/sqrt.d.ts.map +1 -0
- package/dist/advanced/sqrt.js +6 -0
- package/dist/advanced/sqrt.js.map +1 -0
- package/dist/algebra/circle-area.d.ts +2 -0
- package/dist/algebra/circle-area.d.ts.map +1 -0
- package/dist/algebra/circle-area.js +4 -0
- package/dist/algebra/circle-area.js.map +1 -0
- package/dist/algebra/distance.d.ts +2 -0
- package/dist/algebra/distance.d.ts.map +1 -0
- package/dist/algebra/distance.js +4 -0
- package/dist/algebra/distance.js.map +1 -0
- package/dist/algebra/midpoint.d.ts +2 -0
- package/dist/algebra/midpoint.d.ts.map +1 -0
- package/dist/algebra/midpoint.js +4 -0
- package/dist/algebra/midpoint.js.map +1 -0
- package/dist/algebra/slope.d.ts +2 -0
- package/dist/algebra/slope.d.ts.map +1 -0
- package/dist/algebra/slope.js +6 -0
- package/dist/algebra/slope.js.map +1 -0
- package/dist/algebra/solve-linear.d.ts +2 -0
- package/dist/algebra/solve-linear.d.ts.map +1 -0
- package/dist/algebra/solve-linear.js +6 -0
- package/dist/algebra/solve-linear.js.map +1 -0
- package/dist/algebra/solve-quadratic.d.ts +2 -0
- package/dist/algebra/solve-quadratic.d.ts.map +1 -0
- package/dist/algebra/solve-quadratic.js +12 -0
- package/dist/algebra/solve-quadratic.js.map +1 -0
- package/dist/algebra/triangle-area.d.ts +2 -0
- package/dist/algebra/triangle-area.d.ts.map +1 -0
- package/dist/algebra/triangle-area.js +5 -0
- package/dist/algebra/triangle-area.js.map +1 -0
- package/dist/arithmetic/add.d.ts +2 -0
- package/dist/arithmetic/add.d.ts.map +1 -0
- package/dist/arithmetic/add.js +4 -0
- package/dist/arithmetic/add.js.map +1 -0
- package/dist/arithmetic/ceil.d.ts +2 -0
- package/dist/arithmetic/ceil.d.ts.map +1 -0
- package/dist/arithmetic/ceil.js +4 -0
- package/dist/arithmetic/ceil.js.map +1 -0
- package/dist/arithmetic/clamp.d.ts +2 -0
- package/dist/arithmetic/clamp.d.ts.map +1 -0
- package/dist/arithmetic/clamp.js +4 -0
- package/dist/arithmetic/clamp.js.map +1 -0
- package/dist/arithmetic/divide.d.ts +2 -0
- package/dist/arithmetic/divide.d.ts.map +1 -0
- package/dist/arithmetic/divide.js +6 -0
- package/dist/arithmetic/divide.js.map +1 -0
- package/dist/arithmetic/floor.d.ts +2 -0
- package/dist/arithmetic/floor.d.ts.map +1 -0
- package/dist/arithmetic/floor.js +4 -0
- package/dist/arithmetic/floor.js.map +1 -0
- package/dist/arithmetic/modulo.d.ts +2 -0
- package/dist/arithmetic/modulo.d.ts.map +1 -0
- package/dist/arithmetic/modulo.js +4 -0
- package/dist/arithmetic/modulo.js.map +1 -0
- package/dist/arithmetic/multiply.d.ts +2 -0
- package/dist/arithmetic/multiply.d.ts.map +1 -0
- package/dist/arithmetic/multiply.js +4 -0
- package/dist/arithmetic/multiply.js.map +1 -0
- package/dist/arithmetic/percentage.d.ts +2 -0
- package/dist/arithmetic/percentage.d.ts.map +1 -0
- package/dist/arithmetic/percentage.js +4 -0
- package/dist/arithmetic/percentage.js.map +1 -0
- package/dist/arithmetic/round.d.ts +2 -0
- package/dist/arithmetic/round.d.ts.map +1 -0
- package/dist/arithmetic/round.js +5 -0
- package/dist/arithmetic/round.js.map +1 -0
- package/dist/arithmetic/subtract.d.ts +2 -0
- package/dist/arithmetic/subtract.d.ts.map +1 -0
- package/dist/arithmetic/subtract.js +4 -0
- package/dist/arithmetic/subtract.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +277 -0
- package/dist/cli.js.map +1 -0
- package/dist/convert/c-to-f.d.ts +2 -0
- package/dist/convert/c-to-f.d.ts.map +1 -0
- package/dist/convert/c-to-f.js +4 -0
- package/dist/convert/c-to-f.js.map +1 -0
- package/dist/convert/deg-to-rad.d.ts +2 -0
- package/dist/convert/deg-to-rad.d.ts.map +1 -0
- package/dist/convert/deg-to-rad.js +4 -0
- package/dist/convert/deg-to-rad.js.map +1 -0
- package/dist/convert/f-to-c.d.ts +2 -0
- package/dist/convert/f-to-c.d.ts.map +1 -0
- package/dist/convert/f-to-c.js +4 -0
- package/dist/convert/f-to-c.js.map +1 -0
- package/dist/convert/km-to-miles.d.ts +2 -0
- package/dist/convert/km-to-miles.d.ts.map +1 -0
- package/dist/convert/km-to-miles.js +4 -0
- package/dist/convert/km-to-miles.js.map +1 -0
- package/dist/convert/miles-to-km.d.ts +2 -0
- package/dist/convert/miles-to-km.d.ts.map +1 -0
- package/dist/convert/miles-to-km.js +4 -0
- package/dist/convert/miles-to-km.js.map +1 -0
- package/dist/convert/rad-to-deg.d.ts +2 -0
- package/dist/convert/rad-to-deg.d.ts.map +1 -0
- package/dist/convert/rad-to-deg.js +4 -0
- package/dist/convert/rad-to-deg.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/random/random-array.d.ts +2 -0
- package/dist/random/random-array.d.ts.map +1 -0
- package/dist/random/random-array.js +4 -0
- package/dist/random/random-array.js.map +1 -0
- package/dist/random/random-float.d.ts +2 -0
- package/dist/random/random-float.d.ts.map +1 -0
- package/dist/random/random-float.js +4 -0
- package/dist/random/random-float.js.map +1 -0
- package/dist/random/random-from-array.d.ts +2 -0
- package/dist/random/random-from-array.d.ts.map +1 -0
- package/dist/random/random-from-array.js +4 -0
- package/dist/random/random-from-array.js.map +1 -0
- package/dist/random/random-int.d.ts +2 -0
- package/dist/random/random-int.d.ts.map +1 -0
- package/dist/random/random-int.js +4 -0
- package/dist/random/random-int.js.map +1 -0
- package/dist/statistics/mean.d.ts +2 -0
- package/dist/statistics/mean.d.ts.map +1 -0
- package/dist/statistics/mean.js +6 -0
- package/dist/statistics/mean.js.map +1 -0
- package/dist/statistics/median.d.ts +2 -0
- package/dist/statistics/median.d.ts.map +1 -0
- package/dist/statistics/median.js +8 -0
- package/dist/statistics/median.js.map +1 -0
- package/dist/statistics/mode.d.ts +2 -0
- package/dist/statistics/mode.d.ts.map +1 -0
- package/dist/statistics/mode.js +13 -0
- package/dist/statistics/mode.js.map +1 -0
- package/dist/statistics/product-array.d.ts +2 -0
- package/dist/statistics/product-array.d.ts.map +1 -0
- package/dist/statistics/product-array.js +4 -0
- package/dist/statistics/product-array.js.map +1 -0
- package/dist/statistics/range.d.ts +2 -0
- package/dist/statistics/range.d.ts.map +1 -0
- package/dist/statistics/range.js +6 -0
- package/dist/statistics/range.js.map +1 -0
- package/dist/statistics/std-dev.d.ts +2 -0
- package/dist/statistics/std-dev.d.ts.map +1 -0
- package/dist/statistics/std-dev.js +10 -0
- package/dist/statistics/std-dev.js.map +1 -0
- package/dist/statistics/sum-array.d.ts +2 -0
- package/dist/statistics/sum-array.d.ts.map +1 -0
- package/dist/statistics/sum-array.js +4 -0
- package/dist/statistics/sum-array.js.map +1 -0
- package/dist/statistics/variance.d.ts +2 -0
- package/dist/statistics/variance.d.ts.map +1 -0
- package/dist/statistics/variance.js +7 -0
- package/dist/statistics/variance.js.map +1 -0
- package/examples/advanced-examples.ts +31 -0
- package/examples/algebra-examples.ts +24 -0
- package/examples/arithmetic-examples.ts +24 -0
- package/examples/conversion-examples.ts +24 -0
- package/examples/statistics-examples.ts +29 -0
- package/hooks/use-mobile.ts +19 -0
- package/hooks/use-toast.ts +191 -0
- package/jest.config.js +15 -0
- package/lib/utils.ts +6 -0
- package/next.config.mjs +11 -0
- package/package.json +110 -0
- package/postcss.config.mjs +8 -0
- package/public/apple-icon.png +0 -0
- package/public/icon-dark-32x32.png +0 -0
- package/public/icon-light-32x32.png +0 -0
- package/public/icon.svg +26 -0
- package/public/placeholder-logo.png +0 -0
- package/public/placeholder-logo.svg +1 -0
- package/public/placeholder-user.jpg +0 -0
- package/public/placeholder.jpg +0 -0
- package/public/placeholder.svg +1 -0
- package/src/advanced/cube-root.ts +8 -0
- package/src/advanced/factorial.ts +12 -0
- package/src/advanced/fibonacci.ts +16 -0
- package/src/advanced/gcd.ts +14 -0
- package/src/advanced/lcm.ts +18 -0
- package/src/advanced/power.ts +9 -0
- package/src/advanced/prime-check.ts +14 -0
- package/src/advanced/prime-list.ts +16 -0
- package/src/advanced/sqrt.ts +9 -0
- package/src/algebra/circle-area.ts +8 -0
- package/src/algebra/distance.ts +11 -0
- package/src/algebra/midpoint.ts +11 -0
- package/src/algebra/slope.ts +12 -0
- package/src/algebra/solve-linear.ts +10 -0
- package/src/algebra/solve-quadratic.ts +15 -0
- package/src/algebra/triangle-area.ts +11 -0
- package/src/arithmetic/add.ts +9 -0
- package/src/arithmetic/ceil.ts +8 -0
- package/src/arithmetic/clamp.ts +10 -0
- package/src/arithmetic/divide.ts +11 -0
- package/src/arithmetic/floor.ts +8 -0
- package/src/arithmetic/modulo.ts +9 -0
- package/src/arithmetic/multiply.ts +9 -0
- package/src/arithmetic/percentage.ts +9 -0
- package/src/arithmetic/round.ts +10 -0
- package/src/arithmetic/subtract.ts +9 -0
- package/src/cli.ts +321 -0
- package/src/convert/c-to-f.ts +8 -0
- package/src/convert/deg-to-rad.ts +8 -0
- package/src/convert/f-to-c.ts +8 -0
- package/src/convert/km-to-miles.ts +8 -0
- package/src/convert/miles-to-km.ts +8 -0
- package/src/convert/rad-to-deg.ts +8 -0
- package/src/index.ts +49 -0
- package/src/random/random-array.ts +10 -0
- package/src/random/random-float.ts +9 -0
- package/src/random/random-from-array.ts +8 -0
- package/src/random/random-int.ts +9 -0
- package/src/statistics/mean.ts +9 -0
- package/src/statistics/median.ts +11 -0
- package/src/statistics/mode.ts +16 -0
- package/src/statistics/product-array.ts +8 -0
- package/src/statistics/range.ts +9 -0
- package/src/statistics/std-dev.ts +14 -0
- package/src/statistics/sum-array.ts +8 -0
- package/src/statistics/variance.ts +10 -0
- package/styles/globals.css +125 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
// Inspired by react-hot-toast library
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
|
|
6
|
+
import type { ToastActionElement, ToastProps } from '@/components/ui/toast'
|
|
7
|
+
|
|
8
|
+
const TOAST_LIMIT = 1
|
|
9
|
+
const TOAST_REMOVE_DELAY = 1000000
|
|
10
|
+
|
|
11
|
+
type ToasterToast = ToastProps & {
|
|
12
|
+
id: string
|
|
13
|
+
title?: React.ReactNode
|
|
14
|
+
description?: React.ReactNode
|
|
15
|
+
action?: ToastActionElement
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const actionTypes = {
|
|
19
|
+
ADD_TOAST: 'ADD_TOAST',
|
|
20
|
+
UPDATE_TOAST: 'UPDATE_TOAST',
|
|
21
|
+
DISMISS_TOAST: 'DISMISS_TOAST',
|
|
22
|
+
REMOVE_TOAST: 'REMOVE_TOAST',
|
|
23
|
+
} as const
|
|
24
|
+
|
|
25
|
+
let count = 0
|
|
26
|
+
|
|
27
|
+
function genId() {
|
|
28
|
+
count = (count + 1) % Number.MAX_SAFE_INTEGER
|
|
29
|
+
return count.toString()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ActionType = typeof actionTypes
|
|
33
|
+
|
|
34
|
+
type Action =
|
|
35
|
+
| {
|
|
36
|
+
type: ActionType['ADD_TOAST']
|
|
37
|
+
toast: ToasterToast
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
type: ActionType['UPDATE_TOAST']
|
|
41
|
+
toast: Partial<ToasterToast>
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
type: ActionType['DISMISS_TOAST']
|
|
45
|
+
toastId?: ToasterToast['id']
|
|
46
|
+
}
|
|
47
|
+
| {
|
|
48
|
+
type: ActionType['REMOVE_TOAST']
|
|
49
|
+
toastId?: ToasterToast['id']
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface State {
|
|
53
|
+
toasts: ToasterToast[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
|
57
|
+
|
|
58
|
+
const addToRemoveQueue = (toastId: string) => {
|
|
59
|
+
if (toastTimeouts.has(toastId)) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const timeout = setTimeout(() => {
|
|
64
|
+
toastTimeouts.delete(toastId)
|
|
65
|
+
dispatch({
|
|
66
|
+
type: 'REMOVE_TOAST',
|
|
67
|
+
toastId: toastId,
|
|
68
|
+
})
|
|
69
|
+
}, TOAST_REMOVE_DELAY)
|
|
70
|
+
|
|
71
|
+
toastTimeouts.set(toastId, timeout)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const reducer = (state: State, action: Action): State => {
|
|
75
|
+
switch (action.type) {
|
|
76
|
+
case 'ADD_TOAST':
|
|
77
|
+
return {
|
|
78
|
+
...state,
|
|
79
|
+
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
case 'UPDATE_TOAST':
|
|
83
|
+
return {
|
|
84
|
+
...state,
|
|
85
|
+
toasts: state.toasts.map((t) =>
|
|
86
|
+
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
|
87
|
+
),
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
case 'DISMISS_TOAST': {
|
|
91
|
+
const { toastId } = action
|
|
92
|
+
|
|
93
|
+
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
|
94
|
+
// but I'll keep it here for simplicity
|
|
95
|
+
if (toastId) {
|
|
96
|
+
addToRemoveQueue(toastId)
|
|
97
|
+
} else {
|
|
98
|
+
state.toasts.forEach((toast) => {
|
|
99
|
+
addToRemoveQueue(toast.id)
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
...state,
|
|
105
|
+
toasts: state.toasts.map((t) =>
|
|
106
|
+
t.id === toastId || toastId === undefined
|
|
107
|
+
? {
|
|
108
|
+
...t,
|
|
109
|
+
open: false,
|
|
110
|
+
}
|
|
111
|
+
: t,
|
|
112
|
+
),
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
case 'REMOVE_TOAST':
|
|
116
|
+
if (action.toastId === undefined) {
|
|
117
|
+
return {
|
|
118
|
+
...state,
|
|
119
|
+
toasts: [],
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
...state,
|
|
124
|
+
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const listeners: Array<(state: State) => void> = []
|
|
130
|
+
|
|
131
|
+
let memoryState: State = { toasts: [] }
|
|
132
|
+
|
|
133
|
+
function dispatch(action: Action) {
|
|
134
|
+
memoryState = reducer(memoryState, action)
|
|
135
|
+
listeners.forEach((listener) => {
|
|
136
|
+
listener(memoryState)
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
type Toast = Omit<ToasterToast, 'id'>
|
|
141
|
+
|
|
142
|
+
function toast({ ...props }: Toast) {
|
|
143
|
+
const id = genId()
|
|
144
|
+
|
|
145
|
+
const update = (props: ToasterToast) =>
|
|
146
|
+
dispatch({
|
|
147
|
+
type: 'UPDATE_TOAST',
|
|
148
|
+
toast: { ...props, id },
|
|
149
|
+
})
|
|
150
|
+
const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id })
|
|
151
|
+
|
|
152
|
+
dispatch({
|
|
153
|
+
type: 'ADD_TOAST',
|
|
154
|
+
toast: {
|
|
155
|
+
...props,
|
|
156
|
+
id,
|
|
157
|
+
open: true,
|
|
158
|
+
onOpenChange: (open) => {
|
|
159
|
+
if (!open) dismiss()
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
id: id,
|
|
166
|
+
dismiss,
|
|
167
|
+
update,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function useToast() {
|
|
172
|
+
const [state, setState] = React.useState<State>(memoryState)
|
|
173
|
+
|
|
174
|
+
React.useEffect(() => {
|
|
175
|
+
listeners.push(setState)
|
|
176
|
+
return () => {
|
|
177
|
+
const index = listeners.indexOf(setState)
|
|
178
|
+
if (index > -1) {
|
|
179
|
+
listeners.splice(index, 1)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, [state])
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
...state,
|
|
186
|
+
toast,
|
|
187
|
+
dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { useToast, toast }
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
preset: "ts-jest",
|
|
3
|
+
testEnvironment: "node",
|
|
4
|
+
roots: ["<rootDir>/src"],
|
|
5
|
+
testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
|
|
6
|
+
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts", "!src/cli.ts"],
|
|
7
|
+
coverageThreshold: {
|
|
8
|
+
global: {
|
|
9
|
+
branches: 80,
|
|
10
|
+
functions: 80,
|
|
11
|
+
lines: 80,
|
|
12
|
+
statements: 80,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
}
|
package/lib/utils.ts
ADDED
package/next.config.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lite-math",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A comprehensive TypeScript library of 40+ mathematical operations including arithmetic, advanced math, statistics, random numbers, algebra, and unit conversions.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./arithmetic": {
|
|
14
|
+
"import": "./dist/arithmetic/index.js",
|
|
15
|
+
"types": "./dist/arithmetic/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./advanced": {
|
|
18
|
+
"import": "./dist/advanced/index.js",
|
|
19
|
+
"types": "./dist/advanced/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./statistics": {
|
|
22
|
+
"import": "./dist/statistics/index.js",
|
|
23
|
+
"types": "./dist/statistics/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./random": {
|
|
26
|
+
"import": "./dist/random/index.js",
|
|
27
|
+
"types": "./dist/random/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./algebra": {
|
|
30
|
+
"import": "./dist/algebra/index.js",
|
|
31
|
+
"types": "./dist/algebra/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./conversion": {
|
|
34
|
+
"import": "./dist/conversion/index.js",
|
|
35
|
+
"types": "./dist/conversion/index.d.ts"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"math-ops": "./dist/cli.js"
|
|
40
|
+
},
|
|
41
|
+
"author": {
|
|
42
|
+
"name": "Kanti Lal",
|
|
43
|
+
"url": "https://github.com/kanti-lal"
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/kanti-lal/math-operations"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/kanti-lal/math-operations",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/kanti-lal/math-operations/issues"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"math",
|
|
56
|
+
"mathematics",
|
|
57
|
+
"calculations",
|
|
58
|
+
"arithmetic",
|
|
59
|
+
"statistics",
|
|
60
|
+
"algebra",
|
|
61
|
+
"random",
|
|
62
|
+
"conversion",
|
|
63
|
+
"utility",
|
|
64
|
+
"typescript",
|
|
65
|
+
"cli"
|
|
66
|
+
],
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsc",
|
|
69
|
+
"watch": "tsc --watch",
|
|
70
|
+
"test": "jest --passWithNoTests",
|
|
71
|
+
"test:watch": "jest --watch",
|
|
72
|
+
"test:coverage": "jest --coverage",
|
|
73
|
+
"lint": "eslint src --ext .ts",
|
|
74
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
75
|
+
"prepublishOnly": "npm run build && npm run test",
|
|
76
|
+
"postpublish": "echo 'Package published successfully!'",
|
|
77
|
+
"cli": "node dist/cli.js"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@types/jest": "^29.5.0",
|
|
81
|
+
"@types/node": "^20.0.0",
|
|
82
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
83
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
84
|
+
"eslint": "^8.0.0",
|
|
85
|
+
"jest": "^29.5.0",
|
|
86
|
+
"prettier": "^3.0.0",
|
|
87
|
+
"ts-jest": "^29.1.0",
|
|
88
|
+
"typescript": "^5.0.0",
|
|
89
|
+
"@types/react": "19.2.7",
|
|
90
|
+
"@types/react-dom": "19.2.3",
|
|
91
|
+
"tailwindcss": "^4.1.9",
|
|
92
|
+
"postcss": "8.5.6"
|
|
93
|
+
},
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": ">=16.0.0"
|
|
96
|
+
},
|
|
97
|
+
"publishConfig": {
|
|
98
|
+
"access": "public"
|
|
99
|
+
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"next": "16.0.7",
|
|
102
|
+
"react": "19.2.1",
|
|
103
|
+
"react-dom": "19.2.1",
|
|
104
|
+
"class-variance-authority": "0.7.1",
|
|
105
|
+
"clsx": "2.1.1",
|
|
106
|
+
"lucide-react": "0.556.0",
|
|
107
|
+
"tailwind-merge": "3.4.0",
|
|
108
|
+
"tailwindcss-animate": "1.0.7"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/public/icon.svg
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<svg width="180" height="180" viewBox="0 0 180 180" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<style>
|
|
3
|
+
@media (prefers-color-scheme: light) {
|
|
4
|
+
.background { fill: black; }
|
|
5
|
+
.foreground { fill: white; }
|
|
6
|
+
}
|
|
7
|
+
@media (prefers-color-scheme: dark) {
|
|
8
|
+
.background { fill: white; }
|
|
9
|
+
.foreground { fill: black; }
|
|
10
|
+
}
|
|
11
|
+
</style>
|
|
12
|
+
<g clip-path="url(#clip0_7960_43945)">
|
|
13
|
+
<rect class="background" width="180" height="180" rx="37" />
|
|
14
|
+
<g style="transform: scale(95%); transform-origin: center">
|
|
15
|
+
<path class="foreground"
|
|
16
|
+
d="M101.141 53H136.632C151.023 53 162.689 64.6662 162.689 79.0573V112.904H148.112V79.0573C148.112 78.7105 148.098 78.3662 148.072 78.0251L112.581 112.898C112.701 112.902 112.821 112.904 112.941 112.904H148.112V126.672H112.941C98.5504 126.672 86.5638 114.891 86.5638 100.5V66.7434H101.141V100.5C101.141 101.15 101.191 101.792 101.289 102.422L137.56 66.7816C137.255 66.7563 136.945 66.7434 136.632 66.7434H101.141V53Z" />
|
|
17
|
+
<path class="foreground"
|
|
18
|
+
d="M65.2926 124.136L14 66.7372H34.6355L64.7495 100.436V66.7372H80.1365V118.47C80.1365 126.278 70.4953 129.958 65.2926 124.136Z" />
|
|
19
|
+
</g>
|
|
20
|
+
</g>
|
|
21
|
+
<defs>
|
|
22
|
+
<clipPath id="clip0_7960_43945">
|
|
23
|
+
<rect width="180" height="180" fill="white" />
|
|
24
|
+
</clipPath>
|
|
25
|
+
</defs>
|
|
26
|
+
</svg>
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="215" height="48" fill="none"><path fill="#000" d="M57.588 9.6h6L73.828 38h-5.2l-2.36-6.88h-11.36L52.548 38h-5.2l10.24-28.4Zm7.16 17.16-4.16-12.16-4.16 12.16h8.32Zm23.694-2.24c-.186-1.307-.706-2.32-1.56-3.04-.853-.72-1.866-1.08-3.04-1.08-1.68 0-2.986.613-3.92 1.84-.906 1.227-1.36 2.947-1.36 5.16s.454 3.933 1.36 5.16c.934 1.227 2.24 1.84 3.92 1.84 1.254 0 2.307-.373 3.16-1.12.854-.773 1.387-1.867 1.6-3.28l5.12.24c-.186 1.68-.733 3.147-1.64 4.4-.906 1.227-2.08 2.173-3.52 2.84-1.413.667-2.986 1-4.72 1-2.08 0-3.906-.453-5.48-1.36-1.546-.907-2.76-2.2-3.64-3.88-.853-1.68-1.28-3.627-1.28-5.84 0-2.24.427-4.187 1.28-5.84.88-1.68 2.094-2.973 3.64-3.88 1.574-.907 3.4-1.36 5.48-1.36 1.68 0 3.227.32 4.64.96 1.414.64 2.56 1.56 3.44 2.76.907 1.2 1.454 2.6 1.64 4.2l-5.12.28Zm11.486-7.72.12 3.4c.534-1.227 1.307-2.173 2.32-2.84 1.04-.693 2.267-1.04 3.68-1.04 1.494 0 2.76.387 3.8 1.16 1.067.747 1.827 1.813 2.28 3.2.507-1.44 1.294-2.52 2.36-3.24 1.094-.747 2.414-1.12 3.96-1.12 1.414 0 2.64.307 3.68.92s1.84 1.52 2.4 2.72c.56 1.2.84 2.667.84 4.4V38h-4.96V25.92c0-1.813-.293-3.187-.88-4.12-.56-.96-1.413-1.44-2.56-1.44-.906 0-1.68.213-2.32.64-.64.427-1.133 1.053-1.48 1.88-.32.827-.48 1.84-.48 3.04V38h-4.56V25.92c0-1.2-.133-2.213-.4-3.04-.24-.827-.626-1.453-1.16-1.88-.506-.427-1.133-.64-1.88-.64-.906 0-1.68.227-2.32.68-.64.427-1.133 1.053-1.48 1.88-.32.827-.48 1.827-.48 3V38h-4.96V16.8h4.48Zm26.723 10.6c0-2.24.427-4.187 1.28-5.84.854-1.68 2.067-2.973 3.64-3.88 1.574-.907 3.4-1.36 5.48-1.36 1.84 0 3.494.413 4.96 1.24 1.467.827 2.64 2.08 3.52 3.76.88 1.653 1.347 3.693 1.4 6.12v1.32h-15.08c.107 1.813.614 3.227 1.52 4.24.907.987 2.134 1.48 3.68 1.48.987 0 1.88-.253 2.68-.76a4.803 4.803 0 0 0 1.84-2.2l5.08.36c-.64 2.027-1.84 3.64-3.6 4.84-1.733 1.173-3.733 1.76-6 1.76-2.08 0-3.906-.453-5.48-1.36-1.573-.907-2.786-2.2-3.64-3.88-.853-1.68-1.28-3.627-1.28-5.84Zm15.16-2.04c-.213-1.733-.76-3.013-1.64-3.84-.853-.827-1.893-1.24-3.12-1.24-1.44 0-2.6.453-3.48 1.36-.88.88-1.44 2.12-1.68 3.72h9.92ZM163.139 9.6V38h-5.04V9.6h5.04Zm8.322 7.2.24 5.88-.64-.36c.32-2.053 1.094-3.56 2.32-4.52 1.254-.987 2.787-1.48 4.6-1.48 2.32 0 4.107.733 5.36 2.2 1.254 1.44 1.88 3.387 1.88 5.84V38h-4.96V25.92c0-1.253-.12-2.28-.36-3.08-.24-.8-.64-1.413-1.2-1.84-.533-.427-1.253-.64-2.16-.64-1.44 0-2.573.48-3.4 1.44-.8.933-1.2 2.307-1.2 4.12V38h-4.96V16.8h4.48Zm30.003 7.72c-.186-1.307-.706-2.32-1.56-3.04-.853-.72-1.866-1.08-3.04-1.08-1.68 0-2.986.613-3.92 1.84-.906 1.227-1.36 2.947-1.36 5.16s.454 3.933 1.36 5.16c.934 1.227 2.24 1.84 3.92 1.84 1.254 0 2.307-.373 3.16-1.12.854-.773 1.387-1.867 1.6-3.28l5.12.24c-.186 1.68-.733 3.147-1.64 4.4-.906 1.227-2.08 2.173-3.52 2.84-1.413.667-2.986 1-4.72 1-2.08 0-3.906-.453-5.48-1.36-1.546-.907-2.76-2.2-3.64-3.88-.853-1.68-1.28-3.627-1.28-5.84 0-2.24.427-4.187 1.28-5.84.88-1.68 2.094-2.973 3.64-3.88 1.574-.907 3.4-1.36 5.48-1.36 1.68 0 3.227.32 4.64.96 1.414.64 2.56 1.56 3.44 2.76.907 1.2 1.454 2.6 1.64 4.2l-5.12.28Zm11.443 8.16V38h-5.6v-5.32h5.6Z"/><path fill="#171717" fill-rule="evenodd" d="m7.839 40.783 16.03-28.054L20 6 0 40.783h7.839Zm8.214 0H40L27.99 19.894l-4.02 7.032 3.976 6.914H20.02l-3.967 6.943Z" clip-rule="evenodd"/></svg>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="1200" fill="none"><rect width="1200" height="1200" fill="#EAEAEA" rx="3"/><g opacity=".5"><g opacity=".5"><path fill="#FAFAFA" d="M600.709 736.5c-75.454 0-136.621-61.167-136.621-136.62 0-75.454 61.167-136.621 136.621-136.621 75.453 0 136.62 61.167 136.62 136.621 0 75.453-61.167 136.62-136.62 136.62Z"/><path stroke="#C9C9C9" stroke-width="2.418" d="M600.709 736.5c-75.454 0-136.621-61.167-136.621-136.62 0-75.454 61.167-136.621 136.621-136.621 75.453 0 136.62 61.167 136.62 136.621 0 75.453-61.167 136.62-136.62 136.62Z"/></g><path stroke="url(#a)" stroke-width="2.418" d="M0-1.209h553.581" transform="scale(1 -1) rotate(45 1163.11 91.165)"/><path stroke="url(#b)" stroke-width="2.418" d="M404.846 598.671h391.726"/><path stroke="url(#c)" stroke-width="2.418" d="M599.5 795.742V404.017"/><path stroke="url(#d)" stroke-width="2.418" d="m795.717 796.597-391.441-391.44"/><path fill="#fff" d="M600.709 656.704c-31.384 0-56.825-25.441-56.825-56.824 0-31.384 25.441-56.825 56.825-56.825 31.383 0 56.824 25.441 56.824 56.825 0 31.383-25.441 56.824-56.824 56.824Z"/><g clip-path="url(#e)"><path fill="#666" fill-rule="evenodd" d="M616.426 586.58h-31.434v16.176l3.553-3.554.531-.531h9.068l.074-.074 8.463-8.463h2.565l7.18 7.181V586.58Zm-15.715 14.654 3.698 3.699 1.283 1.282-2.565 2.565-1.282-1.283-5.2-5.199h-6.066l-5.514 5.514-.073.073v2.876a2.418 2.418 0 0 0 2.418 2.418h26.598a2.418 2.418 0 0 0 2.418-2.418v-8.317l-8.463-8.463-7.181 7.181-.071.072Zm-19.347 5.442v4.085a6.045 6.045 0 0 0 6.046 6.045h26.598a6.044 6.044 0 0 0 6.045-6.045v-7.108l1.356-1.355-1.282-1.283-.074-.073v-17.989h-38.689v23.43l-.146.146.146.147Z" clip-rule="evenodd"/></g><path stroke="#C9C9C9" stroke-width="2.418" d="M600.709 656.704c-31.384 0-56.825-25.441-56.825-56.824 0-31.384 25.441-56.825 56.825-56.825 31.383 0 56.824 25.441 56.824 56.825 0 31.383-25.441 56.824-56.824 56.824Z"/></g><defs><linearGradient id="a" x1="554.061" x2="-.48" y1=".083" y2=".087" gradientUnits="userSpaceOnUse"><stop stop-color="#C9C9C9" stop-opacity="0"/><stop offset=".208" stop-color="#C9C9C9"/><stop offset=".792" stop-color="#C9C9C9"/><stop offset="1" stop-color="#C9C9C9" stop-opacity="0"/></linearGradient><linearGradient id="b" x1="796.912" x2="404.507" y1="599.963" y2="599.965" gradientUnits="userSpaceOnUse"><stop stop-color="#C9C9C9" stop-opacity="0"/><stop offset=".208" stop-color="#C9C9C9"/><stop offset=".792" stop-color="#C9C9C9"/><stop offset="1" stop-color="#C9C9C9" stop-opacity="0"/></linearGradient><linearGradient id="c" x1="600.792" x2="600.794" y1="403.677" y2="796.082" gradientUnits="userSpaceOnUse"><stop stop-color="#C9C9C9" stop-opacity="0"/><stop offset=".208" stop-color="#C9C9C9"/><stop offset=".792" stop-color="#C9C9C9"/><stop offset="1" stop-color="#C9C9C9" stop-opacity="0"/></linearGradient><linearGradient id="d" x1="404.85" x2="796.972" y1="403.903" y2="796.02" gradientUnits="userSpaceOnUse"><stop stop-color="#C9C9C9" stop-opacity="0"/><stop offset=".208" stop-color="#C9C9C9"/><stop offset=".792" stop-color="#C9C9C9"/><stop offset="1" stop-color="#C9C9C9" stop-opacity="0"/></linearGradient><clipPath id="e"><path fill="#fff" d="M581.364 580.535h38.689v38.689h-38.689z"/></clipPath></defs></svg>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates factorial of a number
|
|
3
|
+
* @param n - Non-negative integer
|
|
4
|
+
* @returns Factorial of n
|
|
5
|
+
*/
|
|
6
|
+
export function factorial(n: number): number {
|
|
7
|
+
if (n < 0) throw new Error("Factorial undefined for negative numbers")
|
|
8
|
+
if (n === 0 || n === 1) return 1
|
|
9
|
+
let result = 1
|
|
10
|
+
for (let i = 2; i <= n; i++) result *= i
|
|
11
|
+
return result
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the nth Fibonacci number
|
|
3
|
+
* @param n - Position in sequence (0-indexed)
|
|
4
|
+
* @returns Fibonacci number at position n
|
|
5
|
+
*/
|
|
6
|
+
export function fibonacci(n: number): number {
|
|
7
|
+
if (n < 0) throw new Error("Fibonacci index must be non-negative")
|
|
8
|
+
if (n === 0) return 0
|
|
9
|
+
if (n === 1) return 1
|
|
10
|
+
let a = 0,
|
|
11
|
+
b = 1
|
|
12
|
+
for (let i = 2; i <= n; i++) {
|
|
13
|
+
;[a, b] = [b, a + b]
|
|
14
|
+
}
|
|
15
|
+
return b
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates greatest common divisor
|
|
3
|
+
* @param a - First number
|
|
4
|
+
* @param b - Second number
|
|
5
|
+
* @returns GCD of a and b
|
|
6
|
+
*/
|
|
7
|
+
export function gcd(a: number, b: number): number {
|
|
8
|
+
a = Math.abs(a)
|
|
9
|
+
b = Math.abs(b)
|
|
10
|
+
while (b !== 0) {
|
|
11
|
+
;[a, b] = [b, a % b]
|
|
12
|
+
}
|
|
13
|
+
return a
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates least common multiple
|
|
3
|
+
* @param a - First number
|
|
4
|
+
* @param b - Second number
|
|
5
|
+
* @returns LCM of a and b
|
|
6
|
+
*/
|
|
7
|
+
export function lcm(a: number, b: number): number {
|
|
8
|
+
return Math.abs(a * b) / gcd(a, b)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function gcd(a: number, b: number): number {
|
|
12
|
+
a = Math.abs(a)
|
|
13
|
+
b = Math.abs(b)
|
|
14
|
+
while (b !== 0) {
|
|
15
|
+
;[a, b] = [b, a % b]
|
|
16
|
+
}
|
|
17
|
+
return a
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is prime
|
|
3
|
+
* @param n - Number to check
|
|
4
|
+
* @returns True if prime, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
export function primeCheck(n: number): boolean {
|
|
7
|
+
if (n <= 1) return false
|
|
8
|
+
if (n <= 3) return true
|
|
9
|
+
if (n % 2 === 0 || n % 3 === 0) return false
|
|
10
|
+
for (let i = 5; i * i <= n; i += 6) {
|
|
11
|
+
if (n % i === 0 || n % (i + 2) === 0) return false
|
|
12
|
+
}
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns list of prime numbers up to n
|
|
3
|
+
* @param n - Upper limit
|
|
4
|
+
* @returns Array of primes up to n
|
|
5
|
+
*/
|
|
6
|
+
export function primeList(n: number): number[] {
|
|
7
|
+
if (n < 2) return []
|
|
8
|
+
const sieve = Array(n + 1).fill(true)
|
|
9
|
+
sieve[0] = sieve[1] = false
|
|
10
|
+
for (let i = 2; i * i <= n; i++) {
|
|
11
|
+
if (sieve[i]) {
|
|
12
|
+
for (let j = i * i; j <= n; j += i) sieve[j] = false
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return sieve.map((v, i) => (v ? i : null)).filter((v) => v !== null) as number[]
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates distance between two points
|
|
3
|
+
* @param x1 - X coordinate of point 1
|
|
4
|
+
* @param y1 - Y coordinate of point 1
|
|
5
|
+
* @param x2 - X coordinate of point 2
|
|
6
|
+
* @param y2 - Y coordinate of point 2
|
|
7
|
+
* @returns Distance between points
|
|
8
|
+
*/
|
|
9
|
+
export function distance(x1: number, y1: number, x2: number, y2: number): number {
|
|
10
|
+
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2))
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates midpoint between two points
|
|
3
|
+
* @param x1 - X coordinate of point 1
|
|
4
|
+
* @param y1 - Y coordinate of point 1
|
|
5
|
+
* @param x2 - X coordinate of point 2
|
|
6
|
+
* @param y2 - Y coordinate of point 2
|
|
7
|
+
* @returns Midpoint coordinates
|
|
8
|
+
*/
|
|
9
|
+
export function midpoint(x1: number, y1: number, x2: number, y2: number): [number, number] {
|
|
10
|
+
return [(x1 + x2) / 2, (y1 + y2) / 2]
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates slope between two points
|
|
3
|
+
* @param x1 - X coordinate of point 1
|
|
4
|
+
* @param y1 - Y coordinate of point 1
|
|
5
|
+
* @param x2 - X coordinate of point 2
|
|
6
|
+
* @param y2 - Y coordinate of point 2
|
|
7
|
+
* @returns Slope value
|
|
8
|
+
*/
|
|
9
|
+
export function slope(x1: number, y1: number, x2: number, y2: number): number {
|
|
10
|
+
if (x2 === x1) throw new Error("Vertical line - undefined slope")
|
|
11
|
+
return (y2 - y1) / (x2 - x1)
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solves linear equation ax + b = 0
|
|
3
|
+
* @param a - Coefficient of x
|
|
4
|
+
* @param b - Constant term
|
|
5
|
+
* @returns Solution x
|
|
6
|
+
*/
|
|
7
|
+
export function solveLinear(a: number, b: number): number {
|
|
8
|
+
if (a === 0) throw new Error("Not a linear equation")
|
|
9
|
+
return -b / a
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solves quadratic equation ax^2 + bx + c = 0
|
|
3
|
+
* @param a - Coefficient of x^2
|
|
4
|
+
* @param b - Coefficient of x
|
|
5
|
+
* @param c - Constant term
|
|
6
|
+
* @returns Array of solutions
|
|
7
|
+
*/
|
|
8
|
+
export function solveQuadratic(a: number, b: number, c: number): number[] {
|
|
9
|
+
if (a === 0) throw new Error("Not a quadratic equation")
|
|
10
|
+
const discriminant = b * b - 4 * a * c
|
|
11
|
+
if (discriminant < 0) return []
|
|
12
|
+
if (discriminant === 0) return [-b / (2 * a)]
|
|
13
|
+
const sqrtD = Math.sqrt(discriminant)
|
|
14
|
+
return [(-b + sqrtD) / (2 * a), (-b - sqrtD) / (2 * a)]
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates area of triangle using Heron's formula
|
|
3
|
+
* @param a - Side a
|
|
4
|
+
* @param b - Side b
|
|
5
|
+
* @param c - Side c
|
|
6
|
+
* @returns Area of triangle
|
|
7
|
+
*/
|
|
8
|
+
export function triangleArea(a: number, b: number, c: number): number {
|
|
9
|
+
const s = (a + b + c) / 2
|
|
10
|
+
return Math.sqrt(s * (s - a) * (s - b) * (s - c))
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a value between min and max
|
|
3
|
+
* @param value - The value to clamp
|
|
4
|
+
* @param min - Minimum value
|
|
5
|
+
* @param max - Maximum value
|
|
6
|
+
* @returns Clamped value
|
|
7
|
+
*/
|
|
8
|
+
export function clamp(value: number, min: number, max: number): number {
|
|
9
|
+
return Math.min(Math.max(value, min), max)
|
|
10
|
+
}
|