@utilix-tech/sdk 0.2.0 → 0.3.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.
@@ -0,0 +1,130 @@
1
+ 'use strict';
2
+
3
+ // src/tools/media.ts
4
+ function readU32BE(bytes, offset) {
5
+ return (bytes[offset] << 24 | bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3]) >>> 0;
6
+ }
7
+ function readI32LE(bytes, offset) {
8
+ return bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24;
9
+ }
10
+ var PNG_COLOR_TYPES = {
11
+ 0: "grayscale",
12
+ 2: "rgb",
13
+ 3: "palette",
14
+ 4: "grayscale+alpha",
15
+ 6: "rgba"
16
+ };
17
+ function readPng(bytes) {
18
+ if (bytes.length < 33) return { error: "Truncated PNG file" };
19
+ const width = readU32BE(bytes, 16);
20
+ const height = readU32BE(bytes, 20);
21
+ const bitDepth = bytes[24];
22
+ const colorTypeNum = bytes[25];
23
+ const colorType = PNG_COLOR_TYPES[colorTypeNum] ?? "unknown";
24
+ const hasAlpha = colorTypeNum === 4 || colorTypeNum === 6;
25
+ return { format: "png", width, height, bitDepth, colorType, hasAlpha };
26
+ }
27
+ function readGif(bytes) {
28
+ if (bytes.length < 10) return { error: "Truncated GIF file" };
29
+ const width = bytes[6] | bytes[7] << 8;
30
+ const height = bytes[8] | bytes[9] << 8;
31
+ return { format: "gif", width, height };
32
+ }
33
+ function readBmp(bytes) {
34
+ if (bytes.length < 30) return { error: "Truncated BMP file" };
35
+ const width = readI32LE(bytes, 18);
36
+ const heightRaw = readI32LE(bytes, 22);
37
+ const bitDepth = bytes[28] | bytes[29] << 8;
38
+ return { format: "bmp", width: Math.abs(width), height: Math.abs(heightRaw), bitDepth };
39
+ }
40
+ function readWebp(bytes) {
41
+ if (bytes.length < 16) return { error: "Truncated WebP file" };
42
+ const fourCC = String.fromCharCode(bytes[12], bytes[13], bytes[14], bytes[15]);
43
+ if (fourCC === "VP8 ") {
44
+ if (bytes.length < 30) return { error: "Truncated WebP file" };
45
+ const width = (bytes[26] | bytes[27] << 8) & 16383;
46
+ const height = (bytes[28] | bytes[29] << 8) & 16383;
47
+ return { format: "webp", width, height };
48
+ }
49
+ if (fourCC === "VP8L") {
50
+ if (bytes.length < 25) return { error: "Truncated WebP file" };
51
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
52
+ const width = (bits & 16383) + 1;
53
+ const height = (bits >>> 14 & 16383) + 1;
54
+ const hasAlpha = !!(bits >>> 28 & 1);
55
+ return { format: "webp", width, height, hasAlpha };
56
+ }
57
+ if (fourCC === "VP8X") {
58
+ if (bytes.length < 30) return { error: "Truncated WebP file" };
59
+ const flags = bytes[20];
60
+ const hasAlpha = !!(flags & 16);
61
+ const width = (bytes[24] | bytes[25] << 8 | bytes[26] << 16) + 1;
62
+ const height = (bytes[27] | bytes[28] << 8 | bytes[29] << 16) + 1;
63
+ return { format: "webp", width, height, hasAlpha };
64
+ }
65
+ return { error: "Unrecognized WebP chunk format" };
66
+ }
67
+ var JPEG_SOF_MARKERS = /* @__PURE__ */ new Set([
68
+ 192,
69
+ 193,
70
+ 194,
71
+ 195,
72
+ 197,
73
+ 198,
74
+ 199,
75
+ 201,
76
+ 202,
77
+ 203,
78
+ 205,
79
+ 206,
80
+ 207
81
+ ]);
82
+ function readJpeg(bytes) {
83
+ let offset = 2;
84
+ while (offset < bytes.length - 1) {
85
+ if (bytes[offset] !== 255) {
86
+ offset++;
87
+ continue;
88
+ }
89
+ const marker = bytes[offset + 1];
90
+ if (marker === 216 || marker === 1 || marker >= 208 && marker <= 215) {
91
+ offset += 2;
92
+ continue;
93
+ }
94
+ if (marker === 217) break;
95
+ if (offset + 3 >= bytes.length) break;
96
+ const segmentLength = bytes[offset + 2] << 8 | bytes[offset + 3];
97
+ if (JPEG_SOF_MARKERS.has(marker)) {
98
+ if (offset + 9 >= bytes.length) return { error: "Truncated JPEG SOF segment" };
99
+ const bitDepth = bytes[offset + 4];
100
+ const height = bytes[offset + 5] << 8 | bytes[offset + 6];
101
+ const width = bytes[offset + 7] << 8 | bytes[offset + 8];
102
+ const components = bytes[offset + 9];
103
+ const colorType = components === 1 ? "grayscale" : components === 3 ? "rgb" : components === 4 ? "cmyk" : "unknown";
104
+ return { format: "jpeg", width, height, bitDepth, colorType };
105
+ }
106
+ offset += 2 + segmentLength;
107
+ }
108
+ return { error: "No SOF marker found in JPEG (file may be corrupt)" };
109
+ }
110
+ function readImageInfo(bytes) {
111
+ if (bytes.length < 10) return { error: "File too small to determine format" };
112
+ if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10) {
113
+ return readPng(bytes);
114
+ }
115
+ if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70) {
116
+ return readGif(bytes);
117
+ }
118
+ if (bytes[0] === 66 && bytes[1] === 77) {
119
+ return readBmp(bytes);
120
+ }
121
+ if (bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70 && bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80) {
122
+ return readWebp(bytes);
123
+ }
124
+ if (bytes[0] === 255 && bytes[1] === 216) {
125
+ return readJpeg(bytes);
126
+ }
127
+ return { error: "Unrecognized image format \u2014 supported: PNG, JPEG, GIF, WebP, BMP" };
128
+ }
129
+
130
+ exports.readImageInfo = readImageInfo;
@@ -0,0 +1 @@
1
+ export { I as ImageFormat, a as ImageInfo, b as ImageInfoError, r as readImageInfo } from '../media-DF2cx3pK.cjs';
@@ -0,0 +1 @@
1
+ export { I as ImageFormat, a as ImageInfo, b as ImageInfoError, r as readImageInfo } from '../media-DF2cx3pK.js';
@@ -0,0 +1,2 @@
1
+ export { readImageInfo } from '../chunk-T3JTY2M5.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -2167,6 +2167,171 @@ function getMorseTiming(morse) {
2167
2167
  }
