@riotprompt/riotprompt 0.0.3 → 0.0.4

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.
@@ -13,7 +13,7 @@ export * as Loader from './loader';
13
13
  export * as Override from './override';
14
14
  export * as Builder from './builder';
15
15
  export * as Recipes from './recipes';
16
- export { cook, commit, release, documentation, review, quick, recipe, configureTemplates, getTemplates } from './recipes';
16
+ export { cook, recipe, registerTemplates, getTemplates, clearTemplates } from './recipes';
17
17
  export type { Content } from './items/content';
18
18
  export type { Context } from './items/context';
19
19
  export type { Instruction } from './items/instruction';
@@ -20,5 +20,5 @@ import * as builder from './builder.js';
20
20
  export { builder as Builder };
21
21
  import * as recipes from './recipes.js';
22
22
  export { recipes as Recipes };
23
- export { commit, configureTemplates, cook, documentation, getTemplates, quick, recipe, release, review } from './recipes.js';
23
+ export { clearTemplates, cook, getTemplates, recipe, registerTemplates } from './recipes.js';
24
24
  //# sourceMappingURL=riotprompt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"general.js","sources":["../../src/util/general.ts"],"sourcesContent":["export const clean = (obj: any) => {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, v]) => v !== undefined)\n );\n}\n\n//Recursive implementation of jSON.stringify;\nexport const stringifyJSON = function (obj: any, visited: Set<any> = new Set()): string {\n const arrOfKeyVals: string[] = [];\n const arrVals: string[] = [];\n let objKeys: string[] = [];\n\n /*********CHECK FOR PRIMITIVE TYPES**********/\n if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null)\n return '' + obj;\n else if (typeof obj === 'string')\n return '\"' + obj + '\"';\n\n /*********DETECT CIRCULAR REFERENCES**********/\n if (obj instanceof Object && visited.has(obj)) {\n return '\"(circular)\"';\n }\n\n /*********CHECK FOR ARRAY**********/\n else if (Array.isArray(obj)) {\n //check for empty array\n if (obj[0] === undefined)\n return '[]';\n else {\n // Add array to visited before processing its elements\n visited.add(obj);\n obj.forEach(function (el) {\n arrVals.push(stringifyJSON(el, visited));\n });\n return '[' + arrVals + ']';\n }\n }\n /*********CHECK FOR OBJECT**********/\n else if (obj instanceof Object) {\n // Add object to visited before processing its properties\n visited.add(obj);\n //get object keys\n objKeys = Object.keys(obj);\n //set key output;\n objKeys.forEach(function (key) {\n const keyOut = '\"' + key + '\":';\n const keyValOut = obj[key];\n //skip functions and undefined properties\n if (keyValOut instanceof Function || keyValOut === undefined)\n return; // Skip this entry entirely instead of pushing an empty string\n else if (typeof keyValOut === 'string')\n arrOfKeyVals.push(keyOut + '\"' + keyValOut + '\"');\n else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null)\n arrOfKeyVals.push(keyOut + keyValOut);\n //check for nested objects, call recursively until no more objects\n else if (keyValOut instanceof Object) {\n arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));\n }\n });\n return '{' + arrOfKeyVals + '}';\n }\n return '';\n};"],"names":["clean","obj","Object","fromEntries","entries","filter","_","v","undefined","stringifyJSON","visited","Set","arrOfKeyVals","arrVals","objKeys","has","Array","isArray","add","forEach","el","push","keys","key","keyOut","keyValOut","Function"],"mappings":"AAAO,MAAMA,QAAQ,CAACC,GAAAA,GAAAA;AAClB,IAAA,OAAOC,MAAAA,CAAOC,WAAW,CACrBD,MAAAA,CAAOE,OAAO,CAACH,GAAAA,CAAAA,CAAKI,MAAM,CAAC,CAAC,CAACC,CAAAA,EAAGC,CAAAA,CAAE,GAAKA,CAAAA,KAAMC,SAAAA,CAAAA,CAAAA;AAErD;AAEA;MACaC,aAAAA,GAAgB,SAAUR,GAAQ,EAAES,OAAAA,GAAoB,IAAIC,GAAAA,EAAK,EAAA;AAC1E,IAAA,MAAMC,eAAyB,EAAE;AACjC,IAAA,MAAMC,UAAoB,EAAE;AAC5B,IAAA,IAAIC,UAAoB,EAAE;mDAG1B,IAAI,OAAOb,GAAAA,KAAQ,QAAA,IAAY,OAAOA,GAAAA,KAAQ,SAAA,IAAaA,GAAAA,KAAQ,IAAA,EAC/D,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KAAc,QAAA,IAAYA,SAAAA,KAAc,IAAA,EACtFb,YAAAA,CAAaS,IAAI,CAACG,MAAAA,GAASC,SAAAA,CAAAA;AAE1B,iBAAA,IAAIA,qBAAqBvB,MAAAA,EAAQ;AAClCU,gBAAAA,YAAAA,CAAaS,IAAI,CAACG,MAAAA,GAASf,aAAAA,CAAcgB,SAAAA,EAAWf,OAAAA,CAAAA,CAAAA;AACxD;AACJ,SAAA,CAAA;AACA,QAAA,OAAO,MAAME,YAAAA,GAAe,GAAA;AAChC;IACA,OAAO,EAAA;AACX;;;;"}
