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.
Files changed (321) hide show
  1. package/.eslintrc.json +19 -0
  2. package/.prettierrc +10 -0
  3. package/CHANGELOG.md +22 -0
  4. package/CONTRIBUTING.md +51 -0
  5. package/LICENSE +21 -0
  6. package/README.md +213 -0
  7. package/app/globals.css +125 -0
  8. package/app/layout.tsx +27 -0
  9. package/app/page.tsx +7 -0
  10. package/components/theme-provider.tsx +11 -0
  11. package/components/ui/accordion.tsx +66 -0
  12. package/components/ui/alert-dialog.tsx +157 -0
  13. package/components/ui/alert.tsx +66 -0
  14. package/components/ui/aspect-ratio.tsx +11 -0
  15. package/components/ui/avatar.tsx +53 -0
  16. package/components/ui/badge.tsx +46 -0
  17. package/components/ui/breadcrumb.tsx +109 -0
  18. package/components/ui/button-group.tsx +83 -0
  19. package/components/ui/button.tsx +60 -0
  20. package/components/ui/calendar.tsx +213 -0
  21. package/components/ui/card.tsx +92 -0
  22. package/components/ui/carousel.tsx +241 -0
  23. package/components/ui/chart.tsx +353 -0
  24. package/components/ui/checkbox.tsx +32 -0
  25. package/components/ui/collapsible.tsx +33 -0
  26. package/components/ui/command.tsx +184 -0
  27. package/components/ui/context-menu.tsx +252 -0
  28. package/components/ui/dialog.tsx +143 -0
  29. package/components/ui/drawer.tsx +135 -0
  30. package/components/ui/dropdown-menu.tsx +257 -0
  31. package/components/ui/empty.tsx +104 -0
  32. package/components/ui/field.tsx +244 -0
  33. package/components/ui/form.tsx +167 -0
  34. package/components/ui/hover-card.tsx +44 -0
  35. package/components/ui/input-group.tsx +169 -0
  36. package/components/ui/input-otp.tsx +77 -0
  37. package/components/ui/input.tsx +21 -0
  38. package/components/ui/item.tsx +193 -0
  39. package/components/ui/kbd.tsx +28 -0
  40. package/components/ui/label.tsx +24 -0
  41. package/components/ui/menubar.tsx +276 -0
  42. package/components/ui/navigation-menu.tsx +166 -0
  43. package/components/ui/pagination.tsx +127 -0
  44. package/components/ui/popover.tsx +48 -0
  45. package/components/ui/progress.tsx +31 -0
  46. package/components/ui/radio-group.tsx +45 -0
  47. package/components/ui/resizable.tsx +56 -0
  48. package/components/ui/scroll-area.tsx +58 -0
  49. package/components/ui/select.tsx +185 -0
  50. package/components/ui/separator.tsx +28 -0
  51. package/components/ui/sheet.tsx +139 -0
  52. package/components/ui/sidebar.tsx +726 -0
  53. package/components/ui/skeleton.tsx +13 -0
  54. package/components/ui/slider.tsx +63 -0
  55. package/components/ui/sonner.tsx +25 -0
  56. package/components/ui/spinner.tsx +16 -0
  57. package/components/ui/switch.tsx +31 -0
  58. package/components/ui/table.tsx +116 -0
  59. package/components/ui/tabs.tsx +66 -0
  60. package/components/ui/textarea.tsx +18 -0
  61. package/components/ui/toast.tsx +129 -0
  62. package/components/ui/toaster.tsx +35 -0
  63. package/components/ui/toggle-group.tsx +73 -0
  64. package/components/ui/toggle.tsx +47 -0
  65. package/components/ui/tooltip.tsx +61 -0
  66. package/components/ui/use-mobile.tsx +19 -0
  67. package/components/ui/use-toast.ts +191 -0
  68. package/components.json +21 -0
  69. package/dist/advanced/cube-root.d.ts +2 -0
  70. package/dist/advanced/cube-root.d.ts.map +1 -0
  71. package/dist/advanced/cube-root.js +4 -0
  72. package/dist/advanced/cube-root.js.map +1 -0
  73. package/dist/advanced/factorial.d.ts +2 -0
  74. package/dist/advanced/factorial.d.ts.map +1 -0
  75. package/dist/advanced/factorial.js +11 -0
  76. package/dist/advanced/factorial.js.map +1 -0
  77. package/dist/advanced/fibonacci.d.ts +2 -0
  78. package/dist/advanced/fibonacci.d.ts.map +1 -0
  79. package/dist/advanced/fibonacci.js +15 -0
  80. package/dist/advanced/fibonacci.js.map +1 -0
  81. package/dist/advanced/gcd.d.ts +2 -0
  82. package/dist/advanced/gcd.d.ts.map +1 -0
  83. package/dist/advanced/gcd.js +10 -0
  84. package/dist/advanced/gcd.js.map +1 -0
  85. package/dist/advanced/lcm.d.ts +2 -0
  86. package/dist/advanced/lcm.d.ts.map +1 -0
  87. package/dist/advanced/lcm.js +13 -0
  88. package/dist/advanced/lcm.js.map +1 -0
  89. package/dist/advanced/power.d.ts +2 -0
  90. package/dist/advanced/power.d.ts.map +1 -0
  91. package/dist/advanced/power.js +4 -0
  92. package/dist/advanced/power.js.map +1 -0
  93. package/dist/advanced/prime-check.d.ts +2 -0
  94. package/dist/advanced/prime-check.d.ts.map +1 -0
  95. package/dist/advanced/prime-check.js +14 -0
  96. package/dist/advanced/prime-check.js.map +1 -0
  97. package/dist/advanced/prime-list.d.ts +2 -0
  98. package/dist/advanced/prime-list.d.ts.map +1 -0
  99. package/dist/advanced/prime-list.js +14 -0
  100. package/dist/advanced/prime-list.js.map +1 -0
  101. package/dist/advanced/sqrt.d.ts +2 -0
  102. package/dist/advanced/sqrt.d.ts.map +1 -0
  103. package/dist/advanced/sqrt.js +6 -0
  104. package/dist/advanced/sqrt.js.map +1 -0
  105. package/dist/algebra/circle-area.d.ts +2 -0
  106. package/dist/algebra/circle-area.d.ts.map +1 -0
  107. package/dist/algebra/circle-area.js +4 -0
  108. package/dist/algebra/circle-area.js.map +1 -0
  109. package/dist/algebra/distance.d.ts +2 -0
  110. package/dist/algebra/distance.d.ts.map +1 -0
  111. package/dist/algebra/distance.js +4 -0
  112. package/dist/algebra/distance.js.map +1 -0
  113. package/dist/algebra/midpoint.d.ts +2 -0
  114. package/dist/algebra/midpoint.d.ts.map +1 -0
  115. package/dist/algebra/midpoint.js +4 -0
  116. package/dist/algebra/midpoint.js.map +1 -0
  117. package/dist/algebra/slope.d.ts +2 -0
  118. package/dist/algebra/slope.d.ts.map +1 -0
  119. package/dist/algebra/slope.js +6 -0
  120. package/dist/algebra/slope.js.map +1 -0
  121. package/dist/algebra/solve-linear.d.ts +2 -0
  122. package/dist/algebra/solve-linear.d.ts.map +1 -0
  123. package/dist/algebra/solve-linear.js +6 -0
  124. package/dist/algebra/solve-linear.js.map +1 -0
  125. package/dist/algebra/solve-quadratic.d.ts +2 -0
  126. package/dist/algebra/solve-quadratic.d.ts.map +1 -0
  127. package/dist/algebra/solve-quadratic.js +12 -0
  128. package/dist/algebra/solve-quadratic.js.map +1 -0
  129. package/dist/algebra/triangle-area.d.ts +2 -0
  130. package/dist/algebra/triangle-area.d.ts.map +1 -0
  131. package/dist/algebra/triangle-area.js +5 -0
  132. package/dist/algebra/triangle-area.js.map +1 -0
  133. package/dist/arithmetic/add.d.ts +2 -0
  134. package/dist/arithmetic/add.d.ts.map +1 -0
  135. package/dist/arithmetic/add.js +4 -0
  136. package/dist/arithmetic/add.js.map +1 -0
  137. package/dist/arithmetic/ceil.d.ts +2 -0
  138. package/dist/arithmetic/ceil.d.ts.map +1 -0
  139. package/dist/arithmetic/ceil.js +4 -0
  140. package/dist/arithmetic/ceil.js.map +1 -0
  141. package/dist/arithmetic/clamp.d.ts +2 -0
  142. package/dist/arithmetic/clamp.d.ts.map +1 -0
  143. package/dist/arithmetic/clamp.js +4 -0
  144. package/dist/arithmetic/clamp.js.map +1 -0
  145. package/dist/arithmetic/divide.d.ts +2 -0
  146. package/dist/arithmetic/divide.d.ts.map +1 -0
  147. package/dist/arithmetic/divide.js +6 -0
  148. package/dist/arithmetic/divide.js.map +1 -0
  149. package/dist/arithmetic/floor.d.ts +2 -0
  150. package/dist/arithmetic/floor.d.ts.map +1 -0
  151. package/dist/arithmetic/floor.js +4 -0
  152. package/dist/arithmetic/floor.js.map +1 -0
  153. package/dist/arithmetic/modulo.d.ts +2 -0
  154. package/dist/arithmetic/modulo.d.ts.map +1 -0
  155. package/dist/arithmetic/modulo.js +4 -0
  156. package/dist/arithmetic/modulo.js.map +1 -0
  157. package/dist/arithmetic/multiply.d.ts +2 -0
  158. package/dist/arithmetic/multiply.d.ts.map +1 -0
  159. package/dist/arithmetic/multiply.js +4 -0
  160. package/dist/arithmetic/multiply.js.map +1 -0
  161. package/dist/arithmetic/percentage.d.ts +2 -0
  162. package/dist/arithmetic/percentage.d.ts.map +1 -0
  163. package/dist/arithmetic/percentage.js +4 -0
  164. package/dist/arithmetic/percentage.js.map +1 -0
  165. package/dist/arithmetic/round.d.ts +2 -0
  166. package/dist/arithmetic/round.d.ts.map +1 -0
  167. package/dist/arithmetic/round.js +5 -0
  168. package/dist/arithmetic/round.js.map +1 -0
  169. package/dist/arithmetic/subtract.d.ts +2 -0
  170. package/dist/arithmetic/subtract.d.ts.map +1 -0
  171. package/dist/arithmetic/subtract.js +4 -0
  172. package/dist/arithmetic/subtract.js.map +1 -0
  173. package/dist/cli.d.ts +3 -0
  174. package/dist/cli.d.ts.map +1 -0
  175. package/dist/cli.js +277 -0
  176. package/dist/cli.js.map +1 -0
  177. package/dist/convert/c-to-f.d.ts +2 -0
  178. package/dist/convert/c-to-f.d.ts.map +1 -0
  179. package/dist/convert/c-to-f.js +4 -0
  180. package/dist/convert/c-to-f.js.map +1 -0
  181. package/dist/convert/deg-to-rad.d.ts +2 -0
  182. package/dist/convert/deg-to-rad.d.ts.map +1 -0
  183. package/dist/convert/deg-to-rad.js +4 -0
  184. package/dist/convert/deg-to-rad.js.map +1 -0
  185. package/dist/convert/f-to-c.d.ts +2 -0
  186. package/dist/convert/f-to-c.d.ts.map +1 -0
  187. package/dist/convert/f-to-c.js +4 -0
  188. package/dist/convert/f-to-c.js.map +1 -0
  189. package/dist/convert/km-to-miles.d.ts +2 -0
  190. package/dist/convert/km-to-miles.d.ts.map +1 -0
  191. package/dist/convert/km-to-miles.js +4 -0
  192. package/dist/convert/km-to-miles.js.map +1 -0
  193. package/dist/convert/miles-to-km.d.ts +2 -0
  194. package/dist/convert/miles-to-km.d.ts.map +1 -0
  195. package/dist/convert/miles-to-km.js +4 -0
  196. package/dist/convert/miles-to-km.js.map +1 -0
  197. package/dist/convert/rad-to-deg.d.ts +2 -0
  198. package/dist/convert/rad-to-deg.d.ts.map +1 -0
  199. package/dist/convert/rad-to-deg.js +4 -0
  200. package/dist/convert/rad-to-deg.js.map +1 -0
  201. package/dist/index.d.ts +45 -0
  202. package/dist/index.d.ts.map +1 -0
  203. package/dist/index.js +45 -0
  204. package/dist/index.js.map +1 -0
  205. package/dist/random/random-array.d.ts +2 -0
  206. package/dist/random/random-array.d.ts.map +1 -0
  207. package/dist/random/random-array.js +4 -0
  208. package/dist/random/random-array.js.map +1 -0
  209. package/dist/random/random-float.d.ts +2 -0
  210. package/dist/random/random-float.d.ts.map +1 -0
  211. package/dist/random/random-float.js +4 -0
  212. package/dist/random/random-float.js.map +1 -0
  213. package/dist/random/random-from-array.d.ts +2 -0
  214. package/dist/random/random-from-array.d.ts.map +1 -0
  215. package/dist/random/random-from-array.js +4 -0
  216. package/dist/random/random-from-array.js.map +1 -0
  217. package/dist/random/random-int.d.ts +2 -0
  218. package/dist/random/random-int.d.ts.map +1 -0
  219. package/dist/random/random-int.js +4 -0
  220. package/dist/random/random-int.js.map +1 -0
  221. package/dist/statistics/mean.d.ts +2 -0
  222. package/dist/statistics/mean.d.ts.map +1 -0
  223. package/dist/statistics/mean.js +6 -0
  224. package/dist/statistics/mean.js.map +1 -0
  225. package/dist/statistics/median.d.ts +2 -0
  226. package/dist/statistics/median.d.ts.map +1 -0
  227. package/dist/statistics/median.js +8 -0
  228. package/dist/statistics/median.js.map +1 -0
  229. package/dist/statistics/mode.d.ts +2 -0
  230. package/dist/statistics/mode.d.ts.map +1 -0
  231. package/dist/statistics/mode.js +13 -0
  232. package/dist/statistics/mode.js.map +1 -0
  233. package/dist/statistics/product-array.d.ts +2 -0
  234. package/dist/statistics/product-array.d.ts.map +1 -0
  235. package/dist/statistics/product-array.js +4 -0
  236. package/dist/statistics/product-array.js.map +1 -0
  237. package/dist/statistics/range.d.ts +2 -0
  238. package/dist/statistics/range.d.ts.map +1 -0
  239. package/dist/statistics/range.js +6 -0
  240. package/dist/statistics/range.js.map +1 -0
  241. package/dist/statistics/std-dev.d.ts +2 -0
  242. package/dist/statistics/std-dev.d.ts.map +1 -0
  243. package/dist/statistics/std-dev.js +10 -0
  244. package/dist/statistics/std-dev.js.map +1 -0
  245. package/dist/statistics/sum-array.d.ts +2 -0
  246. package/dist/statistics/sum-array.d.ts.map +1 -0
  247. package/dist/statistics/sum-array.js +4 -0
  248. package/dist/statistics/sum-array.js.map +1 -0
  249. package/dist/statistics/variance.d.ts +2 -0
  250. package/dist/statistics/variance.d.ts.map +1 -0
  251. package/dist/statistics/variance.js +7 -0
  252. package/dist/statistics/variance.js.map +1 -0
  253. package/examples/advanced-examples.ts +31 -0
  254. package/examples/algebra-examples.ts +24 -0
  255. package/examples/arithmetic-examples.ts +24 -0
  256. package/examples/conversion-examples.ts +24 -0
  257. package/examples/statistics-examples.ts +29 -0
  258. package/hooks/use-mobile.ts +19 -0
  259. package/hooks/use-toast.ts +191 -0
  260. package/jest.config.js +15 -0
  261. package/lib/utils.ts +6 -0
  262. package/next.config.mjs +11 -0
  263. package/package.json +110 -0
  264. package/postcss.config.mjs +8 -0
  265. package/public/apple-icon.png +0 -0
  266. package/public/icon-dark-32x32.png +0 -0
  267. package/public/icon-light-32x32.png +0 -0
  268. package/public/icon.svg +26 -0
  269. package/public/placeholder-logo.png +0 -0
  270. package/public/placeholder-logo.svg +1 -0
  271. package/public/placeholder-user.jpg +0 -0
  272. package/public/placeholder.jpg +0 -0
  273. package/public/placeholder.svg +1 -0
  274. package/src/advanced/cube-root.ts +8 -0
  275. package/src/advanced/factorial.ts +12 -0
  276. package/src/advanced/fibonacci.ts +16 -0
  277. package/src/advanced/gcd.ts +14 -0
  278. package/src/advanced/lcm.ts +18 -0
  279. package/src/advanced/power.ts +9 -0
  280. package/src/advanced/prime-check.ts +14 -0
  281. package/src/advanced/prime-list.ts +16 -0
  282. package/src/advanced/sqrt.ts +9 -0
  283. package/src/algebra/circle-area.ts +8 -0
  284. package/src/algebra/distance.ts +11 -0
  285. package/src/algebra/midpoint.ts +11 -0
  286. package/src/algebra/slope.ts +12 -0
  287. package/src/algebra/solve-linear.ts +10 -0
  288. package/src/algebra/solve-quadratic.ts +15 -0
  289. package/src/algebra/triangle-area.ts +11 -0
  290. package/src/arithmetic/add.ts +9 -0
  291. package/src/arithmetic/ceil.ts +8 -0
  292. package/src/arithmetic/clamp.ts +10 -0
  293. package/src/arithmetic/divide.ts +11 -0
  294. package/src/arithmetic/floor.ts +8 -0
  295. package/src/arithmetic/modulo.ts +9 -0
  296. package/src/arithmetic/multiply.ts +9 -0
  297. package/src/arithmetic/percentage.ts +9 -0
  298. package/src/arithmetic/round.ts +10 -0
  299. package/src/arithmetic/subtract.ts +9 -0
  300. package/src/cli.ts +321 -0
  301. package/src/convert/c-to-f.ts +8 -0
  302. package/src/convert/deg-to-rad.ts +8 -0
  303. package/src/convert/f-to-c.ts +8 -0
  304. package/src/convert/km-to-miles.ts +8 -0
  305. package/src/convert/miles-to-km.ts +8 -0
  306. package/src/convert/rad-to-deg.ts +8 -0
  307. package/src/index.ts +49 -0
  308. package/src/random/random-array.ts +10 -0
  309. package/src/random/random-float.ts +9 -0
  310. package/src/random/random-from-array.ts +8 -0
  311. package/src/random/random-int.ts +9 -0
  312. package/src/statistics/mean.ts +9 -0
  313. package/src/statistics/median.ts +11 -0
  314. package/src/statistics/mode.ts +16 -0
  315. package/src/statistics/product-array.ts +8 -0
  316. package/src/statistics/range.ts +9 -0
  317. package/src/statistics/std-dev.ts +14 -0
  318. package/src/statistics/sum-array.ts +8 -0
  319. package/src/statistics/variance.ts +10 -0
  320. package/styles/globals.css +125 -0
  321. 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
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from 'clsx'
2
+ import { twMerge } from 'tailwind-merge'
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs))
6
+ }
@@ -0,0 +1,11 @@
1
+ /** @type {import('next').NextConfig} */
2
+ const nextConfig = {
3
+ typescript: {
4
+ ignoreBuildErrors: true,
5
+ },
6
+ images: {
7
+ unoptimized: true,
8
+ },
9
+ }
10
+
11
+ export default nextConfig
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
+ }
@@ -0,0 +1,8 @@
1
+ /** @type {import('postcss-load-config').Config} */
2
+ const config = {
3
+ plugins: {
4
+ '@tailwindcss/postcss': {},
5
+ },
6
+ }
7
+
8
+ export default config
Binary file
Binary file
Binary file
@@ -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,8 @@
1
+ /**
2
+ * Calculates cube root
3
+ * @param n - Number to find cube root of
4
+ * @returns Cube root of n
5
+ */
6
+ export function cubeRoot(n: number): number {
7
+ return Math.cbrt(n)
8
+ }
@@ -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,9 @@
1
+ /**
2
+ * Raises base to the power of exponent
3
+ * @param base - Base number
4
+ * @param exponent - Power
5
+ * @returns base^exponent
6
+ */
7
+ export function power(base: number, exponent: number): number {
8
+ return Math.pow(base, exponent)
9
+ }
@@ -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,9 @@
1
+ /**
2
+ * Calculates square root
3
+ * @param n - Number to find square root of
4
+ * @returns Square root of n
5
+ */
6
+ export function sqrt(n: number): number {
7
+ if (n < 0) throw new Error("Square root of negative number")
8
+ return Math.sqrt(n)
9
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculates area of circle
3
+ * @param radius - Circle radius
4
+ * @returns Area of circle
5
+ */
6
+ export function circleArea(radius: number): number {
7
+ return Math.PI * radius * radius
8
+ }
@@ -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,9 @@
1
+ /**
2
+ * Adds two numbers
3
+ * @param a - First number
4
+ * @param b - Second number
5
+ * @returns Sum of a and b
6
+ */
7
+ export function add(a: number, b: number): number {
8
+ return a + b
9
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Rounds up to nearest integer
3
+ * @param value - The number
4
+ * @returns Ceiling value
5
+ */
6
+ export function ceil(value: number): number {
7
+ return Math.ceil(value)
8
+ }
@@ -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
+ }