voight-kampff-compactor 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/README.md +23 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.mjs +3 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# tsdown-starter
|
|
2
|
+
|
|
3
|
+
A starter for creating a TypeScript package.
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
- Install dependencies:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Run the unit tests:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run test
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Build the library:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run build
|
|
23
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface CompactorOptions {
|
|
3
|
+
includeFields?: string[] | null;
|
|
4
|
+
dateFields?: string[];
|
|
5
|
+
dateFormat?: "MMDD" | "YYYY-MM-DD";
|
|
6
|
+
arrayHandling?: "compact" | "count";
|
|
7
|
+
minAbbrevLength?: number;
|
|
8
|
+
intelligentAbbrev?: boolean;
|
|
9
|
+
includeLegend?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface CompactorConfig extends CompactorOptions {
|
|
12
|
+
includeFields: string[] | null;
|
|
13
|
+
dateFields: string[];
|
|
14
|
+
dateFormat: "MMDD" | "YYYY-MM-DD";
|
|
15
|
+
arrayHandling: "compact" | "count";
|
|
16
|
+
minAbbrevLength: number;
|
|
17
|
+
intelligentAbbrev: boolean;
|
|
18
|
+
includeLegend: boolean;
|
|
19
|
+
}
|
|
20
|
+
type JsonValue = string | number | boolean | null | undefined | Record<string, unknown> | JsonValue[];
|
|
21
|
+
declare function compactor(json: JsonValue | string, options?: CompactorOptions): string;
|
|
22
|
+
interface DecompactorOptions {
|
|
23
|
+
legend?: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
declare function decompactor(compressed: string, options?: DecompactorOptions): Record<string, unknown> | Record<string, unknown>[];
|
|
26
|
+
//#endregion
|
|
27
|
+
export { CompactorConfig, CompactorOptions, JsonValue, compactor, decompactor };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function e(e,t={}){let n=typeof e==`string`?JSON.parse(e):e,r={includeFields:t.includeFields??null,dateFields:t.dateFields??[`created_at`,`updated_at`,`timestamp`,`date`],dateFormat:t.dateFormat??`MMDD`,arrayHandling:t.arrayHandling??`compact`,minAbbrevLength:t.minAbbrevLength??1,intelligentAbbrev:t.intelligentAbbrev!==!1,includeLegend:t.includeLegend??!1,...t};function i(e){return e.split(`.`)}function a(e){if(!r.includeFields)return!0;let t=e.join(`.`);return r.includeFields.includes(t)?!0:r.includeFields.some(n=>i(n).slice(0,e.length).join(`.`)===t)}function o(e){if(!r.includeFields)return!0;let t=e.join(`.`);return r.includeFields.includes(t)}function s(e,t=[]){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(e=>typeof e==`object`&&e?s(e,t):e);let n={};for(let[r,i]of Object.entries(e)){let e=[...t,r];if(a(e)){if(o(e))if(typeof i==`object`&&i){let t=s(i,e);((Array.isArray(t)?t.length>0:t&&typeof t==`object`&&Object.keys(t).length>0)||!Array.isArray(t)&&typeof t!=`object`)&&(n[r]=t)}else n[r]=i;else if(typeof i==`object`&&i){let t=s(i,e);(Array.isArray(t)?t.length>0:t&&typeof t==`object`&&Object.keys(t).length>0)&&(n[r]=t)}}}return n}let c=new Map,l=new Map;function u(e,t=0){if(!(typeof e!=`object`||!e)){if(Array.isArray(e)){e.forEach(e=>u(e,t));return}Object.keys(e).forEach(n=>{c.set(n,(c.get(n)||0)+1),u(e[n],t+1)})}}let d=r.includeFields?s(n):n;u(d);let f=Array.from(c.entries()).sort((e,t)=>t[1]===e[1]?t[0].length-e[0].length:t[1]-e[1]).map(([e])=>e);function p(e,t){let n=e[0].toLowerCase();if(!t.has(n)||e.length>1&&(n=(e[0]+e[e.length-1]).toLowerCase(),!t.has(n)))return n;let i=e.replace(/[aeiou]/gi,``);if(i.length>=r.minAbbrevLength&&(n=i.slice(0,Math.max(2,r.minAbbrevLength)).toLowerCase(),!t.has(n)))return n;let a=e.match(/[A-Z]/g);if(a&&a.length>0&&(n=a.join(``).toLowerCase(),!t.has(n))||e.includes(`_`)&&(n=e.split(`_`).map(e=>e[0]).join(``).toLowerCase(),!t.has(n)))return n;let o=r.minAbbrevLength;for(;o<=e.length;){if(n=e.slice(0,o).toLowerCase(),!t.has(n))return n;o++}let s=2;for(n=e.slice(0,Math.max(1,r.minAbbrevLength)).toLowerCase();t.has(`${n}${s}`);)s++;return`${n}${s}`}let m=new Set;f.forEach(e=>{let t=p(e,m);l.set(e,t),m.add(t)});function h(e,t=0){return e==null?``:typeof e==`boolean`?e?`1`:`0`:typeof e==`number`?e.toString():typeof e==`string`?e.match(/^\d{4}-\d{2}-\d{2}/)?g(e):e.length>100&&t>2?e.slice(0,97)+`...`:e:Array.isArray(e)?_(e,t):typeof e==`object`?v(e,t):String(e)}function g(e){let t=new Date(e);return r.dateFormat===`MMDD`?`${String(t.getMonth()+1).padStart(2,`0`)}${String(t.getDate()).padStart(2,`0`)}`:(r.dateFormat,e.split(`T`)[0])}function _(e,t){if(e.length===0)return`[]`;if(r.arrayHandling===`count`)return`[${e.length}]`;if(e.every(e=>typeof e!=`object`||!e))return e.map(e=>h(e,t+1)).join(`,`);let n=e.map((e,n)=>typeof e==`object`&&e?v(e,t+1):h(e,t+1));return t===0?n.join(`
|
|
2
|
+
`):n.join(`|`)}function v(e,t=0){let n=[];for(let[r,i]of Object.entries(e)){let e=l.get(r)||r,a=h(i,t+1);a!==``&&n.push(`${e}:${a}`)}return n.join(`|`)}let y;return y=Array.isArray(d)?_(d,0):v(d),r.includeLegend?`# ${Array.from(l.entries()).sort((e,t)=>e[1].localeCompare(t[1])).map(([e,t])=>`${t}=${e}`).join(` `)}\n${y}`:y}function t(e,t={}){let n=e.split(`
|
|
3
|
+
`),r={},i=0;n[0]&&n[0].startsWith(`#`)?(n[0].slice(1).trim().split(` `).forEach(e=>{let[t,n]=e.split(`=`);r[t]=n}),i=1):t.legend&&(r=t.legend);function a(e){let t={};return e.split(`|`).forEach(e=>{let n=e.indexOf(`:`);if(n===-1)return;let i=e.slice(0,n),a=e.slice(n+1),s=r[i]||i;t[s]=o(a)}),t}function o(e){return e===`1`?!0:e===`0`?!1:e===`[]`?[]:!isNaN(Number(e))&&e!==``?Number(e):e.includes(`:`)?a(e):e.includes(`|`)?e.split(`|`).map(o):e.includes(`,`)?e.split(`,`).map(o):e}let s=n.slice(i).filter(e=>e.trim());return s.length===1?a(s[0]):s.map(e=>a(e))}export{e as compactor,t as decompactor};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "voight-kampff-compactor",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Convert GitHub events into a compact strings optimized for LLM efficiency",
|
|
5
|
+
"homepage": "https://github.com/matteogabriele/voight-kampff-compactor#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/matteogabriele/voight-kampff-compactor/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Matteo Gabriele <m.gabriele.dev@gmail.com>",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/matteogabriele/voight-kampff-compactor.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.mjs",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vp pack",
|
|
25
|
+
"dev": "vp pack --watch",
|
|
26
|
+
"test": "vp test",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"release": "bumpp",
|
|
29
|
+
"prepublishOnly": "pnpm run build"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^25.5.0",
|
|
33
|
+
"@typescript/native-preview": "7.0.0-dev.20260316.1",
|
|
34
|
+
"bumpp": "^11.0.1",
|
|
35
|
+
"publint": "^0.3.18",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vite-plus": "latest",
|
|
38
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
39
|
+
},
|
|
40
|
+
"packageManager": "pnpm@10.33.0",
|
|
41
|
+
"pnpm": {
|
|
42
|
+
"overrides": {
|
|
43
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
|
44
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|