1
+ {"version":3,"file":"general.js","sources":["../../src/util/general.ts"],"sourcesContent":["export const clean = (obj: any) => {\n return Object.fromEntries(\n Object.entries(obj).filter(([_, v]) => v !== undefined)\n );\n}\n\n//Recursive implementation of jSON.stringify;\nexport const stringifyJSON = function (obj: any, visited: Set<any> = new Set()): string {\n const arrOfKeyVals: string[] = [];\n const arrVals: string[] = [];\n let objKeys: string[] = [];\n\n /*********CHECK FOR PRIMITIVE TYPES**********/\n if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null)\n return '' + obj;\n else if (typeof obj === 'string')\n return '\"' + obj + '\"';\n\n /*********DETECT CIRCULAR REFERENCES**********/\n if (obj instanceof Object && visited.has(obj)) {\n return '\"(circular)\"';\n }\n\n /*********CHECK FOR ARRAY**********/\n else if (Array.isArray(obj)) {\n //check for empty array\n if (obj[0] === undefined)\n return '[]';\n else {\n // Add array to visited before processing its elements\n visited.add(obj);\n obj.forEach(function (el) {\n arrVals.push(stringifyJSON(el, visited));\n });\n return '[' + arrVals + ']';\n }\n }\n /*********CHECK FOR OBJECT**********/\n else if (obj instanceof Object) {\n // Add object to visited before processing its properties\n visited.add(obj);\n //get object keys\n objKeys = Object.keys(obj);\n //set key output;\n objKeys.forEach(function (key) {\n const keyOut = '\"' + key + '\":';\n const keyValOut = obj[key];\n //skip functions and undefined properties\n if (keyValOut instanceof Function || keyValOut === undefined)\n return; // Skip this entry entirely instead of pushing an empty string\n else if (typeof keyValOut === 'string')\n arrOfKeyVals.push(keyOut + '\"' + keyValOut + '\"');\n else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null)\n arrOfKeyVals.push(keyOut + keyValOut);\n //check for nested objects, call recursively until no more objects\n else if (keyValOut instanceof Object) {\n arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));\n }\n });\n return '{' + arrOfKeyVals + '}';\n }\n return '';\n};"],"names":["clean","obj","Object","fromEntries","entries","filter","_","v","undefined","stringifyJSON","visited","Set","arrOfKeyVals","arrVals","objKeys","has","Array","isArray","add","forEach","el","push","keys","key","keyOut","keyValOut","Function"],"mappings":"AAAO,MAAMA,QAAQ,CAACC,GAAAA,GAAAA;AAClB,IAAA,OAAOC,MAAAA,CAAOC,WAAW,CACrBD,MAAAA,CAAOE,OAAO,CAACH,GAAAA,CAAAA,CAAKI,MAAM,CAAC,CAAC,CAACC,CAAAA,EAAGC,CAAAA,CAAE,GAAKA,CAAAA,KAAMC,SAAAA,CAAAA,CAAAA;AAErD;AAEA;MACaC,aAAAA,GAAgB,SAAUR,GAAQ,EAAES,OAAAA,GAAoB,IAAIC,GAAAA,EAAK,EAAA;AAC1E,IAAA,MAAMC,eAAyB,EAAE;AACjC,IAAA,MAAMC,UAAoB,EAAE;AAC5B,IAAA,IAAIC,UAAoB,EAAE;mDAG1B,IAAI,OAAOb,GAAAA,KAAQ,QAAA,IAAY,OAAOA,GAAAA,KAAQ,SAAA,IAAaA,GAAAA,KAAQ,IAAA,EAC/D,OAAO,EAAA,GAAKA,GAAAA;AACX,SAAA,IAAI,OAAOA,GAAAA,KAAQ,QAAA,EACpB,OAAO,MAAMA,GAAAA,GAAM,GAAA;AAEvB,oDACA,IAAIA,GAAAA,YAAeC,UAAUQ,OAAAA,CAAQK,GAAG,CAACd,GAAAA,CAAAA,EAAM;QAC3C,OAAO,cAAA;AACX,IAAA,CAAA,MAGK,IAAIe,KAAAA,CAAMC,OAAO,CAAChB,GA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ACxD,YAAA;AACJ,QAAA,CAAA,CAAA;AACA,QAAA,OAAO,MAAME,YAAAA,GAAe,GAAA;AAChC,IAAA;IACA,OAAO,EAAA;AACX;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","sources":["../../src/util/markdown.ts"],"sourcesContent":["import { DEFAULT_CHARACTER_ENCODING } from \"../constants\";\n\n// Heuristic to check for Markdown syntax. This is not a full parser.\n// It looks for common Markdown patterns.\nconst markdownRegex = /^(#+\\s|\\*\\s|-\\s|\\+\\s|>\\s|\\[.*\\]\\(.*\\)|```|~~~|---\\\\s*$)/m;\n\n/**\n * Inspects a string to see if it likely contains Markdown syntax.\n *\n * @param input The string or Buffer content to inspect.\n * @returns True if Markdown syntax is suspected, false otherwise.\n */\nexport function isMarkdown(input: string | Buffer): boolean {\n if (input == null) {\n return false;\n }\n // Convert Buffer to string if necessary\n const content = typeof input === 'string' ? input : input.toString(DEFAULT_CHARACTER_ENCODING);\n if (!content || content.trim() === '') {\n return false; // Empty string is not considered Markdown\n }\n\n // Check for common Markdown patterns in the entire content\n if (markdownRegex.test(content)) {\n return true;\n }\n\n // Fallback: Check for a high prevalence of Markdown-like list/header starters\n // or thematic breaks, or code blocks.\n // We'll consider up to the first ~2000 characters, roughly equivalent to the byte check.\n const effectiveContent = content.length > 2000 ? content.substring(0, 2000) : content;\n const lines = effectiveContent.split('\\n');\n let markdownFeatureCount = 0;\n const featurePatterns = [\n /^#+\\s+.+/, // Headers (e.g., # Heading)\n /^\\s*[*+-]\\s+.+/, // List items (e.g., * item, - item, + item)\n /^\\s*>\\s+.+/, // Blockquotes (e.g., > quote)\n /\\[.+\\]\\(.+\\)/, // Links (e.g., [text](url))\n /!\\[.+\\]\\(.+\\)/, // Images (e.g., ![alt](src))\n /`{1,3}[^`]+`{1,3}/, // Inline code (e.g., `code`) or code blocks (```code```)\n /^\\s*_{3,}\\s*$/, // Thematic breaks (e.g., ---, ***, ___)\n /^\\s*-{3,}\\s*$/,\n /^\\s*\\*{3,}\\s*$/\n ];\n\n for (const line of lines) {\n // Stop checking if we have already found enough features to be confident.\n // This is a small optimization for very long inputs that are clearly markdown early on.\n if (markdownFeatureCount >= 2 && lines.length > 10) { // Heuristic threshold\n const significantLineCountEarly = Math.min(lines.indexOf(line) + 1, 20);\n if (significantLineCountEarly > 0 && markdownFeatureCount / significantLineCountEarly > 0.1) {\n return true;\n }\n }\n\n for (const pattern of featurePatterns) {\n if (pattern.test(line.trim())) {\n markdownFeatureCount++;\n break; // Count each line only once\n }\n }\n }\n\n // If more than 5% of the first few lines (up to 20 lines or all lines if fewer)\n // show markdown features, or if there are at least 2 distinct features in short texts,\n // consider it Markdown.\n const significantLineCount = Math.min(lines.length, 20);\n if (significantLineCount > 0) {\n // Calculate the exact threshold percentage\n const thresholdPercentage = markdownFeatureCount / significantLineCount;\n\n // Check against the 5% threshold (0.05)\n // Using >= 0.05 exactly matches 5%, > 0.05 requires more than 5%\n if (thresholdPercentage >= 0.05 + 0.0001) { // Adding a small epsilon to ensure exactly 5% passes but just below fails\n return true;\n }\n\n // Other conditions for returning true\n if ((markdownFeatureCount >= 1 && significantLineCount <= 5) || markdownFeatureCount >= 2) {\n return true;\n }\n }\n\n return false;\n}\n\n// Example usage (optional, for testing):\n// function testIsMarkdownString() {\n// console.log('--- Testing isMarkdownString ---');\n// const markdown1 = '# Hello World\\\\nThis is a test.';\n// console.log(`Test 1 (Header): \"${markdown1.substring(0,10)}...\" -> ${isMarkdownString(markdown1)}`); // true\n\n// const markdown2 = '* Item 1\\\\n* Item 2';\n// console.log(`Test 2 (List): \"${markdown2.substring(0,10)}...\" -> ${isMarkdownString(markdown2)}`); // true\n\n// const markdown3 = '[Google](https://google.com)';\n// console.log(`Test 3 (Link): \"${markdown3.substring(0,15)}...\" -> ${isMarkdownString(markdown3)}`); // true\n\n// const markdown4 = '> This is a quote.';\n// console.log(`Test 4 (Blockquote): \"${markdown4.substring(0,10)}...\" -> ${isMarkdownString(markdown4)}`); // true\n\n// const markdown5 = '```javascript\\\\nconsole.log(\"hello\");\\\\n```';\n// console.log(`Test 5 (Code block): \"${markdown5.substring(0,15)}...\" -> ${isMarkdownString(markdown5)}`); // true\n\n// const text1 = 'This is a plain text string.';\n// console.log(`Test 6 (Plain text): \"${text1.substring(0,10)}...\" -> ${isMarkdownString(text1)}`); // false\n\n// const text2 = 'hello_world.this_is_a_test_string_with_underscores_but_not_markdown_thematic_break';\n// console.log(`Test 7 (Long non-markdown): \"${text2.substring(0,10)}...\" -> ${isMarkdownString(text2)}`); // false\n\n// const text3 = '<xml><tag>value</tag></xml>';\n// console.log(`Test 8 (XML): \"${text3.substring(0,10)}...\" -> ${isMarkdownString(text3)}`); // false\n\n// const shortMarkdown = '# H';\n// console.log(`Test 9 (Short Markdown): \"${shortMarkdown}\" -> ${isMarkdownString(shortMarkdown)}`); // true\n\n// const shortNonMarkdown = 'Hello';\n// console.log(`Test 10 (Short Non-Markdown): \"${shortNonMarkdown}\" -> ${isMarkdownString(shortNonMarkdown)}`); // false\n\n// const emptyString = '';\n// console.log(`Test 11 (Empty string): \"\" -> ${isMarkdownString(emptyString)}`); // false\n\n// const whitespaceString = ' \\t \\n ';\n// console.log(`Test 12 (Whitespace string): \"${whitespaceString.substring(0,5)}...\" -> ${isMarkdownString(whitespaceString)}`); // false\n\n// const markdownWithManyFeatures = `# Title\\\\n\\\\n* list\\\\n* list2\\\\n\\\\n> quote here\\\\n\\\\n\\`\\`\\`\\\\ncode\\\\n\\`\\`\\`\\\\n\\\\nnormal text paragraph with a [link](url).\\n---\\nAnother paragraph.\\nThis is just a test string to see how it performs with multiple markdown features present.\\nHello world this is a very long line that does not contain any markdown syntax at all, it is just plain text that goes on and on.\\n* Another list item\\n* And another one\\n# Another Header\\n## Subheader\\nThis is fun.\\nOkay I think this is enough.\\nFinal line.\\nAnother final line.\\nOne more for good measure.\\nOkay that should be enough lines to test the early exit.\\n`;\n// console.log(`Test 13 (Many Features): \"${markdownWithManyFeatures.substring(0,10)}...\" -> ${isMarkdownString(markdownWithManyFeatures)}`); // true\n\n// const htmlLike = '<div><p>Hello</p><ul><li>item</li></ul></div>';\n// console.log(`Test 14 (HTML-like): \"${htmlLike.substring(0,10)}...\" -> ${isMarkdownString(htmlLike)}`); // false\n\n// console.log('--- End Testing ---');\n// }\n\n// testIsMarkdownString();\n"],"names":["markdownRegex","isMarkdown","input","content","toString","DEFAULT_CHARACTER_ENCODING","trim","test","effectiveContent","length","substring","lines","split","markdownFeatureCount","featurePatterns","line","significantLineCountEarly","Math","min","indexOf","pattern","significantLineCount","thresholdPercentage"],"mappings":";;AAEA;AACA;AACA,MAAMA,aAAAA,GAAgB,0DAAA;AAEtB;;;;;IAMO,SAASC,UAAAA,CAAWC,KAAsB,EAAA;AAC7C,IAAA,IAAIA,SAAS,IAAA,EAAM;QACf,OAAO,KAAA;AACX;;AAEA,IAAA,MAAMC,UAAU,OAAOD,KAAAA,KAAU,WAAWA,KAAAA,GAAQA,KAAAA,CAAME,QAAQ,CAACC,0BAAAA,CAAAA;AACnE,IAAA,IAAI,CAACF,OAAAA,IAAWA,OAAAA,CAAQG,IAAI,OAAO,EAAA,EAAI;AACnC,QAAA,OAAO;AACX;;IAGA,IAAIN,aAAAA,CAAcO,IAAI,CAACJ,OAAAA,CAAAA,EAAU;QAC7B,OAAO,IAAA;AACX;;;;IAKA,MAAMK,gBAAAA,GAAmBL,QAAQM,MAAM,GAAG,OAAON,OAAAA,CAAQO,SAAS,CAAC,CAAA,EAAG,IAAA,CAAA,GAAQP,OAAAA;IAC9E,MAAMQ,KAAAA,GAAQH,gBAAAA,CAAiBI,KAAK,CAAC,IAAA,CAAA;AACrC,IAAA,IAAIC,oBAAAA,GAAuB,CAAA;AAC3B,IAAA,MAAMC,eAAAA,GAAkB;AACpB,QAAA,UAAA;AACA,QAAA,gBAAA;AACA,QAAA,YAAA;AACA,QAAA,cAAA;AACA,QAAA,eAAA;AACA,QAAA,mBAAA;AACA,QAAA,eAAA;AACA,QAAA,eAAA;AACA,QAAA;AACH,KAAA;IAED,KAAK,MAAMC,QAAQJ,KAAAA,CAAO;;;AAGtB,QAAA,IAAIE,oBAAAA,IAAwB,CAAA,IAAKF,KAAAA,CAAMF,MAAM,GAAG,EAAA,EAAI;YAChD,MAAMO,yBAAAA,GAA4BC,KAAKC,GAAG,CAACP,MAAMQ,OAAO,CAACJ,QAAQ,CAAA,EAAG,EAAA,CAAA;AACpE,YAAA,IAAIC,yBAAAA,GAA4B,CAAA,IAAKH,oBAAAA,GAAuBG,yBAAAA,GAA4B,GAAA,EAAK;gBACzF,OAAO,IAAA;AACX;AACJ;QAEA,KAAK,MAAMI,WAAWN,eAAAA,CAAiB;AACnC,YAAA,IAAIM,OAAAA,CAAQb,IAAI,CAACQ,IAAAA,CAAKT,IAAI,EAAA,CAAA,EAAK;AAC3BO,gBAAAA,oBAAAA,EAAAA;AACA,gBAAA,MAAA;AACJ;AACJ;AACJ;;;;AAKA,IAAA,MAAMQ,uBAAuBJ,IAAAA,CAAKC,GAAG,CAACP,KAAAA,CAAMF,MAAM,EAAE,EAAA,CAAA;AACpD,IAAA,IAAIY,uBAAuB,CAAA,EAAG;;AAE1B,QAAA,MAAMC,sBAAsBT,oBAAAA,GAAuBQ,oBAAAA;;;QAInD,IAAIC,mBAAAA,IAAuB,OAAO,MAAA,EAAQ;YACtC,OAAO,IAAA;AACX;;AAGA,QAAA,IAAI,oBAACT,IAAwB,CAAA,IAAKQ,oBAAAA,IAAwB,CAAA,IAAMR,wBAAwB,CAAA,EAAG;YACvF,OAAO,IAAA;AACX;AACJ;IAEA,OAAO,KAAA;AACX,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"markdown.js","sources":["../../src/util/markdown.ts"],"sourcesContent":["import { DEFAULT_CHARACTER_ENCODING } from \"../constants\";\n\n// Heuristic to check for Markdown syntax. This is not a full parser.\n// It looks for common Markdown patterns.\nconst markdownRegex = /^(#+\\s|\\*\\s|-\\s|\\+\\s|>\\s|\\[.*\\]\\(.*\\)|```|~~~|---\\\\s*$)/m;\n\n/**\n * Inspects a string to see if it likely contains Markdown syntax.\n *\n * @param input The string or Buffer content to inspect.\n * @returns True if Markdown syntax is suspected, false otherwise.\n */\nexport function isMarkdown(input: string | Buffer): boolean {\n if (input == null) {\n return false;\n }\n // Convert Buffer to string if necessary\n const content = typeof input === 'string' ? input : input.toString(DEFAULT_CHARACTER_ENCODING);\n if (!content || content.trim() === '') {\n return false; // Empty string is not considered Markdown\n }\n\n // Check for common Markdown patterns in the entire content\n if (markdownRegex.test(content)) {\n return true;\n }\n\n // Fallback: Check for a high prevalence of Markdown-like list/header starters\n // or thematic breaks, or code blocks.\n // We'll consider up to the first ~2000 characters, roughly equivalent to the byte check.\n const effectiveContent = content.length > 2000 ? content.substring(0, 2000) : content;\n const lines = effectiveContent.split('\\n');\n let markdownFeatureCount = 0;\n const featurePatterns = [\n /^#+\\s+.+/, // Headers (e.g., # Heading)\n /^\\s*[*+-]\\s+.+/, // List items (e.g., * item, - item, + item)\n /^\\s*>\\s+.+/, // Blockquotes (e.g., > quote)\n /\\[.+\\]\\(.+\\)/, // Links (e.g., [text](url))\n /!\\[.+\\]\\(.+\\)/, // Images (e.g., ![alt](src))\n /`{1,3}[^`]+`{1,3}/, // Inline code (e.g., `code`) or code blocks (```code```)\n /^\\s*_{3,}\\s*$/, // Thematic breaks (e.g., ---, ***, ___)\n /^\\s*-{3,}\\s*$/,\n /^\\s*\\*{3,}\\s*$/\n ];\n\n for (const line of lines) {\n // Stop checking if we have already found enough features to be confident.\n // This is a small optimization for very long inputs that are clearly markdown early on.\n if (markdownFeatureCount >= 2 && lines.length > 10) { // Heuristic threshold\n const significantLineCountEarly = Math.min(lines.indexOf(line) + 1, 20);\n if (significantLineCountEarly > 0 && markdownFeatureCount / significantLineCountEarly > 0.1) {\n return true;\n }\n }\n\n for (const pattern of featurePatterns) {\n if (pattern.test(line.trim())) {\n markdownFeatureCount++;\n break; // Count each line only once\n }\n }\n }\n\n // If more than 5% of the first few lines (up to 20 lines or all lines if fewer)\n // show markdown features, or if there are at least 2 distinct features in short texts,\n // consider it Markdown.\n const significantLineCount = Math.min(lines.length, 20);\n if (significantLineCount > 0) {\n // Calculate the exact threshold percentage\n const thresholdPercentage = markdownFeatureCount / significantLineCount;\n\n // Check against the 5% threshold (0.05)\n // Using >= 0.05 exactly matches 5%, > 0.05 requires more than 5%\n if (thresholdPercentage >= 0.05 + 0.0001) { // Adding a small epsilon to ensure exactly 5% passes but just below fails\n return true;\n }\n\n // Other conditions for returning true\n if ((markdownFeatureCount >= 1 && significantLineCount <= 5) || markdownFeatureCount >= 2) {\n return true;\n }\n }\n\n return false;\n}\n\n// Example usage (optional, for testing):\n// function testIsMarkdownString() {\n// console.log('--- Testing isMarkdownString ---');\n// const markdown1 = '# Hello World\\\\nThis is a test.';\n// console.log(`Test 1 (Header): \"${markdown1.substring(0,10)}...\" -> ${isMarkdownString(markdown1)}`); // true\n\n// const markdown2 = '* Item 1\\\\n* Item 2';\n// console.log(`Test 2 (List): \"${markdown2.substring(0,10)}...\" -> ${isMarkdownString(markdown2)}`); // true\n\n// const markdown3 = '[Google](https://google.com)';\n// console.log(`Test 3 (Link): \"${markdown3.substring(0,15)}...\" -> ${isMarkdownString(markdown3)}`); // true\n\n// const markdown4 = '> This is a quote.';\n// console.log(`Test 4 (Blockquote): \"${markdown4.substring(0,10)}...\" -> ${isMarkdownString(markdown4)}`); // true\n\n// const markdown5 = '```javascript\\\\nconsole.log(\"hello\");\\\\n```';\n// console.log(`Test 5 (Code block): \"${markdown5.substring(0,15)}...\" -> ${isMarkdownString(markdown5)}`); // true\n\n// const text1 = 'This is a plain text string.';\n// console.log(`Test 6 (Plain text): \"${text1.substring(0,10)}...\" -> ${isMarkdownString(text1)}`); // false\n\n// const text2 = 'hello_world.this_is_a_test_string_with_underscores_but_not_markdown_thematic_break';\n// console.log(`Test 7 (Long non-markdown): \"${text2.substring(0,10)}...\" -> ${isMarkdownString(text2)}`); // false\n\n// const text3 = '<xml><tag>value</tag></xml>';\n// console.log(`Test 8 (XML): \"${text3.substring(0,10)}...\" -> ${isMarkdownString(text3)}`); // false\n\n// const shortMarkdown = '# H';\n// console.log(`Test 9 (Short Markdown): \"${shortMarkdown}\" -> ${isMarkdownString(shortMarkdown)}`); // true\n\n// const shortNonMarkdown = 'Hello';\n// console.log(`Test 10 (Short Non-Markdown): \"${shortNonMarkdown}\" -> ${isMarkdownString(shortNonMarkdown)}`); // false\n\n// const emptyString = '';\n// console.log(`Test 11 (Empty string): \"\" -> ${isMarkdownString(emptyString)}`); // false\n\n// const whitespaceString = ' \\t \\n ';\n// console.log(`Test 12 (Whitespace string): \"${whitespaceString.substring(0,5)}...\" -> ${isMarkdownString(whitespaceString)}`); // false\n\n// const markdownWithManyFeatures = `# Title\\\\n\\\\n* list\\\\n* list2\\\\n\\\\n> quote here\\\\n\\\\n\\`\\`\\`\\\\ncode\\\\n\\`\\`\\`\\\\n\\\\nnormal text paragraph with a [link](url).\\n---\\nAnother paragraph.\\nThis is just a test string to see how it performs with multiple markdown features present.\\nHello world this is a very long line that does not contain any markdown syntax at all, it is just plain text that goes on and on.\\n* Another list item\\n* And another one\\n# Another Header\\n## Subheader\\nThis is fun.\\nOkay I think this is enough.\\nFinal line.\\nAnother final line.\\nOne more for good measure.\\nOkay that should be enough lines to test the early exit.\\n`;\n// console.log(`Test 13 (Many Features): \"${markdownWithManyFeatures.substring(0,10)}...\" -> ${isMarkdownString(markdownWithManyFeatures)}`); // true\n\n// const htmlLike = '<div><p>Hello</p><ul><li>item</li></ul></div>';\n// console.log(`Test 14 (HTML-like): \"${htmlLike.substring(0,10)}...\" -> ${isMarkdownString(htmlLike)}`); // false\n\n// console.log('--- End Testing ---');\n// }\n\n// testIsMarkdownString();\n"],"names":["markdownRegex","isMarkdown","input","content","toString","DEFAULT_CHARACTER_ENCODING","trim","test","effectiveContent","length","substring","lines","split","markdownFeatureCount","featurePatterns","line","significantLineCountEarly","Math","min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GAAuBG,yBAAAA,GAA4B,GAAA,EAAK;gBACzF,OAAO,IAAA;AACX,YAAA;AACJ,QAAA;QAEA,KAAK,MAAMI,WAAWN,eAAAA,CAAiB;AACnC,YAAA,IAAIM,OAAAA,CAAQb,IAAI,CAACQ,IAAAA,CAAKT,IAAI,EAAA,CAAA,EAAK;AAC3BO,gBAAAA,oBAAAA,EAAAA;AACA,gBAAA,MAAA;AACJ,YAAA;AACJ,QAAA;AACJ,IAAA;;;;AAKA,IAAA,MAAMQ,uBAAuBJ,IAAAA,CAAKC,GAAG,CAACP,KAAAA,CAAMF,MAAM,EAAE,EAAA,CAAA;AACpD,IAAA,IAAIY,uBAAuB,CAAA,EAAG;;AAE1B,QAAA,MAAMC,sBAAsBT,oBAAAA,GAAuBQ,oBAAAA;;;QAInD,IAAIC,mBAAAA,IAAuB,OAAO,MAAA,EAAQ;YACtC,OAAO,IAAA;AACX,QAAA;;AAGA,QAAA,IAAI,oBAACT,IAAwB,CAAA,IAAKQ,oBAAAA,IAAwB,CAAA,IAAMR,wBAAwB,CAAA,EAAG;YACvF,OAAO,IAAA;AACX,QAAA;AACJ,IAAA;IAEA,OAAO,KAAA;AACX,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage.js","sources":["../../src/util/storage.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string, limit?: number }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (\n directory: string,\n callback: (file: string) => Promise<void>,\n options: { pattern: string | string[], limit?: number } = { pattern: '*.*' },\n ): Promise<void> => {\n try {\n let filesProcessed = 0;\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n filesProcessed++;\n if (options.limit && filesProcessed >= options.limit) {\n log(`Reached limit of ${options.limit} files, stopping`);\n break;\n }\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}"],"names":["create","params","log","console","exists","path","fs","promises","stat","error","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","encoding","writeFile","data","forEachFileIn","directory","callback","options","pattern","filesProcessed","files","glob","cwd","nodir","file","join","limit","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir"],"mappings":";;;;;AAAA;AAgCO,MAAMA,SAAS,CAACC,MAAAA,GAAAA;;AAGnB,IAAA,MAAMC,GAAAA,GAAMD,MAAAA,CAAOC,GAAG,IAAIC,QAAQD,GAAG;AAErC,IAAA,MAAME,SAAS,OAAOC,IAAAA,GAAAA;QAClB,IAAI;AACA,YAAA,MAAMC,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;YACvB,OAAO,IAAA;;AAEX,SAAA,CAAE,OAAOI,KAAAA,EAAY;YACjB,OAAO,KAAA;AACX;AACJ,KAAA;AAEA,IAAA,MAAMC,cAAc,OAAOL,IAAAA,GAAAA;AACvB,QAAA,MAAMM,QAAQ,MAAML,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;QACrC,IAAI,CAACM,KAAAA,CAAMD,WAAW,EAAA,EAAI;YACtBR,GAAAA,CAAI,CAAA,EAAGG,IAAAA,CAAK,mBAAmB,CAAC,CAAA;YAChC,OAAO,KAAA;AACX;QACA,OAAO,IAAA;AACX,KAAA;AAEA,IAAA,MAAMO,SAAS,OAAOP,IAAAA,GAAAA;AAClB,QAAA,MAAMM,QAAQ,MAAML,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;QACrC,IAAI,CAACM,KAAAA,CAAMC,MAAM,EAAA,EAAI;YACjBV,GAAAA,CAAI,CAAA,EAAGG,IAAAA,CAAK,cAAc,CAAC,CAAA;YAC3B,OAAO,KAAA;AACX;QACA,OAAO,IAAA;AACX,KAAA;AAEA,IAAA,MAAMQ,aAAa,OAAOR,IAAAA,GAAAA;QACtB,IAAI;YACA,MAAMC,EAAAA,CAAGC,QAAQ,CAACO,MAAM,CAACT,IAAAA,EAAMC,EAAAA,CAAGS,SAAS,CAACC,IAAI,CAAA;AACpD,SAAA,C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AA;AACAK,QAAAA,QAAAA;AACAkB,QAAAA,UAAAA;AACAhB,QAAAA,SAAAA;AACAE,QAAAA,aAAAA;AACAgB,QAAAA,QAAAA;AACAO,QAAAA;AACJ,KAAA;AACJ;;;;"}
1
+ {"version":3,"file":"storage.js","sources":["../../src/util/storage.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string, limit?: number }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (\n directory: string,\n callback: (file: string) => Promise<void>,\n options: { pattern: string | string[], limit?: number } = { pattern: '*.*' },\n ): Promise<void> => {\n try {\n let filesProcessed = 0;\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n filesProcessed++;\n if (options.limit && filesProcessed >= options.limit) {\n log(`Reached limit of ${options.limit} files, stopping`);\n break;\n }\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}"],"names":["create","params","log","console","exists","path","fs","promises","stat","error","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","encoding","writeFile","data","forEachFileIn","directory","callback","options","pattern","filesProcessed","files","glob","cwd","nodir","file","join","limit","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir"],"mappings":";;;;;AAAA;AAgCO,MAAMA,SAAS,CAACC,MAAAA,GAAAA;;AAGnB,IAAA,MAAMC,GAAAA,GAAMD,MAAAA,CAAOC,GAAG,IAAIC,QAAQD,GAAG;AAErC,IAAA,MAAME,SAAS,OAAOC,IAAAA,GAAAA;QAClB,IAAI;AACA,YAAA,MAAMC,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;YACvB,OAAO,IAAA;;AAEX,QAAA,CAAA,CAAE,OAAOI,KAAAA,EAAY;YACjB,OAAO,KAAA;AACX,QAAA;AACJ,IAAA,CAAA;AAEA,IAAA,MAAMC,cAAc,OAAOL,IAAAA,GAAAA;AACvB,QAAA,MAAMM,QAAQ,MAAML,EAAAA,CAAGC,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;QACrC,IAAI,CAACM,KAAAA,CAAMD,WAAW,EAAA,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AAAA;QACtB,OAAOC,EAAAA,CAAG0C,gBAAgB,CAAC3C,IAAAA,CAAAA;AAC/B,IAAA,CAAA;IAEA,MAAM4C,QAAAA,GAAW,OAAO5C,IAAAA,EAAc6C,MAAAA,GAAAA;QAClC,MAAMP,IAAAA,GAAO,MAAMd,QAAAA,CAASxB,IAAAA,EAAM,MAAA,CAAA;AAClC,QAAA,OAAO8C,MAAAA,CAAOC,UAAU,CAAC,QAAA,CAAA,CAAUC,MAAM,CAACV,IAAAA,CAAAA,CAAMW,MAAM,CAAC,KAAA,CAAA,CAAOC,KAAK,CAAC,CAAA,EAAGL,MAAAA,CAAAA;AAC3E,IAAA,CAAA;AAEA,IAAA,MAAMM,YAAY,OAAOtB,SAAAA,GAAAA;AACrB,QAAA,OAAO,MAAM5B,EAAAA,CAAGC,QAAQ,CAACkD,OAAO,CAACvB,SAAAA,CAAAA;AACrC,IAAA,CAAA;IAEA,OAAO;AACH9B,QAAAA,MAAAA;AACAM,QAAAA,WAAAA;AACAE,QAAAA,MAAAA;AACAC,QAAAA,UAAAA;AACAM,QAAAA,UAAAA;AACAE,QAAAA,cAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,eAAAA;AACAK,QAAAA,QAAAA;AACAkB,QAAAA,UAAAA;AACAhB,QAAAA,SAAAA;AACAE,QAAAA,aAAAA;AACAgB,QAAAA,QAAAA;AACAO,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sources":["../../src/util/text.ts"],"sourcesContent":["import { DEFAULT_CHARACTER_ENCODING } from \"../constants\";\n\n// Returns true if the input is likely text, false if likely binary\nexport function isText(input: string | Buffer): boolean {\n let buf: Buffer;\n if (typeof input === 'string') {\n buf = Buffer.from(input, DEFAULT_CHARACTER_ENCODING);\n } else {\n buf = input;\n }\n\n // Empty buffers are considered text\n if (buf.length === 0) {\n return true;\n }\n\n // If the buffer contains null bytes, it's likely binary\n if (buf.includes(0)) {\n return false;\n }\n\n // For UTF-8 encoded text (including emoji and international characters),\n // convert to string first and check if there are non-printable characters\n const str = buf.toString(DEFAULT_CHARACTER_ENCODING);\n\n // Count the number of non-printable ASCII characters (excluding common whitespace)\n let nonPrintable = 0;\n const len = Math.min(str.length, 512); // Only check the first 512 characters for performance\n\n for (let i = 0; i < len; i++) {\n const charCode = str.charCodeAt(i);\n // Allow: tab (9), line feed (10), carriage return (13), printable ASCII (32-126)\n // Also allow all non-ASCII Unicode characters (charCode > 127)\n if (\n charCode !== 9 && charCode !== 10 && charCode !== 13 &&\n (charCode < 32 || (charCode > 126 && charCode < 128))\n ) {\n nonPrintable++;\n }\n }\n\n // If more than 10% of the checked characters are non-printable, consider it binary\n return nonPrintable / len < 0.1;\n}\n"],"names":["isText","input","buf","Buffer","from","DEFAULT_CHARACTER_ENCODING","length","includes","str","toString","nonPrintable","len","Math","min","i","charCode","charCodeAt"],"mappings":";;AAEA;AACO,SAASA,OAAOC,KAAsB,EAAA;IACzC,IAAIC,GAAAA;IACJ,IAAI,OAAOD,UAAU,QAAA,EAAU;QAC3BC,GAAAA,GAAMC,MAAAA,CAAOC,IAAI,CAACH,KAAAA,EAAOI,0BAAAA,CAAAA;KAC7B,MAAO;QACHH,GAAAA,GAAMD,KAAAA;AACV;;IAGA,IAAIC,GAAAA,CAAII,MAAM,KAAK,CAAA,EAAG;QAClB,OAAO,IAAA;AACX;;IAGA,IAAIJ,GAAAA,CAAIK,QAAQ,CAAC,CAAA,CAAA,EAAI;QACjB,OAAO,KAAA;AACX;;;IAIA,MAAMC,GAAAA,GAAMN,GAAAA,CAAIO,QAAQ,CAACJ,0BAAAA,CAAAA;;AAGzB,IAAA,IAAIK,YAAAA,GAAe,CAAA;IACnB,MAAMC,GAAAA,GAAMC,KAAKC,GAAG,CAACL,IAAIF,MAAM,EAAE;AAEjC,IAAA,IAAK,IAAIQ,CAAAA,GAAI,CAAA,EAAGA,CAAAA,GAAIH,KAAKG,CAAAA,EAAAA,CAAK;QAC1B,MAAMC,QAAAA,GAAWP,GAAAA,CAAIQ,UAAU,CAACF,CAAAA,CAAAA;;;AAGhC,QAAA,IACIC,QAAAA,KAAa,CAAA,IAAKA,QAAAA,KAAa,EAAA,IAAMA,QAAAA,KAAa,EAAA,KACjDA,QAAAA,GAAW,EAAA,IAAOA,QAAAA,GAAW,GAAA,IAAOA,QAAAA,GAAW,GAAG,CAAA,EACrD;AACEL,YAAAA,YAAAA,EAAAA;AACJ;AACJ;;AAGA,IAAA,OAAOA,eAAeC,GAAAA,GAAM,GAAA;AAChC;;;;"}
1
+ {"version":3,"file":"text.js","sources":["../../src/util/text.ts"],"sourcesContent":["import { DEFAULT_CHARACTER_ENCODING } from \"../constants\";\n\n// Returns true if the input is likely text, false if likely binary\nexport function isText(input: string | Buffer): boolean {\n let buf: Buffer;\n if (typeof input === 'string') {\n buf = Buffer.from(input, DEFAULT_CHARACTER_ENCODING);\n } else {\n buf = input;\n }\n\n // Empty buffers are considered text\n if (buf.length === 0) {\n return true;\n }\n\n // If the buffer contains null bytes, it's likely binary\n if (buf.includes(0)) {\n return false;\n }\n\n // For UTF-8 encoded text (including emoji and international characters),\n // convert to string first and check if there are non-printable characters\n const str = buf.toString(DEFAULT_CHARACTER_ENCODING);\n\n // Count the number of non-printable ASCII characters (excluding common whitespace)\n let nonPrintable = 0;\n const len = Math.min(str.length, 512); // Only check the first 512 characters for performance\n\n for (let i = 0; i < len; i++) {\n const charCode = str.charCodeAt(i);\n // Allow: tab (9), line feed (10), carriage return (13), printable ASCII (32-126)\n // Also allow all non-ASCII Unicode characters (charCode > 127)\n if (\n charCode !== 9 && charCode !== 10 && charCode !== 13 &&\n (charCode < 32 || (charCode > 126 && charCode < 128))\n ) {\n nonPrintable++;\n }\n }\n\n // If more than 10% of the checked characters are non-printable, consider it binary\n return nonPrintable / len < 0.1;\n}\n"],"names":["isText","input","buf","Buffer","from","DEFAULT_CHARACTER_ENCODING","length","includes","str","toString","nonPrintable","len","Math","min","i","charCode","charCodeAt"],"mappings":";;AAEA;AACO,SAASA,OAAOC,KAAsB,EAAA;IACzC,IAAIC,GAAAA;IACJ,IAAI,OAAOD,UAAU,QAAA,EAAU;QAC3BC,GAAAA,GAAMC,MAAAA,CAAOC,IAAI,CAACH,KAAAA,EAAOI,0BAAAA,CAAAA;IAC7B,CAAA,MAAO;QACHH,GAAAA,GAAMD,KAAAA;AACV,IAAA;;IAGA,IAAIC,GAAAA,CAAII,MAAM,KAAK,CAAA,EAAG;QAClB,OAAO,IAAA;AACX,IAAA;;IAGA,IAAIJ,GAAAA,CAAIK,QAAQ,CAAC,CAAA,CAAA,EAAI;QACjB,OAAO,KAAA;AACX,IAAA;;;IAIA,MAAMC,GAAAA,GAAMN,GAAAA,CAAIO,QAAQ,CAACJ,0BAAAA,CAAAA;;AAGzB,IAAA,IAAIK,YAAAA,GAAe,CAAA;IACnB,MAAMC,GAAAA,GAAMC,KAAKC,GAAG,CAACL,IAAIF,MAAM,EAAE;AAEjC,IAAA,IAAK,IAAIQ,CAAAA,GAAI,CAAA,EAAGA,CAAAA,GAAIH,KAAKG,CAAAA,EAAAA,CAAK;QAC1B,MAAMC,QAAAA,GAAWP,GAAAA,CAAIQ,UAAU,CAACF,CAAAA,CAAAA;;;AAGhC,QAAA,IACIC,QAAAA,KAAa,CAAA,IAAKA,QAAAA,KAAa,EAAA,IAAMA,QAAAA,KAAa,EAAA,KACjDA,QAAAA,GAAW,EAAA,IAAOA,QAAAA,GAAW,GAAA,IAAOA,QAAAA,GAAW,GAAG,CAAA,EACrD;AACEL,YAAAA,YAAAA,EAAAA;AACJ,QAAA;AACJ,IAAA;;AAGA,IAAA,OAAOA,eAAeC,GAAAA,GAAM,GAAA;AAChC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riotprompt/riotprompt",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Get it together, and organize your prompts.",
5
5
  "type": "module",
6
6
  "main": "./dist/riotprompt.cjs",
@@ -48,7 +48,7 @@
48
48
  "minimatch": "^10.0.3",
49
49
  "rollup-plugin-preserve-shebang": "^1.0.1",
50
50
  "typescript": "^5.8.3",
51
- "vite": "^7.0.1",
51
+ "vite": "^7.0.2",
52
52
  "vite-plugin-dts": "^4.5.4",
53
53
  "vite-plugin-node": "^7.0.0",
54
54
  "vitest": "^3.2.4"
@@ -56,7 +56,7 @@
56
56
  "dependencies": {
57
57
  "glob": "^11.0.3",
58
58
  "marked": "^16.0.0",
59
- "zod": "^3.25.71"
59
+ "zod": "^3.25.74"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "pnpm run lint && tsc --noEmit && vite build",