@library/math 0.0.0-stage → 0.0.8

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.
@@ -0,0 +1,205 @@
1
+ /* eslint-disable */
2
+ var addSorting = (function () {
3
+ "use strict";
4
+ var cols,
5
+ currentSort = {
6
+ index: 0,
7
+ desc: false,
8
+ };
9
+
10
+ // returns the summary table element
11
+ function getTable() {
12
+ return document.querySelector(".coverage-summary");
13
+ }
14
+ // returns the thead element of the summary table
15
+ function getTableHeader() {
16
+ return getTable().querySelector("thead tr");
17
+ }
18
+ // returns the tbody element of the summary table
19
+ function getTableBody() {
20
+ return getTable().querySelector("tbody");
21
+ }
22
+ // returns the th element for nth column
23
+ function getNthColumn(n) {
24
+ return getTableHeader().querySelectorAll("th")[n];
25
+ }
26
+
27
+ function onFilterInput() {
28
+ const searchValue = document.getElementById("fileSearch").value;
29
+ const rows = document.getElementsByTagName("tbody")[0].children;
30
+
31
+ // Try to create a RegExp from the searchValue. If it fails (invalid regex),
32
+ // it will be treated as a plain text search
33
+ let searchRegex;
34
+ try {
35
+ searchRegex = new RegExp(searchValue, "i"); // 'i' for case-insensitive
36
+ } catch (error) {
37
+ searchRegex = null;
38
+ }
39
+
40
+ for (let i = 0; i < rows.length; i++) {
41
+ const row = rows[i];
42
+ let isMatch = false;
43
+
44
+ if (searchRegex) {
45
+ // If a valid regex was created, use it for matching
46
+ isMatch = searchRegex.test(row.textContent);
47
+ } else {
48
+ // Otherwise, fall back to the original plain text search
49
+ isMatch = row.textContent.toLowerCase().includes(searchValue.toLowerCase());
50
+ }
51
+
52
+ row.style.display = isMatch ? "" : "none";
53
+ }
54
+ }
55
+
56
+ // loads the search box
57
+ function addSearchBox() {
58
+ var template = document.getElementById("filterTemplate");
59
+ var templateClone = template.content.cloneNode(true);
60
+ templateClone.getElementById("fileSearch").oninput = onFilterInput;
61
+ template.parentElement.appendChild(templateClone);
62
+ }
63
+
64
+ // loads all columns
65
+ function loadColumns() {
66
+ var colNodes = getTableHeader().querySelectorAll("th"),
67
+ colNode,
68
+ cols = [],
69
+ col,
70
+ i;
71
+
72
+ for (i = 0; i < colNodes.length; i += 1) {
73
+ colNode = colNodes[i];
74
+ col = {
75
+ key: colNode.getAttribute("data-col"),
76
+ sortable: !colNode.getAttribute("data-nosort"),
77
+ type: colNode.getAttribute("data-type") || "string",
78
+ };
79
+ cols.push(col);
80
+ if (col.sortable) {
81
+ col.defaultDescSort = col.type === "number";
82
+ colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
83
+ }
84
+ }
85
+ return cols;
86
+ }
87
+ // attaches a data attribute to every tr element with an object
88
+ // of data values keyed by column name
89
+ function loadRowData(tableRow) {
90
+ var tableCols = tableRow.querySelectorAll("td"),
91
+ colNode,
92
+ col,
93
+ data = {},
94
+ i,
95
+ val;
96
+ for (i = 0; i < tableCols.length; i += 1) {
97
+ colNode = tableCols[i];
98
+ col = cols[i];
99
+ val = colNode.getAttribute("data-value");
100
+ if (col.type === "number") {
101
+ val = Number(val);
102
+ }
103
+ data[col.key] = val;
104
+ }
105
+ return data;
106
+ }
107
+ // loads all row data
108
+ function loadData() {
109
+ var rows = getTableBody().querySelectorAll("tr"),
110
+ i;
111
+
112
+ for (i = 0; i < rows.length; i += 1) {
113
+ rows[i].data = loadRowData(rows[i]);
114
+ }
115
+ }
116
+ // sorts the table using the data for the ith column
117
+ function sortByIndex(index, desc) {
118
+ var key = cols[index].key,
119
+ sorter = function (a, b) {
120
+ a = a.data[key];
121
+ b = b.data[key];
122
+ return a < b ? -1 : a > b ? 1 : 0;
123
+ },
124
+ finalSorter = sorter,
125
+ tableBody = document.querySelector(".coverage-summary tbody"),
126
+ rowNodes = tableBody.querySelectorAll("tr"),
127
+ rows = [],
128
+ i;
129
+
130
+ if (desc) {
131
+ finalSorter = function (a, b) {
132
+ return -1 * sorter(a, b);
133
+ };
134
+ }
135
+
136
+ for (i = 0; i < rowNodes.length; i += 1) {
137
+ rows.push(rowNodes[i]);
138
+ tableBody.removeChild(rowNodes[i]);
139
+ }
140
+
141
+ rows.sort(finalSorter);
142
+
143
+ for (i = 0; i < rows.length; i += 1) {
144
+ tableBody.appendChild(rows[i]);
145
+ }
146
+ }
147
+ // removes sort indicators for current column being sorted
148
+ function removeSortIndicators() {
149
+ var col = getNthColumn(currentSort.index),
150
+ cls = col.className;
151
+
152
+ cls = cls.replace(/ sorted$/, "").replace(/ sorted-desc$/, "");
153
+ col.className = cls;
154
+ }
155
+ // adds sort indicators for current column being sorted
156
+ function addSortIndicators() {
157
+ getNthColumn(currentSort.index).className += currentSort.desc ? " sorted-desc" : " sorted";
158
+ }
159
+ // adds event listeners for all sorter widgets
160
+ function enableUI() {
161
+ var i,
162
+ el,
163
+ ithSorter = function ithSorter(i) {
164
+ var col = cols[i];
165
+
166
+ return function () {
167
+ var desc = col.defaultDescSort;
168
+
169
+ if (currentSort.index === i) {
170
+ desc = !currentSort.desc;
171
+ }
172
+ sortByIndex(i, desc);
173
+ removeSortIndicators();
174
+ currentSort.index = i;
175
+ currentSort.desc = desc;
176
+ addSortIndicators();
177
+ };
178
+ };
179
+ for (i = 0; i < cols.length; i += 1) {
180
+ if (cols[i].sortable) {
181
+ // add the click event handler on the th so users
182
+ // dont have to click on those tiny arrows
183
+ el = getNthColumn(i).querySelector(".sorter").parentElement;
184
+ if (el.addEventListener) {
185
+ el.addEventListener("click", ithSorter(i));
186
+ } else {
187
+ el.attachEvent("onclick", ithSorter(i));
188
+ }
189
+ }
190
+ }
191
+ }
192
+ // adds sorting functionality to the UI
193
+ return function () {
194
+ if (!getTable()) {
195
+ return;
196
+ }
197
+ cols = loadColumns();
198
+ loadData();
199
+ addSearchBox();
200
+ addSortIndicators();
201
+ enableUI();
202
+ };
203
+ })();
204
+
205
+ window.addEventListener("load", addSorting);
@@ -0,0 +1,21 @@
1
+ TN:
2
+ SF:src/clamp.ts
3
+ FN:15,clamp
4
+ FNF:1
5
+ FNH:1
6
+ FNDA:5,clamp
7
+ DA:16,5
8
+ LF:1
9
+ LH:1
10
+ BRF:0
11
+ BRH:0
12
+ end_of_record
13
+ TN:
14
+ SF:src/index.ts
15
+ FNF:0
16
+ FNH:0
17
+ LF:0
18
+ LH:0
19
+ BRF:0
20
+ BRH:0
21
+ end_of_record
@@ -0,0 +1 @@
1
+ "use strict";var t=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(r,m)=>{for(var n in m)t(r,n,{get:m[n],enumerable:!0})},x=(r,m,n,u)=>{if(m&&typeof m=="object"||typeof m=="function")for(let e of o(m))!p.call(r,e)&&e!==n&&t(r,e,{get:()=>m[e],enumerable:!(u=b(m,e))||u.enumerable});return r};var f=r=>x(t({},"__esModule",{value:!0}),r);var h={};c(h,{clamp:()=>a});module.exports=f(h);function a(r,m,n){return Math.min(Math.max(r,m),n)}0&&(module.exports={clamp});
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @param {number} value The number to clamp.
3
+ * @param {number} min The lower bound.
4
+ * @param {number} max The upper bound.
5
+ * @returns {number} The clamped number.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * clamp(5, 0, 10); // 5
10
+ * clamp(-5, 0, 10); // 0
11
+ * clamp(15, 0, 10); // 10
12
+ * ```
13
+ */
14
+ declare function clamp(value: number, min: number, max: number): number;
15
+
16
+ export { clamp };
@@ -0,0 +1 @@
1
+ function e(n,m,r){return Math.min(Math.max(n,m),r)}export{e as a};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @param {number} value The number to clamp.
3
+ * @param {number} min The lower bound.
4
+ * @param {number} max The upper bound.
5
+ * @returns {number} The clamped number.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * clamp(5, 0, 10); // 5
10
+ * clamp(-5, 0, 10); // 0
11
+ * clamp(15, 0, 10); // 10
12
+ * ```
13
+ */
14
+ declare function clamp(value: number, min: number, max: number): number;
15
+
16
+ export { clamp };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-KIYOP373.js";export{a as clamp};
@@ -0,0 +1 @@
1
+ export { clamp } from './clamp.js';
@@ -0,0 +1 @@
1
+ import{a as m}from"./chunk-KIYOP373.js";export{m as clamp};
package/llms.txt ADDED
@@ -0,0 +1,42 @@
1
+ <!-- Generated by `yarn docs`. Do not edit by hand. -->
2
+ # @library/math
3
+
4
+ > A collection of math utilities for TypeScript.
5
+
6
+ Install:
7
+
8
+ ```console
9
+ npm install @library/math
10
+ ```
11
+
12
+ All exports are named ESM/CJS exports, importable as:
13
+
14
+ ```ts
15
+ import { clamp } from "@library/math";
16
+ ```
17
+
18
+ ## API
19
+
20
+ ### clamp
21
+
22
+ Clamp a number between a lower and upper bound.
23
+
24
+ ```ts
25
+ function clamp(value: number, min: number, max: number): number
26
+ ```
27
+
28
+ Parameters:
29
+
30
+ - `value`: The number to clamp.
31
+ - `min`: The lower bound.
32
+ - `max`: The upper bound.
33
+
34
+ Returns: The clamped number.
35
+
36
+ Example:
37
+
38
+ ```ts
39
+ clamp(5, 0, 10); // 5
40
+ clamp(-5, 0, 10); // 0
41
+ clamp(15, 0, 10); // 10
42
+ ```
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@library/math",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.8",
4
+ "description": "A collection of math utilities for TypeScript.",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "types": "./dist/cjs/index.d.cts",
8
+ "module": "./dist/esm/index.js",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/esm/index.d.ts",
13
+ "default": "./dist/esm/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/cjs/index.d.cts",
17
+ "default": "./dist/cjs/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "keywords": [
22
+ "math",
23
+ "typescript",
24
+ "utility"
25
+ ],
26
+ "homepage": "https://github.com/yeonjuan/library/tree/main/packages/math#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/yeonjuan/library/issues"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/yeonjuan/library.git",
33
+ "directory": "packages/math"
34
+ },
35
+ "license": "MIT",
36
+ "scripts": {
37
+ "build": "rimraf dist && tsup --tsconfig tsconfig.build.json",
38
+ "test": "vitest run"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "gitHead": "fea3f714ec98af5ce58621c53734e44a62f881df"
44
+ }
@@ -0,0 +1,13 @@
1
+ import { clamp } from "./clamp";
2
+
3
+ describe("clamp", () => {
4
+ test.each([
5
+ [5, 0, 10, 5],
6
+ [-5, 0, 10, 0],
7
+ [15, 0, 10, 10],
8
+ [0, 0, 10, 0],
9
+ [10, 0, 10, 10],
10
+ ])("clamp(%i, %i, %i) = %i", (value, min, max, expected) => {
11
+ expect(clamp(value, min, max)).toBe(expected);
12
+ });
13
+ });
package/src/clamp.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Clamp a number between a lower and upper bound.
3
+ * @param {number} value The number to clamp.
4
+ * @param {number} min The lower bound.
5
+ * @param {number} max The upper bound.
6
+ * @returns {number} The clamped number.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * clamp(5, 0, 10); // 5
11
+ * clamp(-5, 0, 10); // 0
12
+ * clamp(15, 0, 10); // 10
13
+ * ```
14
+ */
15
+ export function clamp(value: number, min: number, max: number): number {
16
+ return Math.min(Math.max(value, min), max);
17
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { clamp } from "./clamp.js";
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src/**/*"],
7
+ "exclude": ["**/*.spec.ts"]
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ const common = {
4
+ dts: true,
5
+ clean: true,
6
+ sourcemap: false,
7
+ skipNodeModulesBundle: true,
8
+ minify: true,
9
+ } as const;
10
+
11
+ export default defineConfig([
12
+ {
13
+ ...common,
14
+ format: ["cjs"],
15
+ target: ["es2016"],
16
+ outDir: "dist/cjs",
17
+ entry: ["src/index.ts"],
18
+ },
19
+ {
20
+ ...common,
21
+ format: ["esm"],
22
+ target: ["esnext"],
23
+ outDir: "dist/esm",
24
+ entry: ["src/**/*.ts", "!src/**/*.spec.ts"],
25
+ },
26
+ ]);
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import { baseConfig } from "../../vitest.config.base";
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ ...baseConfig,
7
+ },
8
+ });