2168
2168
  return result;
2169
2169
  }
2170
+ var BE_VERBS = /* @__PURE__ */ new Set(["am", "is", "are", "was", "were", "be", "been", "being"]);
2171
+ var IRREGULAR_PARTICIPLES = /* @__PURE__ */ new Set([
2172
+ "awoken",
2173
+ "been",
2174
+ "become",
2175
+ "begun",
2176
+ "bent",
2177
+ "bet",
2178
+ "bitten",
2179
+ "bled",
2180
+ "blown",
2181
+ "born",
2182
+ "bought",
2183
+ "bound",
2184
+ "bred",
2185
+ "broken",
2186
+ "brought",
2187
+ "built",
2188
+ "burnt",
2189
+ "burst",
2190
+ "caught",
2191
+ "chosen",
2192
+ "clung",
2193
+ "come",
2194
+ "cost",
2195
+ "crept",
2196
+ "cut",
2197
+ "dealt",
2198
+ "dived",
2199
+ "done",
2200
+ "drawn",
2201
+ "dreamt",
2202
+ "driven",
2203
+ "drunk",
2204
+ "dug",
2205
+ "eaten",
2206
+ "fallen",
2207
+ "fed",
2208
+ "felt",
2209
+ "fit",
2210
+ "fled",
2211
+ "flown",
2212
+ "forbidden",
2213
+ "forgiven",
2214
+ "forgotten",
2215
+ "fought",
2216
+ "found",
2217
+ "frozen",
2218
+ "given",
2219
+ "gone",
2220
+ "gotten",
2221
+ "grown",
2222
+ "hidden",
2223
+ "held",
2224
+ "hung",
2225
+ "hurt",
2226
+ "kept",
2227
+ "knelt",
2228
+ "knit",
2229
+ "known",
2230
+ "laid",
2231
+ "lain",
2232
+ "led",
2233
+ "left",
2234
+ "lent",
2235
+ "let",
2236
+ "lit",
2237
+ "lost",
2238
+ "made",
2239
+ "meant",
2240
+ "met",
2241
+ "mistaken",
2242
+ "paid",
2243
+ "proven",
2244
+ "put",
2245
+ "quit",
2246
+ "read",
2247
+ "rid",
2248
+ "ridden",
2249
+ "risen",
2250
+ "run",
2251
+ "said",
2252
+ "sat",
2253
+ "sawn",
2254
+ "seen",
2255
+ "sent",
2256
+ "set",
2257
+ "sewn",
2258
+ "shaken",
2259
+ "shed",
2260
+ "shone",
2261
+ "shot",
2262
+ "shown",
2263
+ "shrunk",
2264
+ "shut",
2265
+ "sold",
2266
+ "sought",
2267
+ "sown",
2268
+ "spent",
2269
+ "spoken",
2270
+ "spread",
2271
+ "sprung",
2272
+ "stolen",
2273
+ "stood",
2274
+ "stuck",
2275
+ "stung",
2276
+ "struck",
2277
+ "strung",
2278
+ "sung",
2279
+ "sunk",
2280
+ "swept",
2281
+ "sworn",
2282
+ "swum",
2283
+ "swung",
2284
+ "taken",
2285
+ "taught",
2286
+ "thought",
2287
+ "thrown",
2288
+ "told",
2289
+ "torn",
2290
+ "understood",
2291
+ "upset",
2292
+ "woken",
2293
+ "won",
2294
+ "worn",
2295
+ "wound",
2296
+ "woven",
2297
+ "written"
2298
+ ]);
2299
+ function isPastParticiple(word) {
2300
+ const w = word.toLowerCase();
2301
+ if (IRREGULAR_PARTICIPLES.has(w)) return true;
2302
+ return w.length > 3 && /^[a-z]+ed$/.test(w);
2303
+ }
2304
+ function splitIntoSentences(text) {
2305
+ const matches = text.match(/[^.!?]+[.!?]*/g);
2306
+ if (!matches) return [];
2307
+ return matches.map((s) => s.trim()).filter((s) => s.length > 0);
2308
+ }
2309
+ function detectPassiveVoice(text) {
2310
+ const sentences = splitIntoSentences(text);
2311
+ const analyzed = sentences.map((sentence, index) => {
2312
+ const words = sentence.match(/[a-zA-Z']+/g) ?? [];
2313
+ const matches = [];
2314
+ for (let i = 0; i < words.length; i++) {
2315
+ if (!BE_VERBS.has(words[i].toLowerCase())) continue;
2316
+ let j = i + 1;
2317
+ let adverbCount = 0;
2318
+ while (j < words.length && adverbCount < 2 && /ly$/i.test(words[j]) && !isPastParticiple(words[j])) {
2319
+ j++;
2320
+ adverbCount++;
2321
+ }
2322
+ if (j < words.length && isPastParticiple(words[j])) {
2323
+ const hasAgent = words.slice(j + 1, j + 5).some((w) => w.toLowerCase() === "by");
2324
+ matches.push({ phrase: words.slice(i, j + 1).join(" "), hasAgent });
2325
+ i = j;
2326
+ }
2327
+ }
2328
+ return { index, text: sentence, isPassive: matches.length > 0, matches };
2329
+ });
2330
+ const totalSentences = analyzed.length;
2331
+ const passiveSentences = analyzed.filter((s) => s.isPassive).length;
2332
+ const passivePercent = totalSentences > 0 ? Math.round(passiveSentences / totalSentences * 1e3) / 10 : 0;
2333
+ return { sentences: analyzed, totalSentences, passiveSentences, passivePercent };
2334
+ }
2170
2335
 
2171
2336
  exports.CASE_FORMATS = CASE_FORMATS;
2172
2337
  exports.DEFAULT_CONVERT_OPTIONS = DEFAULT_CONVERT_OPTIONS;
@@ -2184,6 +2349,7 @@ exports.countWords = countWords;
2184
2349
  exports.csvToHtml = csvToHtml;
2185
2350
  exports.csvToMarkdown = csvToMarkdown;
2186
2351
  exports.detectDelimiter = detectDelimiter;
2352
+ exports.detectPassiveVoice = detectPassiveVoice;
2187
2353
  exports.diffLines = diffLines;
2188
2354
  exports.diffLinesSimple = diffLinesSimple;
2189
2355
  exports.diffStats = diffStats;
@@ -1 +1 @@
1
- export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, R as ReadabilityScore, S as SlugSeparator, T as TableOptions, q as TextAnalysis, W as WordCountResult, r as addBorder, s as analyzeText, u as applyOp, v as applyOps, w as centerText, x as convertAll, y as convertCase, z as countWords, B as csvToHtml, F as csvToMarkdown, G as detectDelimiter, H as diffLines, I as diffLinesSimple, J as diffStats, K as escapeAll, N as escapeString, O as extractHeadings, Q as formatReadingTime, U as generate, V as generateDiff, X as generateHtmlTable, Y as generateMarkdownTable, Z as generateParagraphs, _ as generateSentences, $ as generateWords, a0 as getAvailableFonts, a1 as getMorseForChar, a2 as getMorseTiming, a3 as htmlToMarkdown, a4 as isValidMorse, a5 as markdownToHtml, a6 as morseToText, a7 as numberToOrdinal, a8 as numberToRoman, a9 as numberToWords, aa as ordinalWords, ab as parseDiff, ac as parseTableData, ad as readabilityScore, ae as renderMarkdown, af as romanToNumber, ag as sentenceCount, ah as slugify, ai as slugifyAll, aj as syllableCount, ak as textToAscii, al as textToMorse, am as unescapeString, an as wordFrequency } from '../text-DqAjPtQ0.cjs';
1
+ export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, q as PassiveVoiceMatch, r as PassiveVoiceResult, s as PassiveVoiceSentence, R as ReadabilityScore, S as SlugSeparator, T as TableOptions, u as TextAnalysis, W as WordCountResult, v as addBorder, w as analyzeText, x as applyOp, y as applyOps, z as centerText, B as convertAll, F as convertCase, G as countWords, H as csvToHtml, I as csvToMarkdown, J as detectDelimiter, K as detectPassiveVoice, N as diffLines, O as diffLinesSimple, Q as diffStats, U as escapeAll, V as escapeString, X as extractHeadings, Y as formatReadingTime, Z as generate, _ as generateDiff, $ as generateHtmlTable, a0 as generateMarkdownTable, a1 as generateParagraphs, a2 as generateSentences, a3 as generateWords, a4 as getAvailableFonts, a5 as getMorseForChar, a6 as getMorseTiming, a7 as htmlToMarkdown, a8 as isValidMorse, a9 as markdownToHtml, aa as morseToText, ab as numberToOrdinal, ac as numberToRoman, ad as numberToWords, ae as ordinalWords, af as parseDiff, ag as parseTableData, ah as readabilityScore, ai as renderMarkdown, aj as romanToNumber, ak as sentenceCount, al as slugify, am as slugifyAll, an as syllableCount, ao as textToAscii, ap as textToMorse, aq as unescapeString, ar as wordFrequency } from '../text-CI7JAl7F.cjs';
@@ -1 +1 @@
1
- export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, R as ReadabilityScore, S as SlugSeparator, T as TableOptions, q as TextAnalysis, W as WordCountResult, r as addBorder, s as analyzeText, u as applyOp, v as applyOps, w as centerText, x as convertAll, y as convertCase, z as countWords, B as csvToHtml, F as csvToMarkdown, G as detectDelimiter, H as diffLines, I as diffLinesSimple, J as diffStats, K as escapeAll, N as escapeString, O as extractHeadings, Q as formatReadingTime, U as generate, V as generateDiff, X as generateHtmlTable, Y as generateMarkdownTable, Z as generateParagraphs, _ as generateSentences, $ as generateWords, a0 as getAvailableFonts, a1 as getMorseForChar, a2 as getMorseTiming, a3 as htmlToMarkdown, a4 as isValidMorse, a5 as markdownToHtml, a6 as morseToText, a7 as numberToOrdinal, a8 as numberToRoman, a9 as numberToWords, aa as ordinalWords, ab as parseDiff, ac as parseTableData, ad as readabilityScore, ae as renderMarkdown, af as romanToNumber, ag as sentenceCount, ah as slugify, ai as slugifyAll, aj as syllableCount, ak as textToAscii, al as textToMorse, am as unescapeString, an as wordFrequency } from '../text-DqAjPtQ0.js';
1
+ export { A as AsciiFont, a as AsciiOptions, C as CASE_FORMATS, b as CaseFormat, c as ConvertOptions, D as DEFAULT_CONVERT_OPTIONS, d as DiffFile, e as DiffHunk, f as DiffLine, g as DiffResult, h as DiffType, i as DiffViewerLine, E as ESCAPE_MODES, j as EscapeMode, L as LINE_OPS, k as LineOp, l as LineType, m as LoremUnit, M as MORSE_CODE, n as MarkdownResult, o as MorseOptions, P as ParsedDiff, p as ParsedTable, q as PassiveVoiceMatch, r as PassiveVoiceResult, s as PassiveVoiceSentence, R as ReadabilityScore, S as SlugSeparator, T as TableOptions, u as TextAnalysis, W as WordCountResult, v as addBorder, w as analyzeText, x as applyOp, y as applyOps, z as centerText, B as convertAll, F as convertCase, G as countWords, H as csvToHtml, I as csvToMarkdown, J as detectDelimiter, K as detectPassiveVoice, N as diffLines, O as diffLinesSimple, Q as diffStats, U as escapeAll, V as escapeString, X as extractHeadings, Y as formatReadingTime, Z as generate, _ as generateDiff, $ as generateHtmlTable, a0 as generateMarkdownTable, a1 as generateParagraphs, a2 as generateSentences, a3 as generateWords, a4 as getAvailableFonts, a5 as getMorseForChar, a6 as getMorseTiming, a7 as htmlToMarkdown, a8 as isValidMorse, a9 as markdownToHtml, aa as morseToText, ab as numberToOrdinal, ac as numberToRoman, ad as numberToWords, ae as ordinalWords, af as parseDiff, ag as parseTableData, ah as readabilityScore, ai as renderMarkdown, aj as romanToNumber, ak as sentenceCount, al as slugify, am as slugifyAll, an as syllableCount, ao as textToAscii, ap as textToMorse, aq as unescapeString, ar as wordFrequency } from '../text-CI7JAl7F.js';
@@ -1,2 +1,2 @@
1
- export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, diffLines, diffLinesSimple, diffStats, escapeAll, escapeString, extractHeadings, formatReadingTime, generate, generateDiff, generateHtmlTable, generateMarkdownTable, generateParagraphs, generateSentences, generateWords, getAvailableFonts, getMorseForChar, getMorseTiming, htmlToMarkdown, isValidMorse, markdownToHtml, morseToText, numberToOrdinal, numberToRoman, numberToWords, ordinalWords, parseDiff, parseTableData, readabilityScore, renderMarkdown, romanToNumber, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, unescapeString, wordFrequency } from '../chunk-XXYZLLHI.js';
1
+ export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectPassiveVoice, diffLines, diffLinesSimple, diffStats, escapeAll, escapeString, extractHeadings, formatReadingTime, generate, generateDiff, generateHtmlTable, generateMarkdownTable, generateParagraphs, generateSentences, generateWords, getAvailableFonts, getMorseForChar, getMorseTiming, htmlToMarkdown, isValidMorse, markdownToHtml, morseToText, numberToOrdinal, numberToRoman, numberToWords, ordinalWords, parseDiff, parseTableData, readabilityScore, renderMarkdown, romanToNumber, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, unescapeString, wordFrequency } from '../chunk-YBBYFAOV.js';
2
2
  import '../chunk-MLKGABMK.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utilix-tech/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "100+ developer utility tools for Node.js — JSON, encoding, hashing, color, CSS, network and more. Runs locally, no API key required.",
5
5
  "author": "Utilix <hello@utilix.tech>",
6
6
  "license": "MIT",
@@ -105,6 +105,11 @@
105
105
  "import": "./dist/tools/ai_agent.js",
106
106
  "require": "./dist/tools/ai_agent.cjs",
107
107
  "types": "./dist/tools/ai_agent.d.ts"
108
+ },
109
+ "./media": {
110
+ "import": "./dist/tools/media.js",
111
+ "require": "./dist/tools/media.cjs",
112
+ "types": "./dist/tools/media.d.ts"
108
113
  }
109
114
  },
110
115
  "files": [