@utilix-tech/sdk 0.31.0 → 0.33.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/CHANGELOG.md +8 -0
- package/README.md +10 -6
- package/dist/{ai_agent-B-c59NXD.d.cts → ai_agent-C1zudGgT.d.cts} +24 -2
- package/dist/{ai_agent-B-c59NXD.d.ts → ai_agent-C1zudGgT.d.ts} +24 -2
- package/dist/{chunk-AFEZ6N4A.js → chunk-H2USEUHD.js} +67 -1
- package/dist/{chunk-LXKIPPDG.js → chunk-UUT5HNST.js} +121 -1
- package/dist/{chunk-265NPGKH.js → chunk-W3J7GZVQ.js} +25 -1
- package/dist/{chunk-GDIZWDBY.js → chunk-ZPQOE7KD.js} +78 -1
- package/dist/{code-DaRvff2v.d.ts → code-BK-x8hVx.d.cts} +51 -2
- package/dist/{code-DaRvff2v.d.cts → code-BK-x8hVx.d.ts} +51 -2
- package/dist/index.cjs +287 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/{text-D1fySkCB.d.cts → text-CA-zuD0C.d.cts} +34 -2
- package/dist/{text-D1fySkCB.d.ts → text-CA-zuD0C.d.ts} +34 -2
- package/dist/tools/ai_agent.cjs +24 -0
- package/dist/tools/ai_agent.d.cts +1 -1
- package/dist/tools/ai_agent.d.ts +1 -1
- package/dist/tools/ai_agent.js +1 -1
- package/dist/tools/code.cjs +120 -0
- package/dist/tools/code.d.cts +1 -1
- package/dist/tools/code.d.ts +1 -1
- package/dist/tools/code.js +1 -1
- package/dist/tools/text.cjs +66 -0
- package/dist/tools/text.d.cts +1 -1
- package/dist/tools/text.d.ts +1 -1
- package/dist/tools/text.js +1 -1
- package/dist/tools/units.cjs +77 -0
- package/dist/tools/units.d.cts +1 -1
- package/dist/tools/units.d.ts +1 -1
- package/dist/tools/units.js +1 -1
- package/dist/{units-DQYLZd1n.d.cts → units-BhoxdHhs.d.cts} +42 -2
- package/dist/{units-DQYLZd1n.d.ts → units-BhoxdHhs.d.ts} +42 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Full release notes for all Utilix surfaces (browser tools, REST API, SDKs, MCP server) live at [utilix.tech/changelog](https://utilix.tech/changelog). This file tracks just this package.
|
|
4
4
|
|
|
5
|
+
## 0.33.0
|
|
6
|
+
- Add `lintConventionalCommit` (conventional-commit-linter): lint a git commit message against the Conventional Commits v1.0.0 spec, checking header format, blank-line separation, footer tokens, and BREAKING CHANGE casing.
|
|
7
|
+
- Add `calculateSavingsGoal` (savings-goal-calculator): solve for months to reach a savings goal at a fixed monthly contribution, or the monthly contribution required to hit a goal by a target month count.
|
|
8
|
+
|
|
9
|
+
## 0.32.0
|
|
10
|
+
- Add `analyzeSentenceLengths` (sentence-length-distribution): histogram of sentence lengths in words, plus mean, median, standard deviation, and a coefficient-of-variation consistency label, distinct from readability grade scores.
|
|
11
|
+
- Add `formatFewShotExamples` (few-shot-formatter): format input/output example pairs into a numbered, XML-tagged, or delimiter-separated few-shot prompt template.
|
|
12
|
+
|
|
5
13
|
## 0.31.0
|
|
6
14
|
- Add `calculateEmi` (emi-calculator): equated monthly installment, total interest, and a year-by-year principal/interest breakdown from principal, annual rate, and tenure in years or months.
|
|
7
15
|
- Add `parseFrontMatter` (markdown-front-matter-parser): split a Markdown document into its YAML front matter fields and body content, parsing scalars, inline arrays, and block lists.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @utilix-tech/sdk
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**590 developer utility functions for Node.js: runs locally, no API key required.**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@utilix-tech/sdk)
|
|
6
6
|
[](https://www.npmjs.com/package/@utilix-tech/sdk)
|
|
@@ -140,7 +140,7 @@ generateHtpasswdFile([{ username: "alice", password: "secret" }]);
|
|
|
140
140
|
```ts
|
|
141
141
|
import { convertCase, slugify, countWords, generateWords, generateParagraphs,
|
|
142
142
|
escapeString, htmlToMarkdown, applyOps, detectPassiveVoice, scoreReadability,
|
|
143
|
-
detectFillerWords, calculateStringDistance } from "@utilix-tech/sdk/text";
|
|
143
|
+
detectFillerWords, calculateStringDistance, analyzeSentenceLengths } from "@utilix-tech/sdk/text";
|
|
144
144
|
|
|
145
145
|
convertCase("hello world", "camelCase"); // "helloWorld"
|
|
146
146
|
convertCase("hello world", "PascalCase"); // "HelloWorld"
|
|
@@ -173,6 +173,10 @@ detectFillerWords("At the end of the day, I just really think we should circle b
|
|
|
173
173
|
// Levenshtein edit distance + similarity ratio; pass mode: "damerau" to count a transposition as 1 edit
|
|
174
174
|
calculateStringDistance("kitten", "sitting");
|
|
175
175
|
// { distance: 3, similarity: 0.5714, maxLength: 7, mode: "levenshtein" }
|
|
176
|
+
|
|
177
|
+
// Histogram + mean/median/stddev of sentence lengths, distinct from readability grade scores
|
|
178
|
+
analyzeSentenceLengths("The cat sat on the mat. It was a sunny day, and the dog ran across the yard to play.");
|
|
179
|
+
// { sentenceCount: 2, meanLength: 10, stdDev: 4, consistency: "Moderate variation in sentence length", buckets: [...] }
|
|
176
180
|
```
|
|
177
181
|
|
|
178
182
|
---
|
|
@@ -654,18 +658,18 @@ readVideoInfo(new Uint8Array(videoBytes));
|
|
|
654
658
|
| `@utilix-tech/sdk/json` | Format, minify, diff, validate, JSONPath, CSV↔JSON, YAML↔JSON, TS types from data or from a JSON Schema |
|
|
655
659
|
| `@utilix-tech/sdk/encoding` | Base64, URL, HTML entities, Base32/Base58/Base62 encode/decode |
|
|
656
660
|
| `@utilix-tech/sdk/hashing` | MD5, SHA-1/256/512, bcrypt, HMAC, .htpasswd |
|
|
657
|
-
| `@utilix-tech/sdk/text` | Case convert, slugify, word count, lorem ipsum, line ops, HTML→Markdown, Levenshtein/Damerau string distance |
|
|
661
|
+
| `@utilix-tech/sdk/text` | Case convert, slugify, word count, lorem ipsum, line ops, HTML→Markdown, Levenshtein/Damerau string distance, readability scoring, sentence length distribution |
|
|
658
662
|
| `@utilix-tech/sdk/data` | CSV, YAML, TOML, XML, INI, NDJSON parse and convert, SRT/WebVTT subtitles, Markdown front matter parser |
|
|
659
663
|
| `@utilix-tech/sdk/generators` | UUID v4/v7, ULID, passwords, strength check, entropy estimator, fake data |
|
|
660
664
|
| `@utilix-tech/sdk/time` | Date diff, timezone convert, cron parse, relative time |
|
|
661
|
-
| `@utilix-tech/sdk/units` | Bytes, CSS px/rem, number bases, currency format, credit card/IBAN/barcode/ISBN validation, loan calculator, EMI calculator, compound/simple interest calculators, VAT/sales tax calculator, tip/bill split calculator, break-even point calculator, Rule of 72 calculator |
|
|
665
|
+
| `@utilix-tech/sdk/units` | Bytes, CSS px/rem, number bases, currency format, credit card/IBAN/barcode/ISBN validation, loan calculator, EMI calculator, compound/simple interest calculators, VAT/sales tax calculator, tip/bill split calculator, break-even point calculator, Rule of 72 calculator, savings goal calculator |
|
|
662
666
|
| `@utilix-tech/sdk/network` | HTTP status codes, IP validation, country flags, geolocation URLs, HAR file parsing, User-Agent parsing, IPv6 address compress/expand |
|
|
663
667
|
| `@utilix-tech/sdk/api` | cURL build/parse, JWT decode/sign, JWKS parse, CORS headers, CSP header |
|
|
664
|
-
| `@utilix-tech/sdk/code` | SQL format/minify, HTML format/minify, regex tester, GraphQL format, MIME type lookup, GitHub URL parsing |
|
|
668
|
+
| `@utilix-tech/sdk/code` | SQL format/minify, HTML format/minify, regex tester, GraphQL format, MIME type lookup, GitHub URL parsing, regex ReDoS detector, Conventional Commits linter |
|
|
665
669
|
| `@utilix-tech/sdk/color` | Hex/RGB/HSL/HSV/CMYK convert, palette generation, contrast check |
|
|
666
670
|
| `@utilix-tech/sdk/css` | CSS gradient, box-shadow, border-radius, keyframe animation generators |
|
|
667
671
|
| `@utilix-tech/sdk/misc` | SVG optimize/sanitize, file size format, Unicode inspector |
|
|
668
|
-
| `@utilix-tech/sdk/ai_agent` | Token estimate/trim, chunk text, extract URLs/JSON/keywords, sanitize HTML, flatten/merge JSON, dedupe lines, validate schema, PII/secret/injection detect, vector similarity |
|
|
672
|
+
| `@utilix-tech/sdk/ai_agent` | Token estimate/trim, chunk text, extract URLs/JSON/keywords, sanitize HTML, flatten/merge JSON, dedupe lines, validate schema, PII/secret/injection detect, vector similarity, few-shot prompt formatter |
|
|
669
673
|
| `@utilix-tech/sdk/media` | Image format & dimension reading from raw bytes (PNG, JPEG, GIF, WebP, BMP); PDF metadata reading; PDF page dimension/orientation listing; WAV audio info; ID3 tags; ICO favicon inspection; FLAC metadata reading; MP4/WebM video info |
|
|
670
674
|
|
|
671
675
|
---
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* - secret-detector : detectSecrets
|
|
9
9
|
* - prompt-injection : detectPromptInjection
|
|
10
10
|
* - json-repair : repairJson
|
|
11
|
+
* - few-shot-formatter : formatFewShotExamples
|
|
11
12
|
*/
|
|
12
13
|
interface ModelPricing {
|
|
13
14
|
model: string;
|
|
@@ -333,6 +334,23 @@ interface VectorSimilarityResult {
|
|
|
333
334
|
declare function vectorSimilarity(a: number[], b: number[]): VectorSimilarityResult | {
|
|
334
335
|
error: string;
|
|
335
336
|
};
|
|
337
|
+
type FewShotFormat = 'numbered' | 'xml' | 'delimiter';
|
|
338
|
+
interface FewShotExample {
|
|
339
|
+
input: string;
|
|
340
|
+
output: string;
|
|
341
|
+
}
|
|
342
|
+
interface FewShotFormatResult {
|
|
343
|
+
formatted: string;
|
|
344
|
+
exampleCount: number;
|
|
345
|
+
format: FewShotFormat;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Format a list of input/output example pairs into a standard few-shot
|
|
349
|
+
* prompt template, ready to paste into a system or user prompt. Examples
|
|
350
|
+
* with an empty input or output are dropped. `delimiter` only applies to
|
|
351
|
+
* the 'delimiter' format and defaults to '---'.
|
|
352
|
+
*/
|
|
353
|
+
declare function formatFewShotExamples(examples: FewShotExample[], format?: FewShotFormat, delimiter?: string): FewShotFormatResult;
|
|
336
354
|
|
|
337
355
|
type ai_agent_ChunkStrategy = ChunkStrategy;
|
|
338
356
|
type ai_agent_CompressHtmlResult = CompressHtmlResult;
|
|
@@ -349,6 +367,9 @@ type ai_agent_EntityType2 = EntityType2;
|
|
|
349
367
|
type ai_agent_ExtractJsonResult = ExtractJsonResult;
|
|
350
368
|
type ai_agent_ExtractKeywordsResult = ExtractKeywordsResult;
|
|
351
369
|
type ai_agent_ExtractUrlsResult = ExtractUrlsResult;
|
|
370
|
+
type ai_agent_FewShotExample = FewShotExample;
|
|
371
|
+
type ai_agent_FewShotFormat = FewShotFormat;
|
|
372
|
+
type ai_agent_FewShotFormatResult = FewShotFormatResult;
|
|
352
373
|
type ai_agent_InjectionDetectResult = InjectionDetectResult;
|
|
353
374
|
type ai_agent_InjectionFinding = InjectionFinding;
|
|
354
375
|
type ai_agent_JsonBlock = JsonBlock;
|
|
@@ -396,6 +417,7 @@ declare const ai_agent_extractKeywords: typeof extractKeywords;
|
|
|
396
417
|
declare const ai_agent_extractTables: typeof extractTables;
|
|
397
418
|
declare const ai_agent_extractUrls: typeof extractUrls;
|
|
398
419
|
declare const ai_agent_flattenJson: typeof flattenJson;
|
|
420
|
+
declare const ai_agent_formatFewShotExamples: typeof formatFewShotExamples;
|
|
399
421
|
declare const ai_agent_mergeJson: typeof mergeJson;
|
|
400
422
|
declare const ai_agent_redactPii: typeof redactPii;
|
|
401
423
|
declare const ai_agent_repairJson: typeof repairJson;
|
|
@@ -408,7 +430,7 @@ declare const ai_agent_unflattenJson: typeof unflattenJson;
|
|
|
408
430
|
declare const ai_agent_validateJsonSchema: typeof validateJsonSchema;
|
|
409
431
|
declare const ai_agent_vectorSimilarity: typeof vectorSimilarity;
|
|
410
432
|
declare namespace ai_agent {
|
|
411
|
-
export { type ai_agent_ChunkStrategy as ChunkStrategy, type ai_agent_CompressHtmlResult as CompressHtmlResult, type ai_agent_CompressJsonResult as CompressJsonResult, type ai_agent_CompressMarkdownResult as CompressMarkdownResult, type ai_agent_CostEstimate as CostEstimate, type ai_agent_DedupeResult as DedupeResult, type ai_agent_DedupeStrategy as DedupeStrategy, type ai_agent_DiffEntry2 as DiffEntry2, type ai_agent_DiffOp2 as DiffOp2, type ai_agent_DiffResult2 as DiffResult2, type ai_agent_Entity2 as Entity2, type ai_agent_EntityType2 as EntityType2, type ai_agent_ExtractJsonResult as ExtractJsonResult, type ai_agent_ExtractKeywordsResult as ExtractKeywordsResult, type ai_agent_ExtractUrlsResult as ExtractUrlsResult, type ai_agent_InjectionDetectResult as InjectionDetectResult, type ai_agent_InjectionFinding as InjectionFinding, type ai_agent_JsonBlock as JsonBlock, type ai_agent_JsonRepairResult as JsonRepairResult, type ai_agent_Keyword as Keyword, ai_agent_MODEL_PRICING as MODEL_PRICING, type ai_agent_MergeResult as MergeResult, type ai_agent_MergeStrategy as MergeStrategy, type ai_agent_ModelPricing as ModelPricing, type ai_agent_PiiDetectResult as PiiDetectResult, type ai_agent_PiiFinding as PiiFinding, type ai_agent_PiiType as PiiType, type ai_agent_RankedChunk as RankedChunk, type ai_agent_RelevanceResult as RelevanceResult, type ai_agent_SanitizeResult as SanitizeResult, type ai_agent_SecretDetectResult as SecretDetectResult, type ai_agent_SecretFinding as SecretFinding, type ai_agent_SecretType as SecretType, type ai_agent_SummaryResult as SummaryResult, type ai_agent_TableResult2 as TableResult2, type ai_agent_TextChunk as TextChunk, type ai_agent_TokenEstimate as TokenEstimate, type ai_agent_TokenEstimateResult as TokenEstimateResult, type ai_agent_TrimResult as TrimResult, type ai_agent_TrimStrategy as TrimStrategy, type ai_agent_UrlMatch as UrlMatch, type ai_agent_ValidationError as ValidationError, type ai_agent_ValidationResult as ValidationResult, type ai_agent_VectorSimilarityResult as VectorSimilarityResult, ai_agent_chunkText as chunkText, ai_agent_compressHtml as compressHtml, ai_agent_compressJson as compressJson, ai_agent_compressMarkdown as compressMarkdown, ai_agent_deduplicateLines as deduplicateLines, ai_agent_detectPii as detectPii, ai_agent_detectPromptInjection as detectPromptInjection, ai_agent_detectSecrets as detectSecrets, ai_agent_diffJson as diffJson, ai_agent_estimateCost as estimateCost, ai_agent_estimateTokens as estimateTokens, ai_agent_expandQuery as expandQuery, ai_agent_extractEntities as extractEntities, ai_agent_extractJson as extractJson, ai_agent_extractKeywords as extractKeywords, ai_agent_extractTables as extractTables, ai_agent_extractUrls as extractUrls, ai_agent_flattenJson as flattenJson, ai_agent_mergeJson as mergeJson, ai_agent_redactPii as redactPii, ai_agent_repairJson as repairJson, ai_agent_rerankChunks as rerankChunks, ai_agent_sanitizeHtml as sanitizeHtml, ai_agent_scoreRelevance as scoreRelevance, ai_agent_summarizeForLlm as summarizeForLlm, ai_agent_trimToTokens as trimToTokens, ai_agent_unflattenJson as unflattenJson, ai_agent_validateJsonSchema as validateJsonSchema, ai_agent_vectorSimilarity as vectorSimilarity };
|
|
433
|
+
export { type ai_agent_ChunkStrategy as ChunkStrategy, type ai_agent_CompressHtmlResult as CompressHtmlResult, type ai_agent_CompressJsonResult as CompressJsonResult, type ai_agent_CompressMarkdownResult as CompressMarkdownResult, type ai_agent_CostEstimate as CostEstimate, type ai_agent_DedupeResult as DedupeResult, type ai_agent_DedupeStrategy as DedupeStrategy, type ai_agent_DiffEntry2 as DiffEntry2, type ai_agent_DiffOp2 as DiffOp2, type ai_agent_DiffResult2 as DiffResult2, type ai_agent_Entity2 as Entity2, type ai_agent_EntityType2 as EntityType2, type ai_agent_ExtractJsonResult as ExtractJsonResult, type ai_agent_ExtractKeywordsResult as ExtractKeywordsResult, type ai_agent_ExtractUrlsResult as ExtractUrlsResult, type ai_agent_FewShotExample as FewShotExample, type ai_agent_FewShotFormat as FewShotFormat, type ai_agent_FewShotFormatResult as FewShotFormatResult, type ai_agent_InjectionDetectResult as InjectionDetectResult, type ai_agent_InjectionFinding as InjectionFinding, type ai_agent_JsonBlock as JsonBlock, type ai_agent_JsonRepairResult as JsonRepairResult, type ai_agent_Keyword as Keyword, ai_agent_MODEL_PRICING as MODEL_PRICING, type ai_agent_MergeResult as MergeResult, type ai_agent_MergeStrategy as MergeStrategy, type ai_agent_ModelPricing as ModelPricing, type ai_agent_PiiDetectResult as PiiDetectResult, type ai_agent_PiiFinding as PiiFinding, type ai_agent_PiiType as PiiType, type ai_agent_RankedChunk as RankedChunk, type ai_agent_RelevanceResult as RelevanceResult, type ai_agent_SanitizeResult as SanitizeResult, type ai_agent_SecretDetectResult as SecretDetectResult, type ai_agent_SecretFinding as SecretFinding, type ai_agent_SecretType as SecretType, type ai_agent_SummaryResult as SummaryResult, type ai_agent_TableResult2 as TableResult2, type ai_agent_TextChunk as TextChunk, type ai_agent_TokenEstimate as TokenEstimate, type ai_agent_TokenEstimateResult as TokenEstimateResult, type ai_agent_TrimResult as TrimResult, type ai_agent_TrimStrategy as TrimStrategy, type ai_agent_UrlMatch as UrlMatch, type ai_agent_ValidationError as ValidationError, type ai_agent_ValidationResult as ValidationResult, type ai_agent_VectorSimilarityResult as VectorSimilarityResult, ai_agent_chunkText as chunkText, ai_agent_compressHtml as compressHtml, ai_agent_compressJson as compressJson, ai_agent_compressMarkdown as compressMarkdown, ai_agent_deduplicateLines as deduplicateLines, ai_agent_detectPii as detectPii, ai_agent_detectPromptInjection as detectPromptInjection, ai_agent_detectSecrets as detectSecrets, ai_agent_diffJson as diffJson, ai_agent_estimateCost as estimateCost, ai_agent_estimateTokens as estimateTokens, ai_agent_expandQuery as expandQuery, ai_agent_extractEntities as extractEntities, ai_agent_extractJson as extractJson, ai_agent_extractKeywords as extractKeywords, ai_agent_extractTables as extractTables, ai_agent_extractUrls as extractUrls, ai_agent_flattenJson as flattenJson, ai_agent_formatFewShotExamples as formatFewShotExamples, ai_agent_mergeJson as mergeJson, ai_agent_redactPii as redactPii, ai_agent_repairJson as repairJson, ai_agent_rerankChunks as rerankChunks, ai_agent_sanitizeHtml as sanitizeHtml, ai_agent_scoreRelevance as scoreRelevance, ai_agent_summarizeForLlm as summarizeForLlm, ai_agent_trimToTokens as trimToTokens, ai_agent_unflattenJson as unflattenJson, ai_agent_validateJsonSchema as validateJsonSchema, ai_agent_vectorSimilarity as vectorSimilarity };
|
|
412
434
|
}
|
|
413
435
|
|
|
414
|
-
export {
|
|
436
|
+
export { detectPii as $, type SummaryResult as A, type TextChunk as B, type ChunkStrategy as C, type DedupeResult as D, type Entity2 as E, type FewShotExample as F, type TokenEstimate as G, type TokenEstimateResult as H, type InjectionDetectResult as I, type JsonBlock as J, type Keyword as K, type TrimResult as L, MODEL_PRICING as M, type TrimStrategy as N, type ValidationResult as O, type PiiDetectResult as P, type VectorSimilarityResult as Q, type RankedChunk as R, type SanitizeResult as S, type TableResult2 as T, type UrlMatch as U, type ValidationError as V, chunkText as W, compressHtml as X, compressJson as Y, compressMarkdown as Z, deduplicateLines as _, ai_agent as a, detectPromptInjection as a0, detectSecrets as a1, diffJson as a2, estimateCost as a3, estimateTokens as a4, expandQuery as a5, extractEntities as a6, extractJson as a7, extractKeywords as a8, extractTables as a9, extractUrls as aa, flattenJson as ab, formatFewShotExamples as ac, mergeJson as ad, redactPii as ae, repairJson as af, rerankChunks as ag, sanitizeHtml as ah, scoreRelevance as ai, summarizeForLlm as aj, trimToTokens as ak, unflattenJson as al, validateJsonSchema as am, vectorSimilarity as an, type CompressHtmlResult as b, type CompressJsonResult as c, type CompressMarkdownResult as d, type CostEstimate as e, type DedupeStrategy as f, type DiffEntry2 as g, type DiffOp2 as h, type DiffResult2 as i, type EntityType2 as j, type ExtractJsonResult as k, type ExtractKeywordsResult as l, type ExtractUrlsResult as m, type FewShotFormat as n, type FewShotFormatResult as o, type InjectionFinding as p, type JsonRepairResult as q, type MergeResult as r, type MergeStrategy as s, type ModelPricing as t, type PiiFinding as u, type PiiType as v, type RelevanceResult as w, type SecretDetectResult as x, type SecretFinding as y, type SecretType as z };
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* - secret-detector : detectSecrets
|
|
9
9
|
* - prompt-injection : detectPromptInjection
|
|
10
10
|
* - json-repair : repairJson
|
|
11
|
+
* - few-shot-formatter : formatFewShotExamples
|
|
11
12
|
*/
|
|
12
13
|
interface ModelPricing {
|
|
13
14
|
model: string;
|
|
@@ -333,6 +334,23 @@ interface VectorSimilarityResult {
|
|
|
333
334
|
declare function vectorSimilarity(a: number[], b: number[]): VectorSimilarityResult | {
|
|
334
335
|
error: string;
|
|
335
336
|
};
|
|
337
|
+
type FewShotFormat = 'numbered' | 'xml' | 'delimiter';
|
|
338
|
+
interface FewShotExample {
|
|
339
|
+
input: string;
|
|
340
|
+
output: string;
|
|
341
|
+
}
|
|
342
|
+
interface FewShotFormatResult {
|
|
343
|
+
formatted: string;
|
|
344
|
+
exampleCount: number;
|
|
345
|
+
format: FewShotFormat;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Format a list of input/output example pairs into a standard few-shot
|
|
349
|
+
* prompt template, ready to paste into a system or user prompt. Examples
|
|
350
|
+
* with an empty input or output are dropped. `delimiter` only applies to
|
|
351
|
+
* the 'delimiter' format and defaults to '---'.
|
|
352
|
+
*/
|
|
353
|
+
declare function formatFewShotExamples(examples: FewShotExample[], format?: FewShotFormat, delimiter?: string): FewShotFormatResult;
|
|
336
354
|
|
|
337
355
|
type ai_agent_ChunkStrategy = ChunkStrategy;
|
|
338
356
|
type ai_agent_CompressHtmlResult = CompressHtmlResult;
|
|
@@ -349,6 +367,9 @@ type ai_agent_EntityType2 = EntityType2;
|
|
|
349
367
|
type ai_agent_ExtractJsonResult = ExtractJsonResult;
|
|
350
368
|
type ai_agent_ExtractKeywordsResult = ExtractKeywordsResult;
|
|
351
369
|
type ai_agent_ExtractUrlsResult = ExtractUrlsResult;
|
|
370
|
+
type ai_agent_FewShotExample = FewShotExample;
|
|
371
|
+
type ai_agent_FewShotFormat = FewShotFormat;
|
|
372
|
+
type ai_agent_FewShotFormatResult = FewShotFormatResult;
|
|
352
373
|
type ai_agent_InjectionDetectResult = InjectionDetectResult;
|
|
353
374
|
type ai_agent_InjectionFinding = InjectionFinding;
|
|
354
375
|
type ai_agent_JsonBlock = JsonBlock;
|
|
@@ -396,6 +417,7 @@ declare const ai_agent_extractKeywords: typeof extractKeywords;
|
|
|
396
417
|
declare const ai_agent_extractTables: typeof extractTables;
|
|
397
418
|
declare const ai_agent_extractUrls: typeof extractUrls;
|
|
398
419
|
declare const ai_agent_flattenJson: typeof flattenJson;
|
|
420
|
+
declare const ai_agent_formatFewShotExamples: typeof formatFewShotExamples;
|
|
399
421
|
declare const ai_agent_mergeJson: typeof mergeJson;
|
|
400
422
|
declare const ai_agent_redactPii: typeof redactPii;
|
|
401
423
|
declare const ai_agent_repairJson: typeof repairJson;
|
|
@@ -408,7 +430,7 @@ declare const ai_agent_unflattenJson: typeof unflattenJson;
|
|
|
408
430
|
declare const ai_agent_validateJsonSchema: typeof validateJsonSchema;
|
|
409
431
|
declare const ai_agent_vectorSimilarity: typeof vectorSimilarity;
|
|
410
432
|
declare namespace ai_agent {
|
|
411
|
-
export { type ai_agent_ChunkStrategy as ChunkStrategy, type ai_agent_CompressHtmlResult as CompressHtmlResult, type ai_agent_CompressJsonResult as CompressJsonResult, type ai_agent_CompressMarkdownResult as CompressMarkdownResult, type ai_agent_CostEstimate as CostEstimate, type ai_agent_DedupeResult as DedupeResult, type ai_agent_DedupeStrategy as DedupeStrategy, type ai_agent_DiffEntry2 as DiffEntry2, type ai_agent_DiffOp2 as DiffOp2, type ai_agent_DiffResult2 as DiffResult2, type ai_agent_Entity2 as Entity2, type ai_agent_EntityType2 as EntityType2, type ai_agent_ExtractJsonResult as ExtractJsonResult, type ai_agent_ExtractKeywordsResult as ExtractKeywordsResult, type ai_agent_ExtractUrlsResult as ExtractUrlsResult, type ai_agent_InjectionDetectResult as InjectionDetectResult, type ai_agent_InjectionFinding as InjectionFinding, type ai_agent_JsonBlock as JsonBlock, type ai_agent_JsonRepairResult as JsonRepairResult, type ai_agent_Keyword as Keyword, ai_agent_MODEL_PRICING as MODEL_PRICING, type ai_agent_MergeResult as MergeResult, type ai_agent_MergeStrategy as MergeStrategy, type ai_agent_ModelPricing as ModelPricing, type ai_agent_PiiDetectResult as PiiDetectResult, type ai_agent_PiiFinding as PiiFinding, type ai_agent_PiiType as PiiType, type ai_agent_RankedChunk as RankedChunk, type ai_agent_RelevanceResult as RelevanceResult, type ai_agent_SanitizeResult as SanitizeResult, type ai_agent_SecretDetectResult as SecretDetectResult, type ai_agent_SecretFinding as SecretFinding, type ai_agent_SecretType as SecretType, type ai_agent_SummaryResult as SummaryResult, type ai_agent_TableResult2 as TableResult2, type ai_agent_TextChunk as TextChunk, type ai_agent_TokenEstimate as TokenEstimate, type ai_agent_TokenEstimateResult as TokenEstimateResult, type ai_agent_TrimResult as TrimResult, type ai_agent_TrimStrategy as TrimStrategy, type ai_agent_UrlMatch as UrlMatch, type ai_agent_ValidationError as ValidationError, type ai_agent_ValidationResult as ValidationResult, type ai_agent_VectorSimilarityResult as VectorSimilarityResult, ai_agent_chunkText as chunkText, ai_agent_compressHtml as compressHtml, ai_agent_compressJson as compressJson, ai_agent_compressMarkdown as compressMarkdown, ai_agent_deduplicateLines as deduplicateLines, ai_agent_detectPii as detectPii, ai_agent_detectPromptInjection as detectPromptInjection, ai_agent_detectSecrets as detectSecrets, ai_agent_diffJson as diffJson, ai_agent_estimateCost as estimateCost, ai_agent_estimateTokens as estimateTokens, ai_agent_expandQuery as expandQuery, ai_agent_extractEntities as extractEntities, ai_agent_extractJson as extractJson, ai_agent_extractKeywords as extractKeywords, ai_agent_extractTables as extractTables, ai_agent_extractUrls as extractUrls, ai_agent_flattenJson as flattenJson, ai_agent_mergeJson as mergeJson, ai_agent_redactPii as redactPii, ai_agent_repairJson as repairJson, ai_agent_rerankChunks as rerankChunks, ai_agent_sanitizeHtml as sanitizeHtml, ai_agent_scoreRelevance as scoreRelevance, ai_agent_summarizeForLlm as summarizeForLlm, ai_agent_trimToTokens as trimToTokens, ai_agent_unflattenJson as unflattenJson, ai_agent_validateJsonSchema as validateJsonSchema, ai_agent_vectorSimilarity as vectorSimilarity };
|
|
433
|
+
export { type ai_agent_ChunkStrategy as ChunkStrategy, type ai_agent_CompressHtmlResult as CompressHtmlResult, type ai_agent_CompressJsonResult as CompressJsonResult, type ai_agent_CompressMarkdownResult as CompressMarkdownResult, type ai_agent_CostEstimate as CostEstimate, type ai_agent_DedupeResult as DedupeResult, type ai_agent_DedupeStrategy as DedupeStrategy, type ai_agent_DiffEntry2 as DiffEntry2, type ai_agent_DiffOp2 as DiffOp2, type ai_agent_DiffResult2 as DiffResult2, type ai_agent_Entity2 as Entity2, type ai_agent_EntityType2 as EntityType2, type ai_agent_ExtractJsonResult as ExtractJsonResult, type ai_agent_ExtractKeywordsResult as ExtractKeywordsResult, type ai_agent_ExtractUrlsResult as ExtractUrlsResult, type ai_agent_FewShotExample as FewShotExample, type ai_agent_FewShotFormat as FewShotFormat, type ai_agent_FewShotFormatResult as FewShotFormatResult, type ai_agent_InjectionDetectResult as InjectionDetectResult, type ai_agent_InjectionFinding as InjectionFinding, type ai_agent_JsonBlock as JsonBlock, type ai_agent_JsonRepairResult as JsonRepairResult, type ai_agent_Keyword as Keyword, ai_agent_MODEL_PRICING as MODEL_PRICING, type ai_agent_MergeResult as MergeResult, type ai_agent_MergeStrategy as MergeStrategy, type ai_agent_ModelPricing as ModelPricing, type ai_agent_PiiDetectResult as PiiDetectResult, type ai_agent_PiiFinding as PiiFinding, type ai_agent_PiiType as PiiType, type ai_agent_RankedChunk as RankedChunk, type ai_agent_RelevanceResult as RelevanceResult, type ai_agent_SanitizeResult as SanitizeResult, type ai_agent_SecretDetectResult as SecretDetectResult, type ai_agent_SecretFinding as SecretFinding, type ai_agent_SecretType as SecretType, type ai_agent_SummaryResult as SummaryResult, type ai_agent_TableResult2 as TableResult2, type ai_agent_TextChunk as TextChunk, type ai_agent_TokenEstimate as TokenEstimate, type ai_agent_TokenEstimateResult as TokenEstimateResult, type ai_agent_TrimResult as TrimResult, type ai_agent_TrimStrategy as TrimStrategy, type ai_agent_UrlMatch as UrlMatch, type ai_agent_ValidationError as ValidationError, type ai_agent_ValidationResult as ValidationResult, type ai_agent_VectorSimilarityResult as VectorSimilarityResult, ai_agent_chunkText as chunkText, ai_agent_compressHtml as compressHtml, ai_agent_compressJson as compressJson, ai_agent_compressMarkdown as compressMarkdown, ai_agent_deduplicateLines as deduplicateLines, ai_agent_detectPii as detectPii, ai_agent_detectPromptInjection as detectPromptInjection, ai_agent_detectSecrets as detectSecrets, ai_agent_diffJson as diffJson, ai_agent_estimateCost as estimateCost, ai_agent_estimateTokens as estimateTokens, ai_agent_expandQuery as expandQuery, ai_agent_extractEntities as extractEntities, ai_agent_extractJson as extractJson, ai_agent_extractKeywords as extractKeywords, ai_agent_extractTables as extractTables, ai_agent_extractUrls as extractUrls, ai_agent_flattenJson as flattenJson, ai_agent_formatFewShotExamples as formatFewShotExamples, ai_agent_mergeJson as mergeJson, ai_agent_redactPii as redactPii, ai_agent_repairJson as repairJson, ai_agent_rerankChunks as rerankChunks, ai_agent_sanitizeHtml as sanitizeHtml, ai_agent_scoreRelevance as scoreRelevance, ai_agent_summarizeForLlm as summarizeForLlm, ai_agent_trimToTokens as trimToTokens, ai_agent_unflattenJson as unflattenJson, ai_agent_validateJsonSchema as validateJsonSchema, ai_agent_vectorSimilarity as vectorSimilarity };
|
|
412
434
|
}
|
|
413
435
|
|
|
414
|
-
export {
|
|
436
|
+
export { detectPii as $, type SummaryResult as A, type TextChunk as B, type ChunkStrategy as C, type DedupeResult as D, type Entity2 as E, type FewShotExample as F, type TokenEstimate as G, type TokenEstimateResult as H, type InjectionDetectResult as I, type JsonBlock as J, type Keyword as K, type TrimResult as L, MODEL_PRICING as M, type TrimStrategy as N, type ValidationResult as O, type PiiDetectResult as P, type VectorSimilarityResult as Q, type RankedChunk as R, type SanitizeResult as S, type TableResult2 as T, type UrlMatch as U, type ValidationError as V, chunkText as W, compressHtml as X, compressJson as Y, compressMarkdown as Z, deduplicateLines as _, ai_agent as a, detectPromptInjection as a0, detectSecrets as a1, diffJson as a2, estimateCost as a3, estimateTokens as a4, expandQuery as a5, extractEntities as a6, extractJson as a7, extractKeywords as a8, extractTables as a9, extractUrls as aa, flattenJson as ab, formatFewShotExamples as ac, mergeJson as ad, redactPii as ae, repairJson as af, rerankChunks as ag, sanitizeHtml as ah, scoreRelevance as ai, summarizeForLlm as aj, trimToTokens as ak, unflattenJson as al, validateJsonSchema as am, vectorSimilarity as an, type CompressHtmlResult as b, type CompressJsonResult as c, type CompressMarkdownResult as d, type CostEstimate as e, type DedupeStrategy as f, type DiffEntry2 as g, type DiffOp2 as h, type DiffResult2 as i, type EntityType2 as j, type ExtractJsonResult as k, type ExtractKeywordsResult as l, type ExtractUrlsResult as m, type FewShotFormat as n, type FewShotFormatResult as o, type InjectionFinding as p, type JsonRepairResult as q, type MergeResult as r, type MergeStrategy as s, type ModelPricing as t, type PiiFinding as u, type PiiType as v, type RelevanceResult as w, type SecretDetectResult as x, type SecretFinding as y, type SecretType as z };
|
|
@@ -10,6 +10,7 @@ __export(text_exports, {
|
|
|
10
10
|
LINE_OPS: () => LINE_OPS,
|
|
11
11
|
MORSE_CODE: () => MORSE_CODE,
|
|
12
12
|
addBorder: () => addBorder,
|
|
13
|
+
analyzeSentenceLengths: () => analyzeSentenceLengths,
|
|
13
14
|
analyzeText: () => analyzeText,
|
|
14
15
|
applyOp: () => applyOp,
|
|
15
16
|
applyOps: () => applyOps,
|
|
@@ -2598,5 +2599,70 @@ function calculateStringDistance(a, b, options) {
|
|
|
2598
2599
|
const similarity = maxLength === 0 ? 1 : Math.round((1 - distance / maxLength) * 1e4) / 1e4;
|
|
2599
2600
|
return { a, b, distance, similarity, maxLength, mode };
|
|
2600
2601
|
}
|
|
2602
|
+
function splitIntoSentencesForLengthDist(text) {
|
|
2603
|
+
const matches = text.match(/[^.!?]+[.!?]*/g);
|
|
2604
|
+
if (!matches) return [];
|
|
2605
|
+
return matches.map((s) => s.trim()).filter((s) => s.length > 0);
|
|
2606
|
+
}
|
|
2607
|
+
function countWordsInSentence(sentence) {
|
|
2608
|
+
return (sentence.match(/[a-zA-Z']+/g) ?? []).length;
|
|
2609
|
+
}
|
|
2610
|
+
function analyzeSentenceLengths(text) {
|
|
2611
|
+
const sentences = splitIntoSentencesForLengthDist(text);
|
|
2612
|
+
const lengths = sentences.map(countWordsInSentence).filter((n) => n > 0);
|
|
2613
|
+
if (lengths.length === 0) {
|
|
2614
|
+
return {
|
|
2615
|
+
sentenceCount: 0,
|
|
2616
|
+
lengths: [],
|
|
2617
|
+
minLength: 0,
|
|
2618
|
+
maxLength: 0,
|
|
2619
|
+
meanLength: 0,
|
|
2620
|
+
medianLength: 0,
|
|
2621
|
+
stdDev: 0,
|
|
2622
|
+
coefficientOfVariation: 0,
|
|
2623
|
+
consistency: "No sentences to analyze",
|
|
2624
|
+
buckets: []
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
const sentenceCount2 = lengths.length;
|
|
2628
|
+
const minLength = Math.min(...lengths);
|
|
2629
|
+
const maxLength = Math.max(...lengths);
|
|
2630
|
+
const meanLength = lengths.reduce((a, b) => a + b, 0) / sentenceCount2;
|
|
2631
|
+
const sorted = [...lengths].sort((a, b) => a - b);
|
|
2632
|
+
const mid = Math.floor(sorted.length / 2);
|
|
2633
|
+
const medianLength = sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
|
|
2634
|
+
const variance = lengths.reduce((sum, n) => sum + (n - meanLength) ** 2, 0) / sentenceCount2;
|
|
2635
|
+
const stdDev = Math.sqrt(variance);
|
|
2636
|
+
const coefficientOfVariation = meanLength > 0 ? stdDev / meanLength : 0;
|
|
2637
|
+
let consistency;
|
|
2638
|
+
if (coefficientOfVariation < 0.3) consistency = "Consistent \u2014 sentence lengths vary little";
|
|
2639
|
+
else if (coefficientOfVariation < 0.6) consistency = "Moderate variation in sentence length";
|
|
2640
|
+
else consistency = "Highly variable sentence length";
|
|
2641
|
+
const bucketWidth = 5;
|
|
2642
|
+
const bucketCount = Math.max(1, Math.ceil(maxLength / bucketWidth));
|
|
2643
|
+
const buckets = [];
|
|
2644
|
+
for (let i = 0; i < bucketCount; i++) {
|
|
2645
|
+
const min = i * bucketWidth + 1;
|
|
2646
|
+
const max = (i + 1) * bucketWidth;
|
|
2647
|
+
buckets.push({ label: `${min}-${max}`, min, max, count: 0 });
|
|
2648
|
+
}
|
|
2649
|
+
for (const len of lengths) {
|
|
2650
|
+
const idx = Math.min(Math.floor((len - 1) / bucketWidth), bucketCount - 1);
|
|
2651
|
+
buckets[idx].count++;
|
|
2652
|
+
}
|
|
2653
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
2654
|
+
return {
|
|
2655
|
+
sentenceCount: sentenceCount2,
|
|
2656
|
+
lengths,
|
|
2657
|
+
minLength,
|
|
2658
|
+
maxLength,
|
|
2659
|
+
meanLength: round2(meanLength),
|
|
2660
|
+
medianLength: round2(medianLength),
|
|
2661
|
+
stdDev: round2(stdDev),
|
|
2662
|
+
coefficientOfVariation: round2(coefficientOfVariation),
|
|
2663
|
+
consistency,
|
|
2664
|
+
buckets
|
|
2665
|
+
};
|
|
2666
|
+
}
|
|
2601
2667
|
|
|
2602
|
-
export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeText, applyOp, applyOps, calculateStringDistance, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectFillerWords, 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, scoreReadability, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, text_exports, unescapeString, wordFrequency };
|
|
2668
|
+
export { CASE_FORMATS, DEFAULT_CONVERT_OPTIONS, ESCAPE_MODES, LINE_OPS, MORSE_CODE, addBorder, analyzeSentenceLengths, analyzeText, applyOp, applyOps, calculateStringDistance, centerText, convertAll, convertCase, countWords, csvToHtml, csvToMarkdown, detectDelimiter, detectFillerWords, 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, scoreReadability, sentenceCount, slugify, slugifyAll, syllableCount, textToAscii, textToMorse, text_exports, unescapeString, wordFrequency };
|
|
@@ -6,6 +6,7 @@ var code_exports = {};
|
|
|
6
6
|
__export(code_exports, {
|
|
7
7
|
ALL_FLAGS: () => ALL_FLAGS,
|
|
8
8
|
CHEATSHEET: () => CHEATSHEET,
|
|
9
|
+
DEFAULT_COMMIT_TYPES: () => DEFAULT_COMMIT_TYPES,
|
|
9
10
|
MIME_TABLE: () => MIME_TABLE,
|
|
10
11
|
OPERATIONS: () => OPERATIONS,
|
|
11
12
|
SQL_DEFAULT_OPTIONS: () => SQL_DEFAULT_OPTIONS,
|
|
@@ -30,6 +31,7 @@ __export(code_exports, {
|
|
|
30
31
|
getJsStats: () => getJsStats,
|
|
31
32
|
getMethodColor: () => getMethodColor,
|
|
32
33
|
isValidTag: () => isValidTag,
|
|
34
|
+
lintConventionalCommit: () => lintConventionalCommit,
|
|
33
35
|
lookupMime: () => lookupMime,
|
|
34
36
|
minifyCss: () => minifyCss,
|
|
35
37
|
minifyGql: () => minifyGql,
|
|
@@ -2740,5 +2742,123 @@ function detectRedos(pattern) {
|
|
|
2740
2742
|
findings: unique
|
|
2741
2743
|
};
|
|
2742
2744
|
}
|
|
2745
|
+
var DEFAULT_COMMIT_TYPES = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"];
|
|
2746
|
+
var _DEFAULT_MAX_HEADER_LENGTH = 100;
|
|
2747
|
+
var _COMMIT_HEADER_RE = /^([A-Za-z][A-Za-z0-9-]*)(\(([^()]*)\))?(!)?: (.+)$/;
|
|
2748
|
+
var _COMMIT_FOOTER_LINE_RE = /^([A-Za-z][A-Za-z0-9-]*|BREAKING CHANGE)(: ?| #)(.*)$/;
|
|
2749
|
+
var _COMMIT_BREAKING_LOOKALIKE_RE = /^([A-Za-z][A-Za-z -]*?)(: | #)(.*)$/;
|
|
2750
|
+
var _COMMIT_BREAKING_TOKEN_RE = /^breaking[- ]change$/i;
|
|
2751
|
+
function lintConventionalCommit(message, options = {}) {
|
|
2752
|
+
if (typeof message !== "string" || message.trim() === "") {
|
|
2753
|
+
return { error: "message is required" };
|
|
2754
|
+
}
|
|
2755
|
+
if (message.length > 2e4) {
|
|
2756
|
+
return { error: "message too long (max 20,000 chars)" };
|
|
2757
|
+
}
|
|
2758
|
+
const types = options.types && options.types.length > 0 ? options.types : DEFAULT_COMMIT_TYPES;
|
|
2759
|
+
const maxHeaderLength = options.maxHeaderLength ?? _DEFAULT_MAX_HEADER_LENGTH;
|
|
2760
|
+
const findings = [];
|
|
2761
|
+
const lines = message.replace(/\r\n/g, "\n").split("\n");
|
|
2762
|
+
const header = lines[0];
|
|
2763
|
+
const match = header.match(_COMMIT_HEADER_RE);
|
|
2764
|
+
const parsed = {
|
|
2765
|
+
header,
|
|
2766
|
+
type: null,
|
|
2767
|
+
scope: null,
|
|
2768
|
+
breaking: false,
|
|
2769
|
+
description: null,
|
|
2770
|
+
body: null,
|
|
2771
|
+
footers: []
|
|
2772
|
+
};
|
|
2773
|
+
if (!match) {
|
|
2774
|
+
findings.push({
|
|
2775
|
+
rule: "header-format",
|
|
2776
|
+
severity: "error",
|
|
2777
|
+
message: "Header must match '<type>[(scope)][!]: <description>', e.g. 'feat(auth): add OAuth2 login'. A single space must follow the colon."
|
|
2778
|
+
});
|
|
2779
|
+
return { message, valid: false, parsed, findings };
|
|
2780
|
+
}
|
|
2781
|
+
const [, type, scopeGroup, scope, bang, description] = match;
|
|
2782
|
+
parsed.type = type;
|
|
2783
|
+
if (scopeGroup !== void 0) {
|
|
2784
|
+
const scopeContent = (scope ?? "").trim();
|
|
2785
|
+
if (scopeContent === "") {
|
|
2786
|
+
findings.push({ rule: "scope-empty", severity: "error", message: "Scope parentheses are present but empty; either remove the parentheses or put a scope inside them, e.g. fix(parser):." });
|
|
2787
|
+
} else {
|
|
2788
|
+
parsed.scope = scopeContent;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
const trimmedDescription = description.trim();
|
|
2792
|
+
if (trimmedDescription === "") {
|
|
2793
|
+
findings.push({ rule: "subject-empty", severity: "error", message: "The description after the colon must not be empty." });
|
|
2794
|
+
} else {
|
|
2795
|
+
parsed.description = trimmedDescription;
|
|
2796
|
+
if (trimmedDescription.endsWith(".")) {
|
|
2797
|
+
findings.push({ rule: "subject-full-stop", severity: "warning", message: "The description should not end with a period." });
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
if (!types.includes(type.toLowerCase())) {
|
|
2801
|
+
findings.push({
|
|
2802
|
+
rule: "type-unknown",
|
|
2803
|
+
severity: "warning",
|
|
2804
|
+
message: `'${type}' is not one of the recognized types (${types.join(", ")}). This is only a convention, not a spec requirement, so a custom type is fine if your team has agreed on it.`
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
if (type !== type.toLowerCase()) {
|
|
2808
|
+
findings.push({ rule: "type-case", severity: "warning", message: "The type is conventionally lower-case. The spec itself is not case-sensitive about this, but nearly every tool and team defaults to lower-case." });
|
|
2809
|
+
}
|
|
2810
|
+
if (header.length > maxHeaderLength) {
|
|
2811
|
+
findings.push({ rule: "header-max-length", severity: "warning", message: `Header is ${header.length} characters, longer than the recommended maximum of ${maxHeaderLength}.` });
|
|
2812
|
+
}
|
|
2813
|
+
let breaking = bang === "!";
|
|
2814
|
+
if (lines.length > 1) {
|
|
2815
|
+
if (lines[1].trim() !== "") {
|
|
2816
|
+
findings.push({ rule: "missing-blank-line-before-body", severity: "error", message: "A blank line must separate the header from the body or footer." });
|
|
2817
|
+
}
|
|
2818
|
+
const rest = lines.slice(1).join("\n");
|
|
2819
|
+
const paragraphs = rest.split(/\n{2,}/).map((p) => p.trim()).filter((p) => p !== "");
|
|
2820
|
+
let footerParagraph = null;
|
|
2821
|
+
if (paragraphs.length > 0) {
|
|
2822
|
+
const last = paragraphs[paragraphs.length - 1];
|
|
2823
|
+
const lastLines = last.split("\n");
|
|
2824
|
+
if (lastLines.every((l) => _COMMIT_FOOTER_LINE_RE.test(l.trim()))) {
|
|
2825
|
+
footerParagraph = last;
|
|
2826
|
+
paragraphs.pop();
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
parsed.body = paragraphs.length > 0 ? paragraphs.join("\n\n") : null;
|
|
2830
|
+
if (footerParagraph) {
|
|
2831
|
+
for (const line of footerParagraph.split("\n")) {
|
|
2832
|
+
const fm = line.trim().match(_COMMIT_FOOTER_LINE_RE);
|
|
2833
|
+
if (!fm) continue;
|
|
2834
|
+
const [, token, , value] = fm;
|
|
2835
|
+
parsed.footers.push({ token, value: value.trim() });
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
for (const f of parsed.footers) {
|
|
2839
|
+
if (_COMMIT_BREAKING_TOKEN_RE.test(f.token) && f.token !== "BREAKING CHANGE" && f.token !== "BREAKING-CHANGE") {
|
|
2840
|
+
findings.push({ rule: "breaking-change-casing", severity: "error", message: `Found '${f.token}:' as a footer, but the spec requires the breaking-change token to be exactly 'BREAKING CHANGE' or 'BREAKING-CHANGE' (uppercase).` });
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
for (const p of paragraphs) {
|
|
2844
|
+
for (const line of p.split("\n")) {
|
|
2845
|
+
const bm = line.trim().match(_COMMIT_BREAKING_LOOKALIKE_RE);
|
|
2846
|
+
if (bm && _COMMIT_BREAKING_TOKEN_RE.test(bm[1]) && bm[1] !== "BREAKING CHANGE") {
|
|
2847
|
+
findings.push({ rule: "breaking-change-casing", severity: "error", message: `Found '${bm[1]}' near the end of the message, but it wasn't recognized as a breaking-change footer. The spec requires the exact uppercase token 'BREAKING CHANGE' (or 'BREAKING-CHANGE'), immediately followed by ': '.` });
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
const breakingFooter = parsed.footers.find((f) => f.token === "BREAKING CHANGE" || f.token === "BREAKING-CHANGE");
|
|
2853
|
+
if (breakingFooter) {
|
|
2854
|
+
breaking = true;
|
|
2855
|
+
if (breakingFooter.value === "") {
|
|
2856
|
+
findings.push({ rule: "breaking-change-empty", severity: "error", message: "A 'BREAKING CHANGE:' footer must be followed by a description of the breaking change." });
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
parsed.breaking = breaking;
|
|
2860
|
+
const valid = !findings.some((f) => f.severity === "error");
|
|
2861
|
+
return { message, valid, parsed, findings };
|
|
2862
|
+
}
|
|
2743
2863
|
|
|
2744
|
-
export { ALL_FLAGS, CHEATSHEET, MIME_TABLE, OPERATIONS, SQL_DEFAULT_OPTIONS, buildDockerPull, buildDockerRun, buildGitCommand, code_exports, collapseHtmlWhitespace, collapseJsWhitespace, countProperties, countRules, detectDialect, detectOperationType, detectRedos, envToExport, envToJson, formatCss, formatGql, formatHtml, formatSql, getEndpointsByTag, getHtmlStats, getJsStats, getMethodColor, isValidTag, lookupMime, minifyCss, minifyGql, minifyHtml, minifyJs, minifySql, normalizeRef, parseDockerImage, parseEnv, parseGitCommand, parseGithubUrl, parseSpec, removeConsoleCalls, removeEmptyAttributes, removeHtmlComments, removeJsComments, removeRedundantAttributes, searchCheatsheet, searchEndpoints, splitStatements, testPattern, testRegex, validateEnvKey };
|
|
2864
|
+
export { ALL_FLAGS, CHEATSHEET, DEFAULT_COMMIT_TYPES, MIME_TABLE, OPERATIONS, SQL_DEFAULT_OPTIONS, buildDockerPull, buildDockerRun, buildGitCommand, code_exports, collapseHtmlWhitespace, collapseJsWhitespace, countProperties, countRules, detectDialect, detectOperationType, detectRedos, envToExport, envToJson, formatCss, formatGql, formatHtml, formatSql, getEndpointsByTag, getHtmlStats, getJsStats, getMethodColor, isValidTag, lintConventionalCommit, lookupMime, minifyCss, minifyGql, minifyHtml, minifyJs, minifySql, normalizeRef, parseDockerImage, parseEnv, parseGitCommand, parseGithubUrl, parseSpec, removeConsoleCalls, removeEmptyAttributes, removeHtmlComments, removeJsComments, removeRedundantAttributes, searchCheatsheet, searchEndpoints, splitStatements, testPattern, testRegex, validateEnvKey };
|
|
@@ -22,6 +22,7 @@ __export(ai_agent_exports, {
|
|
|
22
22
|
extractTables: () => extractTables,
|
|
23
23
|
extractUrls: () => extractUrls,
|
|
24
24
|
flattenJson: () => flattenJson,
|
|
25
|
+
formatFewShotExamples: () => formatFewShotExamples,
|
|
25
26
|
mergeJson: () => mergeJson,
|
|
26
27
|
redactPii: () => redactPii,
|
|
27
28
|
repairJson: () => repairJson,
|
|
@@ -979,5 +980,28 @@ function vectorSimilarity(a, b) {
|
|
|
979
980
|
magnitudeB: round6(magB)
|
|
980
981
|
};
|
|
981
982
|
}
|
|
983
|
+
function formatFewShotExamples(examples, format = "numbered", delimiter = "---") {
|
|
984
|
+
const valid = (examples ?? []).filter((e) => e?.input?.trim() && e?.output?.trim());
|
|
985
|
+
if (valid.length === 0) {
|
|
986
|
+
return { formatted: "", exampleCount: 0, format };
|
|
987
|
+
}
|
|
988
|
+
let formatted;
|
|
989
|
+
if (format === "xml") {
|
|
990
|
+
formatted = valid.map((e) => `<example>
|
|
991
|
+
<input>${e.input.trim()}</input>
|
|
992
|
+
<output>${e.output.trim()}</output>
|
|
993
|
+
</example>`).join("\n\n");
|
|
994
|
+
} else if (format === "delimiter") {
|
|
995
|
+
formatted = valid.map((e) => `Input: ${e.input.trim()}
|
|
996
|
+
Output: ${e.output.trim()}`).join(`
|
|
997
|
+
${delimiter}
|
|
998
|
+
`);
|
|
999
|
+
} else {
|
|
1000
|
+
formatted = valid.map((e, i) => `Example ${i + 1}:
|
|
1001
|
+
Input: ${e.input.trim()}
|
|
1002
|
+
Output: ${e.output.trim()}`).join("\n\n");
|
|
1003
|
+
}
|
|
1004
|
+
return { formatted, exampleCount: valid.length, format };
|
|
1005
|
+
}
|
|
982
1006
|
|
|
983
|
-
export { MODEL_PRICING, ai_agent_exports, chunkText, compressHtml, compressJson, compressMarkdown, deduplicateLines, detectPii, detectPromptInjection, detectSecrets, diffJson, estimateCost, estimateTokens, expandQuery, extractEntities, extractJson, extractKeywords, extractTables, extractUrls, flattenJson, mergeJson, redactPii, repairJson, rerankChunks, sanitizeHtml, scoreRelevance, summarizeForLlm, trimToTokens, unflattenJson, validateJsonSchema, vectorSimilarity };
|
|
1007
|
+
export { MODEL_PRICING, ai_agent_exports, chunkText, compressHtml, compressJson, compressMarkdown, deduplicateLines, detectPii, detectPromptInjection, detectSecrets, diffJson, estimateCost, estimateTokens, expandQuery, extractEntities, extractJson, extractKeywords, extractTables, extractUrls, flattenJson, formatFewShotExamples, mergeJson, redactPii, repairJson, rerankChunks, sanitizeHtml, scoreRelevance, summarizeForLlm, trimToTokens, unflattenJson, validateJsonSchema, vectorSimilarity };
|
|
@@ -27,6 +27,7 @@ __export(units_exports, {
|
|
|
27
27
|
calculateMarginMarkup: () => calculateMarginMarkup,
|
|
28
28
|
calculatePercentageChange: () => calculatePercentageChange,
|
|
29
29
|
calculateRuleOf72: () => calculateRuleOf72,
|
|
30
|
+
calculateSavingsGoal: () => calculateSavingsGoal,
|
|
30
31
|
calculateSimpleInterest: () => calculateSimpleInterest,
|
|
31
32
|
calculateTax: () => calculateTax,
|
|
32
33
|
calculateTimeValue: () => calculateTimeValue,
|
|
@@ -1732,5 +1733,81 @@ function calculateEmi(principal, annualRatePercent, tenure, tenureUnit = "years"
|
|
|
1732
1733
|
yearlyBreakdown
|
|
1733
1734
|
};
|
|
1734
1735
|
}
|
|
1736
|
+
function calculateSavingsGoal(input) {
|
|
1737
|
+
const { mode, goalAmount, currentSavings, annualInterestRatePercent, monthlyContribution, months } = input;
|
|
1738
|
+
if (mode !== "time-to-goal" && mode !== "contribution-for-target") {
|
|
1739
|
+
return { error: "mode must be 'time-to-goal' or 'contribution-for-target'" };
|
|
1740
|
+
}
|
|
1741
|
+
if (!Number.isFinite(goalAmount) || goalAmount <= 0) return { error: "goalAmount must be a finite number greater than zero" };
|
|
1742
|
+
if (!Number.isFinite(currentSavings) || currentSavings < 0) return { error: "currentSavings must be a finite, non-negative number" };
|
|
1743
|
+
if (!Number.isFinite(annualInterestRatePercent) || annualInterestRatePercent < 0) {
|
|
1744
|
+
return { error: "annualInterestRatePercent must be a finite, non-negative number" };
|
|
1745
|
+
}
|
|
1746
|
+
const round4 = (n) => Math.round(n * 1e4) / 1e4;
|
|
1747
|
+
const r = annualInterestRatePercent / 100 / 12;
|
|
1748
|
+
if (mode === "time-to-goal") {
|
|
1749
|
+
if (typeof monthlyContribution !== "number" || !Number.isFinite(monthlyContribution) || monthlyContribution < 0) {
|
|
1750
|
+
return { error: "monthlyContribution must be a finite, non-negative number" };
|
|
1751
|
+
}
|
|
1752
|
+
let exactMonths;
|
|
1753
|
+
if (currentSavings >= goalAmount) {
|
|
1754
|
+
exactMonths = 0;
|
|
1755
|
+
} else if (monthlyContribution === 0) {
|
|
1756
|
+
if (r === 0) return { error: "monthlyContribution must be greater than zero when annualInterestRatePercent is zero, since savings would never grow toward the goal" };
|
|
1757
|
+
if (currentSavings <= 0) return { error: "monthlyContribution must be greater than zero when currentSavings is zero, since there is nothing to compound" };
|
|
1758
|
+
exactMonths = Math.log(goalAmount / currentSavings) / Math.log(1 + r);
|
|
1759
|
+
} else if (r === 0) {
|
|
1760
|
+
exactMonths = (goalAmount - currentSavings) / monthlyContribution;
|
|
1761
|
+
} else {
|
|
1762
|
+
const denom = currentSavings + monthlyContribution / r;
|
|
1763
|
+
const x = (goalAmount + monthlyContribution / r) / denom;
|
|
1764
|
+
exactMonths = Math.log(x) / Math.log(1 + r);
|
|
1765
|
+
}
|
|
1766
|
+
const monthsRounded = Math.max(0, Math.ceil(exactMonths));
|
|
1767
|
+
const finalBalance = r === 0 ? currentSavings + monthlyContribution * monthsRounded : currentSavings * Math.pow(1 + r, monthsRounded) + monthlyContribution * ((Math.pow(1 + r, monthsRounded) - 1) / r);
|
|
1768
|
+
const totalContributed2 = monthlyContribution * monthsRounded;
|
|
1769
|
+
const totalInterestEarned2 = finalBalance - currentSavings - totalContributed2;
|
|
1770
|
+
return {
|
|
1771
|
+
mode,
|
|
1772
|
+
goalAmount: round4(goalAmount),
|
|
1773
|
+
currentSavings: round4(currentSavings),
|
|
1774
|
+
annualInterestRatePercent: round4(annualInterestRatePercent),
|
|
1775
|
+
monthlyContribution: round4(monthlyContribution),
|
|
1776
|
+
months: round4(exactMonths),
|
|
1777
|
+
monthsRounded,
|
|
1778
|
+
years: round4(monthsRounded / 12),
|
|
1779
|
+
totalContributed: round4(totalContributed2),
|
|
1780
|
+
totalInterestEarned: round4(totalInterestEarned2),
|
|
1781
|
+
finalBalance: round4(finalBalance)
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
if (typeof months !== "number" || !Number.isFinite(months) || !Number.isInteger(months) || months <= 0) {
|
|
1785
|
+
return { error: "months must be a positive integer" };
|
|
1786
|
+
}
|
|
1787
|
+
const growthOfCurrentSavings = r === 0 ? currentSavings : currentSavings * Math.pow(1 + r, months);
|
|
1788
|
+
let requiredMonthlyContribution;
|
|
1789
|
+
if (growthOfCurrentSavings >= goalAmount) {
|
|
1790
|
+
requiredMonthlyContribution = 0;
|
|
1791
|
+
} else if (r === 0) {
|
|
1792
|
+
requiredMonthlyContribution = (goalAmount - currentSavings) / months;
|
|
1793
|
+
} else {
|
|
1794
|
+
requiredMonthlyContribution = (goalAmount - growthOfCurrentSavings) * r / (Math.pow(1 + r, months) - 1);
|
|
1795
|
+
}
|
|
1796
|
+
const totalContributed = requiredMonthlyContribution * months;
|
|
1797
|
+
const totalInterestEarned = goalAmount - currentSavings - totalContributed;
|
|
1798
|
+
return {
|
|
1799
|
+
mode,
|
|
1800
|
+
goalAmount: round4(goalAmount),
|
|
1801
|
+
currentSavings: round4(currentSavings),
|
|
1802
|
+
annualInterestRatePercent: round4(annualInterestRatePercent),
|
|
1803
|
+
monthlyContribution: round4(requiredMonthlyContribution),
|
|
1804
|
+
months,
|
|
1805
|
+
monthsRounded: months,
|
|
1806
|
+
years: round4(months / 12),
|
|
1807
|
+
totalContributed: round4(totalContributed),
|
|
1808
|
+
totalInterestEarned: round4(totalInterestEarned),
|
|
1809
|
+
finalBalance: round4(goalAmount)
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1735
1812
|
|
|
1736
|
-
export { BASE_LABELS, BASE_PREFIXES, BYTE_UNITS, COMMON_CURRENCIES, COMMON_LOCALES, COMMON_PERMISSIONS, COMMON_RATIOS, COMMON_SIZES, COMMON_TAX_RATES, COMMON_TIP_PERCENTAGES, COMMON_VIEWPORTS, applySuccessiveDiscounts, autoFormat, bumpVersion, calcAspectRatio, calcSubnet, calculateBreakEven, calculateCompoundInterest, calculateDiscount, calculateEmi, calculateLoan, calculateMarginMarkup, calculatePercentageChange, calculateRuleOf72, calculateSimpleInterest, calculateTax, calculateTimeValue, calculateTipSplit, calculateVideoBitrate, compareSemver, convert, convertAprApy, convertBytes, convertIp, coverBox, decimalToIp, decimalToIpCidr, describePermissions, fitIntoBox, formatNumber, formatValue, formatVwValue, formatWithSeparator, gcd, ipFromBinary, ipFromDecimal, ipFromHex, ipToBinary, ipToDecimal, ipToDecimalCidr, ipToHex, ipToOctal, isValid, isValidCidr, isValidIp, isValidIpv4, marginToMarkup, markupToMargin, octalToPermissions, parseFileSize, parseInput, parseNumberString, parseSemver, permissionsToChmod, permissionsToOctal, permissionsToSymbolic, ptToPx, pxToAll, pxToViewport, remToPx, satisfiesRange, scaleByHeight, scaleByWidth, sortVersions, splitSubnet, symbolicToPermissions, units_exports, validateBarcode, validateCardNumber, validateIban, validateIsbn, viewportToPx };
|
|
1813
|
+
export { BASE_LABELS, BASE_PREFIXES, BYTE_UNITS, COMMON_CURRENCIES, COMMON_LOCALES, COMMON_PERMISSIONS, COMMON_RATIOS, COMMON_SIZES, COMMON_TAX_RATES, COMMON_TIP_PERCENTAGES, COMMON_VIEWPORTS, applySuccessiveDiscounts, autoFormat, bumpVersion, calcAspectRatio, calcSubnet, calculateBreakEven, calculateCompoundInterest, calculateDiscount, calculateEmi, calculateLoan, calculateMarginMarkup, calculatePercentageChange, calculateRuleOf72, calculateSavingsGoal, calculateSimpleInterest, calculateTax, calculateTimeValue, calculateTipSplit, calculateVideoBitrate, compareSemver, convert, convertAprApy, convertBytes, convertIp, coverBox, decimalToIp, decimalToIpCidr, describePermissions, fitIntoBox, formatNumber, formatValue, formatVwValue, formatWithSeparator, gcd, ipFromBinary, ipFromDecimal, ipFromHex, ipToBinary, ipToDecimal, ipToDecimalCidr, ipToHex, ipToOctal, isValid, isValidCidr, isValidIp, isValidIpv4, marginToMarkup, markupToMargin, octalToPermissions, parseFileSize, parseInput, parseNumberString, parseSemver, permissionsToChmod, permissionsToOctal, permissionsToSymbolic, ptToPx, pxToAll, pxToViewport, remToPx, satisfiesRange, scaleByHeight, scaleByWidth, sortVersions, splitSubnet, symbolicToPermissions, units_exports, validateBarcode, validateCardNumber, validateIban, validateIsbn, viewportToPx };
|