@redaksjon/protokoll-engine 0.1.7 → 0.1.8-dev.20260221045945.bbdc773
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/dist/index33.js +1 -1
- package/dist/index34.js +2 -2
- package/dist/index35.js +4 -4
- package/dist/index36.js +1 -1
- package/dist/index38.js +12 -13
- package/dist/index38.js.map +1 -1
- package/dist/index53.js +48 -5
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +34 -46
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +280 -35
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +137 -258
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +60 -142
- package/dist/index57.js.map +1 -1
- package/dist/index58.js +70 -73
- package/dist/index58.js.map +1 -1
- package/dist/index59.js +3 -73
- package/dist/index59.js.map +1 -1
- package/dist/index60.js +5 -148
- package/dist/index60.js.map +1 -1
- package/dist/index61.js +4 -4
- package/dist/index62.js +148 -5
- package/dist/index62.js.map +1 -1
- package/dist/transcript/operations.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index57.js
CHANGED
|
@@ -2,160 +2,78 @@ import { getLogger } from './index47.js';
|
|
|
2
2
|
|
|
3
3
|
const create = (config) => {
|
|
4
4
|
const logger = getLogger();
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
const confidence = classification.confidence ?? 0;
|
|
12
|
-
const minConfidence = mapping.minConfidence ?? tier2MinConfidence;
|
|
13
|
-
if (confidence < minConfidence) {
|
|
14
|
-
logger.debug(
|
|
15
|
-
`Skipping Tier 2 replacement for "${mapping.soundsLike}": confidence ${confidence} < ${minConfidence}`
|
|
16
|
-
);
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (mapping.scopedToProjects && mapping.scopedToProjects.length > 0) {
|
|
20
|
-
const classifiedProject = classification.project;
|
|
21
|
-
if (!classifiedProject) {
|
|
22
|
-
logger.debug(
|
|
23
|
-
`Skipping Tier 2 replacement for "${mapping.soundsLike}": no project in classification`
|
|
24
|
-
);
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
if (!mapping.scopedToProjects.includes(classifiedProject)) {
|
|
28
|
-
logger.debug(
|
|
29
|
-
`Skipping Tier 2 replacement for "${mapping.soundsLike}": project "${classifiedProject}" not in scope [${mapping.scopedToProjects.join(", ")}]`
|
|
30
|
-
);
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
logger.debug(
|
|
35
|
-
`Applying Tier 2 replacement for "${mapping.soundsLike}" → "${mapping.correctText}" (project: ${classification.project}, confidence: ${confidence})`
|
|
36
|
-
);
|
|
37
|
-
return true;
|
|
5
|
+
const createPattern = (soundsLike) => {
|
|
6
|
+
const escaped = soundsLike.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7
|
+
const pattern = `\\b${escaped}\\b` ;
|
|
8
|
+
const flags = "gi" ;
|
|
9
|
+
return new RegExp(pattern, flags);
|
|
38
10
|
};
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
11
|
+
const applySingleReplacement = (text, mapping) => {
|
|
12
|
+
const pattern = createPattern(mapping.soundsLike);
|
|
13
|
+
const occurrences = [];
|
|
14
|
+
let count = 0;
|
|
15
|
+
const replacements = [];
|
|
16
|
+
let match;
|
|
17
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
18
|
+
const original = match[0];
|
|
19
|
+
let replacement = mapping.correctText;
|
|
20
|
+
replacements.push({
|
|
21
|
+
index: match.index,
|
|
22
|
+
length: original.length,
|
|
23
|
+
replacement
|
|
24
|
+
});
|
|
25
|
+
occurrences.push({
|
|
26
|
+
original,
|
|
27
|
+
replacement,
|
|
28
|
+
position: match.index,
|
|
29
|
+
mapping
|
|
30
|
+
});
|
|
31
|
+
count++;
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (tier2Mappings.length > 1) {
|
|
57
|
-
logger.debug(`Multiple Tier 2 mappings match for "${soundsLike}", skipping replacement`);
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
logger.debug(`No applicable mappings for collision "${soundsLike}"`);
|
|
61
|
-
return null;
|
|
62
|
-
};
|
|
63
|
-
const detectCapitalizationHint = (soundsLike, surroundingText) => {
|
|
64
|
-
if (!useCapitalizationHints || !surroundingText) {
|
|
65
|
-
return "unknown";
|
|
33
|
+
let resultText = text;
|
|
34
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
35
|
+
const { index, length, replacement } = replacements[i];
|
|
36
|
+
resultText = resultText.slice(0, index) + replacement + resultText.slice(index + length);
|
|
66
37
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
const matchedText = match[0];
|
|
73
|
-
const isCapitalized = matchedText[0] === matchedText[0].toUpperCase();
|
|
74
|
-
if (!isCapitalized) {
|
|
75
|
-
return "common-term";
|
|
76
|
-
}
|
|
77
|
-
const indexInText = surroundingText.indexOf(matchedText);
|
|
78
|
-
const beforeText = surroundingText.substring(0, indexInText).trimEnd();
|
|
79
|
-
const isAtSentenceStart = beforeText.length === 0 || /[.!?]\s*$/.test(beforeText);
|
|
80
|
-
if (isAtSentenceStart) {
|
|
81
|
-
return "unknown";
|
|
38
|
+
if (count > 0) {
|
|
39
|
+
logger.debug(
|
|
40
|
+
`Replaced "${mapping.soundsLike}" → "${mapping.correctText}" (${count} occurrence${count === 1 ? "" : "s"})`
|
|
41
|
+
);
|
|
82
42
|
}
|
|
83
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
text: resultText,
|
|
45
|
+
count,
|
|
46
|
+
occurrences,
|
|
47
|
+
appliedMappings: count > 0 ? [mapping] : []
|
|
48
|
+
};
|
|
84
49
|
};
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
shouldReplace: true,
|
|
99
|
-
mapping,
|
|
100
|
-
reason: "Tier 1 mapping (always safe)",
|
|
101
|
-
confidence: 1
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
if (mapping.tier === 2) {
|
|
105
|
-
if (shouldApplyTier2(mapping, classification)) {
|
|
106
|
-
return {
|
|
107
|
-
shouldReplace: true,
|
|
108
|
-
mapping,
|
|
109
|
-
reason: `Tier 2 mapping (project: ${classification.project}, confidence: ${classification.confidence})`,
|
|
110
|
-
confidence: classification.confidence ?? 0.5
|
|
111
|
-
};
|
|
112
|
-
} else {
|
|
113
|
-
return {
|
|
114
|
-
shouldReplace: false,
|
|
115
|
-
reason: "Tier 2 conditions not met",
|
|
116
|
-
confidence: 0.5
|
|
117
|
-
};
|
|
118
|
-
}
|
|
50
|
+
const applyReplacements = (text, mappings) => {
|
|
51
|
+
let resultText = text;
|
|
52
|
+
let totalCount = 0;
|
|
53
|
+
const allOccurrences = [];
|
|
54
|
+
const appliedMappings = [];
|
|
55
|
+
for (const mapping of mappings) {
|
|
56
|
+
const result = applySingleReplacement(resultText, mapping);
|
|
57
|
+
if (result.count > 0) {
|
|
58
|
+
resultText = result.text;
|
|
59
|
+
totalCount += result.count;
|
|
60
|
+
allOccurrences.push(...result.occurrences);
|
|
61
|
+
appliedMappings.push(mapping);
|
|
119
62
|
}
|
|
120
|
-
return {
|
|
121
|
-
shouldReplace: false,
|
|
122
|
-
reason: "Tier 3 mapping (too ambiguous)",
|
|
123
|
-
confidence: 1
|
|
124
|
-
};
|
|
125
63
|
}
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
classification
|
|
64
|
+
logger.debug(
|
|
65
|
+
`Applied ${mappings.length} mappings, made ${totalCount} replacements (${appliedMappings.length} mappings had matches)`
|
|
129
66
|
);
|
|
130
|
-
if (resolvedMapping) {
|
|
131
|
-
return {
|
|
132
|
-
shouldReplace: true,
|
|
133
|
-
mapping: resolvedMapping,
|
|
134
|
-
reason: `Collision resolved (${availableMappings.length} candidates)`,
|
|
135
|
-
confidence: classification.confidence ?? 0.5
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (surroundingText && useCapitalizationHints) {
|
|
139
|
-
const hint = detectCapitalizationHint(soundsLike, surroundingText);
|
|
140
|
-
if (hint === "common-term") {
|
|
141
|
-
return {
|
|
142
|
-
shouldReplace: false,
|
|
143
|
-
reason: "Capitalization hint suggests common term",
|
|
144
|
-
confidence: 0.7
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
67
|
return {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
68
|
+
text: resultText,
|
|
69
|
+
count: totalCount,
|
|
70
|
+
occurrences: allOccurrences,
|
|
71
|
+
appliedMappings
|
|
152
72
|
};
|
|
153
73
|
};
|
|
154
74
|
return {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
resolveCollision,
|
|
158
|
-
detectCapitalizationHint
|
|
75
|
+
applyReplacements,
|
|
76
|
+
applySingleReplacement
|
|
159
77
|
};
|
|
160
78
|
};
|
|
161
79
|
|
package/dist/index57.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index57.js","sources":["../src/util/collision-detector.ts"],"sourcesContent":["/**\n * Collision Detector\n *\n * Provides utilities for detecting and resolving collisions in sounds_like mappings.\n * Helps determine when it's safe to apply a replacement and when context is needed.\n *\n * Part of the simple-replace optimization (Phase 1).\n */\n\nimport * as Logging from '@/logging';\nimport { SoundsLikeMapping, Collision } from './sounds-like-database';\n\n/**\n * Classification result for an entity\n */\nexport interface Classification {\n /** Identified project ID */\n project?: string;\n\n /** Classification confidence (0-1) */\n confidence?: number;\n\n /** Additional classification metadata */\n [key: string]: any;\n}\n\n/**\n * Replacement decision\n */\nexport interface ReplacementDecision {\n /** Whether to apply the replacement */\n shouldReplace: boolean;\n\n /** The mapping to use (if shouldReplace is true) */\n mapping?: SoundsLikeMapping;\n\n /** Reason for the decision */\n reason: string;\n\n /** Confidence in this decision (0-1) */\n confidence: number;\n}\n\n/**\n * Context for collision resolution\n */\nexport interface CollisionContext {\n /** Classification of the transcription */\n classification: Classification;\n\n /** The sounds_like value being considered */\n soundsLike: string;\n\n /** Available mappings for this sounds_like */\n availableMappings: SoundsLikeMapping[];\n\n /** Surrounding text context (optional) */\n surroundingText?: string;\n}\n\n/**\n * Instance interface for collision detector\n */\nexport interface Instance {\n /**\n * Decide whether to apply a replacement given a collision context\n */\n decideReplacement(context: CollisionContext): ReplacementDecision;\n\n /**\n * Check if a Tier 2 mapping should be applied given classification\n */\n shouldApplyTier2(mapping: SoundsLikeMapping, classification: Classification): boolean;\n\n /**\n * Resolve a collision by selecting the best mapping\n */\n resolveCollision(collision: Collision, classification: Classification): SoundsLikeMapping | null;\n\n /**\n * Detect capitalization hints in context\n */\n detectCapitalizationHint(soundsLike: string, surroundingText: string): 'proper-noun' | 'common-term' | 'unknown';\n}\n\n/**\n * Configuration for collision detector\n */\nexport interface CollisionDetectorConfig {\n /** Minimum confidence for Tier 2 replacements (default: 0.6) */\n tier2MinConfidence?: number;\n\n /** High confidence threshold for aggressive replacement (default: 0.8) */\n tier2HighConfidence?: number;\n\n /** Enable capitalization hints (default: true) */\n useCapitalizationHints?: boolean;\n\n /** Enable surrounding text analysis (default: false, future feature) */\n useSurroundingText?: boolean;\n}\n\n/**\n * Create a collision detector instance\n */\nexport const create = (config?: CollisionDetectorConfig): Instance => {\n const logger = Logging.getLogger();\n\n const tier2MinConfidence = config?.tier2MinConfidence ?? 0.6;\n // const tier2HighConfidence = config?.tier2HighConfidence ?? 0.8; // Reserved for future use\n const useCapitalizationHints = config?.useCapitalizationHints ?? true;\n\n /**\n * Check if a Tier 2 mapping should be applied\n */\n const shouldApplyTier2 = (\n mapping: SoundsLikeMapping,\n classification: Classification\n ): boolean => {\n // Must be Tier 2\n if (mapping.tier !== 2) {\n return false;\n }\n\n // Check confidence threshold\n const confidence = classification.confidence ?? 0;\n const minConfidence = mapping.minConfidence ?? tier2MinConfidence;\n\n if (confidence < minConfidence) {\n logger.debug(\n `Skipping Tier 2 replacement for \"${mapping.soundsLike}\": ` +\n `confidence ${confidence} < ${minConfidence}`\n );\n return false;\n }\n\n // For project-scoped mappings, check if project matches\n if (mapping.scopedToProjects && mapping.scopedToProjects.length > 0) {\n const classifiedProject = classification.project;\n\n if (!classifiedProject) {\n logger.debug(\n `Skipping Tier 2 replacement for \"${mapping.soundsLike}\": ` +\n `no project in classification`\n );\n return false;\n }\n\n if (!mapping.scopedToProjects.includes(classifiedProject)) {\n logger.debug(\n `Skipping Tier 2 replacement for \"${mapping.soundsLike}\": ` +\n `project \"${classifiedProject}\" not in scope [${mapping.scopedToProjects.join(', ')}]`\n );\n return false;\n }\n }\n\n logger.debug(\n `Applying Tier 2 replacement for \"${mapping.soundsLike}\" → \"${mapping.correctText}\" ` +\n `(project: ${classification.project}, confidence: ${confidence})`\n );\n return true;\n };\n\n /**\n * Resolve a collision by selecting the best mapping\n */\n const resolveCollision = (\n collision: Collision,\n classification: Classification\n ): SoundsLikeMapping | null => {\n const { soundsLike, mappings } = collision;\n\n logger.debug(`Resolving collision for \"${soundsLike}\" (${mappings.length} candidates)`);\n\n // Filter to Tier 1 and applicable Tier 2 mappings\n const tier1Mappings = mappings.filter(m => m.tier === 1);\n const tier2Mappings = mappings.filter(m => m.tier === 2 && shouldApplyTier2(m, classification));\n\n // Prefer Tier 1 if available (always safe)\n if (tier1Mappings.length === 1) {\n logger.debug(`Resolved collision: using Tier 1 mapping \"${tier1Mappings[0].correctText}\"`);\n return tier1Mappings[0];\n }\n\n // If multiple Tier 1 mappings, this is ambiguous (shouldn't happen in practice)\n if (tier1Mappings.length > 1) {\n logger.warn(`Multiple Tier 1 mappings for \"${soundsLike}\", skipping replacement`);\n return null;\n }\n\n // Try Tier 2 mappings that match classification\n if (tier2Mappings.length === 1) {\n logger.debug(`Resolved collision: using Tier 2 mapping \"${tier2Mappings[0].correctText}\"`);\n return tier2Mappings[0];\n }\n\n // If multiple Tier 2 mappings match, this is ambiguous\n if (tier2Mappings.length > 1) {\n logger.debug(`Multiple Tier 2 mappings match for \"${soundsLike}\", skipping replacement`);\n return null;\n }\n\n // No applicable mappings\n logger.debug(`No applicable mappings for collision \"${soundsLike}\"`);\n return null;\n };\n\n /**\n * Detect capitalization hints in surrounding text\n */\n const detectCapitalizationHint = (\n soundsLike: string,\n surroundingText: string\n ): 'proper-noun' | 'common-term' | 'unknown' => {\n if (!useCapitalizationHints || !surroundingText) {\n return 'unknown';\n }\n\n // Find the sounds_like in the surrounding text\n const regex = new RegExp(`\\\\b${soundsLike}\\\\b`, 'i');\n const match = surroundingText.match(regex);\n\n if (!match) {\n return 'unknown';\n }\n\n const matchedText = match[0];\n\n // Check if it's capitalized\n const isCapitalized = matchedText[0] === matchedText[0].toUpperCase();\n\n if (!isCapitalized) {\n // Lowercase in text → likely common term\n return 'common-term';\n }\n\n // Capitalized - check if it's at sentence start\n const indexInText = surroundingText.indexOf(matchedText);\n\n // Look back for sentence boundaries\n const beforeText = surroundingText.substring(0, indexInText).trimEnd();\n const isAtSentenceStart = beforeText.length === 0 || /[.!?]\\s*$/.test(beforeText);\n\n if (isAtSentenceStart) {\n // Capitalized at sentence start → ambiguous\n return 'unknown';\n }\n\n // Capitalized mid-sentence → likely proper noun\n return 'proper-noun';\n };\n\n /**\n * Decide whether to apply a replacement\n */\n const decideReplacement = (context: CollisionContext): ReplacementDecision => {\n const { classification, soundsLike, availableMappings, surroundingText } = context;\n\n // No mappings available\n if (availableMappings.length === 0) {\n return {\n shouldReplace: false,\n reason: 'No mappings available',\n confidence: 1.0,\n };\n }\n\n // Single mapping - straightforward\n if (availableMappings.length === 1) {\n const mapping = availableMappings[0];\n\n // Tier 1: Always apply\n if (mapping.tier === 1) {\n return {\n shouldReplace: true,\n mapping,\n reason: 'Tier 1 mapping (always safe)',\n confidence: 1.0,\n };\n }\n\n // Tier 2: Check conditions\n if (mapping.tier === 2) {\n if (shouldApplyTier2(mapping, classification)) {\n return {\n shouldReplace: true,\n mapping,\n reason: `Tier 2 mapping (project: ${classification.project}, confidence: ${classification.confidence})`,\n confidence: classification.confidence ?? 0.5,\n };\n } else {\n return {\n shouldReplace: false,\n reason: 'Tier 2 conditions not met',\n confidence: 0.5,\n };\n }\n }\n\n // Tier 3: Skip\n return {\n shouldReplace: false,\n reason: 'Tier 3 mapping (too ambiguous)',\n confidence: 1.0,\n };\n }\n\n // Multiple mappings - collision scenario\n const resolvedMapping = resolveCollision(\n { soundsLike, mappings: availableMappings, count: availableMappings.length },\n classification\n );\n\n if (resolvedMapping) {\n return {\n shouldReplace: true,\n mapping: resolvedMapping,\n reason: `Collision resolved (${availableMappings.length} candidates)`,\n confidence: classification.confidence ?? 0.5,\n };\n }\n\n // Use capitalization hint as fallback (future enhancement)\n if (surroundingText && useCapitalizationHints) {\n const hint = detectCapitalizationHint(soundsLike, surroundingText);\n\n if (hint === 'common-term') {\n return {\n shouldReplace: false,\n reason: 'Capitalization hint suggests common term',\n confidence: 0.7,\n };\n }\n }\n\n // Could not resolve collision\n return {\n shouldReplace: false,\n reason: 'Collision could not be resolved',\n confidence: 0.5,\n };\n };\n\n return {\n decideReplacement,\n shouldApplyTier2,\n resolveCollision,\n detectCapitalizationHint,\n };\n};\n"],"names":["Logging.getLogger"],"mappings":";;AAyGO,MAAM,MAAA,GAAS,CAAC,MAAA,KAA+C;AAClE,EAAA,MAAM,MAAA,GAASA,SAAQ,EAAU;AAEjC,EAAA,MAAM,kBAAA,GAAqB,QAAQ,kBAAsB;AAEzD,EAAA,MAAM,sBAAA,GAAyB,QAAQ,sBAAA,IA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eAAA,GAAkB,gBAAA;AAAA,MACpB,EAAE,UAAA,EAAY,QAAA,EAAU,iBAAA,EAAmB,KAAA,EAAO,kBAAkB,MAAA,EAAO;AAAA,MAC3E;AAAA,KACJ;AAEA,IAAA,IAAI,eAAA,EAAiB;AACjB,MAAA,OAAO;AAAA,QACH,aAAA,EAAe,IAAA;AAAA,QACf,OAAA,EAAS,eAAA;AAAA,QACT,MAAA,EAAQ,CAAA,oBAAA,EAAuB,iBAAA,CAAkB,MAAM,CAAA,YAAA,CAAA;AAAA,QACvD,UAAA,EAAY,eAAe,UAAA,IAAc;AAAA,OAC7C;AAAA,IACJ;AAGA,IAAA,IAAI,mBAAmB,sBAAA,EAAwB;AAC3C,MAAA,MAAM,IAAA,GAAO,wBAAA,CAAyB,UAAA,EAAY,eAAe,CAAA;AAEjE,MAAA,IAAI,SAAS,aAAA,EAAe;AACxB,QAAA,OAAO;AAAA,UACH,aAAA,EAAe,KAAA;AAAA,UACf,MAAA,EAAQ,0CAAA;AAAA,UACR,UAAA,EAAY;AAAA,SAChB;AAAA,MACJ;AAAA,IACJ;AAGA,IAAA,OAAO;AAAA,MACH,aAAA,EAAe,KAAA;AAAA,MACf,MAAA,EAAQ,iCAAA;AAAA,MACR,UAAA,EAAY;AAAA,KAChB;AAAA,EACJ,CAAA;AAEA,EAAA,OAAO;AAAA,IACH,iBAAA;AAAA,IACA,gBAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,GACJ;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"index57.js","sources":["../src/util/text-replacer.ts"],"sourcesContent":["/**\n * Text Replacer\n *\n * Performs intelligent text replacements with case preservation and word boundary matching.\n * Core utility for the simple-replace phase.\n *\n * Part of the simple-replace optimization (Phase 2).\n */\n\nimport * as Logging from '@/logging';\nimport { SoundsLikeMapping } from './sounds-like-database';\n\n/**\n * Replacement result for a single occurrence\n */\nexport interface ReplacementOccurrence {\n /** Original text that was replaced */\n original: string;\n\n /** Replacement text */\n replacement: string;\n\n /** Position in the text where replacement occurred */\n position: number;\n\n /** The mapping that was used */\n mapping: SoundsLikeMapping;\n}\n\n/**\n * Result of applying replacements to text\n */\nexport interface ReplacementResult {\n /** The text after replacements */\n text: string;\n\n /** Number of replacements made */\n count: number;\n\n /** Detailed information about each replacement */\n occurrences: ReplacementOccurrence[];\n\n /** Mappings that were applied */\n appliedMappings: SoundsLikeMapping[];\n}\n\n/**\n * Configuration for text replacer\n */\nexport interface TextReplacerConfig {\n /** Preserve case of original text when replacing (default: true) */\n preserveCase?: boolean;\n\n /** Use word boundaries for matching (default: true) */\n useWordBoundaries?: boolean;\n\n /** Case-insensitive matching (default: true) */\n caseInsensitive?: boolean;\n}\n\n/**\n * Instance interface for text replacer\n */\nexport interface Instance {\n /**\n * Apply a set of replacements to text\n */\n applyReplacements(text: string, mappings: SoundsLikeMapping[]): ReplacementResult;\n\n /**\n * Apply a single replacement to text\n */\n applySingleReplacement(text: string, mapping: SoundsLikeMapping): ReplacementResult;\n}\n\n/**\n * Create a text replacer instance\n */\nexport const create = (config?: TextReplacerConfig): Instance => {\n const logger = Logging.getLogger();\n\n const preserveCase = config?.preserveCase ?? true;\n const useWordBoundaries = config?.useWordBoundaries ?? true;\n const caseInsensitive = config?.caseInsensitive ?? true;\n\n /**\n * Determine the case style of a string\n */\n const getCaseStyle = (text: string): 'upper' | 'lower' | 'title' | 'mixed' => {\n // Check for all uppercase first (includes single chars)\n if (text.length > 0 && text === text.toUpperCase() && text.toUpperCase() !== text.toLowerCase()) {\n return 'upper';\n }\n // Check for all lowercase\n if (text === text.toLowerCase()) {\n return 'lower';\n }\n // Check for title case (first char upper, or mixed case starting with upper)\n if (text[0] === text[0].toUpperCase()) {\n return 'title';\n }\n return 'mixed';\n };\n\n /**\n * Apply case style from original to replacement\n *\n * Case preservation means: make the replacement match the case pattern of the original\n * - \"protocol\" (lowercase) → \"protokoll\" (lowercase)\n * - \"Protocol\" (title) → \"Protokoll\" (title)\n * - \"PROTOCOL\" (upper) → \"PROTOKOLL\" (upper)\n */\n const applyCaseStyle = (replacement: string, originalCase: 'upper' | 'lower' | 'title' | 'mixed'): string => {\n switch (originalCase) {\n case 'upper':\n // ALL CAPS in original → ALL CAPS in replacement\n return replacement.toUpperCase();\n case 'lower':\n // all lowercase in original → all lowercase in replacement\n return replacement.toLowerCase();\n case 'title':\n // Title Case in original → Title Case in replacement (first char upper, rest as-is)\n return replacement.charAt(0).toUpperCase() + replacement.slice(1);\n case 'mixed':\n default:\n // Mixed case → preserve replacement's original case\n return replacement;\n }\n };\n\n /**\n * Create a regex pattern for matching\n */\n const createPattern = (soundsLike: string): RegExp => {\n // Escape special regex characters\n const escaped = soundsLike.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n // Add word boundaries if enabled\n const pattern = useWordBoundaries ? `\\\\b${escaped}\\\\b` : escaped;\n\n // Create regex with appropriate flags\n const flags = caseInsensitive ? 'gi' : 'g';\n return new RegExp(pattern, flags);\n };\n\n /**\n * Apply a single replacement to text\n */\n const applySingleReplacement = (text: string, mapping: SoundsLikeMapping): ReplacementResult => {\n const pattern = createPattern(mapping.soundsLike);\n const occurrences: ReplacementOccurrence[] = [];\n let count = 0;\n\n // Track positions to avoid double-replacement issues\n const replacements: { index: number; length: number; replacement: string }[] = [];\n\n // Find all matches\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(text)) !== null) {\n const original = match[0];\n let replacement = mapping.correctText;\n\n // Preserve case if enabled\n if (preserveCase) {\n const caseStyle = getCaseStyle(original);\n replacement = applyCaseStyle(replacement, caseStyle);\n }\n\n replacements.push({\n index: match.index,\n length: original.length,\n replacement,\n });\n\n occurrences.push({\n original,\n replacement,\n position: match.index,\n mapping,\n });\n\n count++;\n }\n\n // Apply replacements in reverse order to preserve positions\n let resultText = text;\n for (let i = replacements.length - 1; i >= 0; i--) {\n const { index, length, replacement } = replacements[i];\n resultText = resultText.slice(0, index) + replacement + resultText.slice(index + length);\n }\n\n if (count > 0) {\n logger.debug(\n `Replaced \"${mapping.soundsLike}\" → \"${mapping.correctText}\" ` +\n `(${count} occurrence${count === 1 ? '' : 's'})`\n );\n }\n\n return {\n text: resultText,\n count,\n occurrences,\n appliedMappings: count > 0 ? [mapping] : [],\n };\n };\n\n /**\n * Apply multiple replacements to text\n */\n const applyReplacements = (text: string, mappings: SoundsLikeMapping[]): ReplacementResult => {\n let resultText = text;\n let totalCount = 0;\n const allOccurrences: ReplacementOccurrence[] = [];\n const appliedMappings: SoundsLikeMapping[] = [];\n\n // Apply each mapping sequentially\n for (const mapping of mappings) {\n const result = applySingleReplacement(resultText, mapping);\n\n if (result.count > 0) {\n resultText = result.text;\n totalCount += result.count;\n allOccurrences.push(...result.occurrences);\n appliedMappings.push(mapping);\n }\n }\n\n logger.debug(\n `Applied ${mappings.length} mappings, made ${totalCount} replacements ` +\n `(${appliedMappings.length} mappings had matches)`\n );\n\n return {\n text: resultText,\n count: totalCount,\n occurrences: allOccurrences,\n appliedMappings,\n };\n };\n\n return {\n applyReplacements,\n applySingleReplacement,\n };\n};\n"],"names":["Logging.getLogger"],"mappings":";;AA8EO,MAAM,MAAA,GAAS,CAAC,MAAA,KAA0C;AAC7D,EAAA,MAAM,MAAA,GAASA,SAAQ,EAAU;AAsDjC,EAAA,MAAM,aAAA,GAAgB,CAAC,UAAA,KAA+B;AAElD,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,OAAA,CAAQ,qBAAA,EAAuB,MAAM,CAAA;AAGhE,IAAA,MAAM,OAAA,GAA8B,CAAA,GAAA,EAAM,OAAO,CAAA,GAAA,CAAA,CAAQ;AAGzD,IAAA,MAAM,KAAA,GAA0B,IAAA,CAAO;AACvC,IAAA,OAAO,IAAI,MAAA,CAAO,OAAA,EAAS,KAAK,CAAA;AAAA,EACpC,CAAA;AAKA,EAAA,MAAM,sBAAA,GAAyB,CAAC,IAAA,EAAc,OAAA,KAAkD;AAC5F,IAAA,MAAM,OAAA,GAAU,aAAA,CAAc,OAAA,CAAQ,UAAU,CA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2
|
+
import timezone from './index60.js';
|
|
3
|
+
import utc from './index61.js';
|
|
4
|
+
import 'moment-timezone';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
while ((match = pattern.exec(text)) !== null) {
|
|
18
|
-
const original = match[0];
|
|
19
|
-
let replacement = mapping.correctText;
|
|
20
|
-
replacements.push({
|
|
21
|
-
index: match.index,
|
|
22
|
-
length: original.length,
|
|
23
|
-
replacement
|
|
24
|
-
});
|
|
25
|
-
occurrences.push({
|
|
26
|
-
original,
|
|
27
|
-
replacement,
|
|
28
|
-
position: match.index,
|
|
29
|
-
mapping
|
|
30
|
-
});
|
|
31
|
-
count++;
|
|
32
|
-
}
|
|
33
|
-
let resultText = text;
|
|
34
|
-
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
35
|
-
const { index, length, replacement } = replacements[i];
|
|
36
|
-
resultText = resultText.slice(0, index) + replacement + resultText.slice(index + length);
|
|
37
|
-
}
|
|
38
|
-
if (count > 0) {
|
|
39
|
-
logger.debug(
|
|
40
|
-
`Replaced "${mapping.soundsLike}" → "${mapping.correctText}" (${count} occurrence${count === 1 ? "" : "s"})`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
text: resultText,
|
|
45
|
-
count,
|
|
46
|
-
occurrences,
|
|
47
|
-
appliedMappings: count > 0 ? [mapping] : []
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const applyReplacements = (text, mappings) => {
|
|
51
|
-
let resultText = text;
|
|
52
|
-
let totalCount = 0;
|
|
53
|
-
const allOccurrences = [];
|
|
54
|
-
const appliedMappings = [];
|
|
55
|
-
for (const mapping of mappings) {
|
|
56
|
-
const result = applySingleReplacement(resultText, mapping);
|
|
57
|
-
if (result.count > 0) {
|
|
58
|
-
resultText = result.text;
|
|
59
|
-
totalCount += result.count;
|
|
60
|
-
allOccurrences.push(...result.occurrences);
|
|
61
|
-
appliedMappings.push(mapping);
|
|
6
|
+
dayjs.extend(utc);
|
|
7
|
+
dayjs.extend(timezone);
|
|
8
|
+
const create = (parameters) => {
|
|
9
|
+
const { timezone: timezone2 } = parameters;
|
|
10
|
+
const now = () => {
|
|
11
|
+
return date(void 0);
|
|
12
|
+
};
|
|
13
|
+
const date = (date2) => {
|
|
14
|
+
let value;
|
|
15
|
+
try {
|
|
16
|
+
if (date2) {
|
|
17
|
+
value = dayjs.tz(date2, timezone2);
|
|
18
|
+
} else {
|
|
19
|
+
value = dayjs().tz(timezone2);
|
|
62
20
|
}
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new Error(`Invalid date: ${date2}, error: ${error.message}`);
|
|
23
|
+
}
|
|
24
|
+
return value.toDate();
|
|
25
|
+
};
|
|
26
|
+
const parse = (date2, format2) => {
|
|
27
|
+
let value;
|
|
28
|
+
try {
|
|
29
|
+
value = dayjs.tz(date2, format2, timezone2);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new Error(`Invalid date: ${date2}, expected format: ${format2}, error: ${error.message}`);
|
|
63
32
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
33
|
+
return value.toDate();
|
|
34
|
+
};
|
|
35
|
+
const addDays = (date2, days) => {
|
|
36
|
+
return dayjs.tz(date2, timezone2).add(days, "day").toDate();
|
|
37
|
+
};
|
|
38
|
+
const addMonths = (date2, months) => {
|
|
39
|
+
return dayjs.tz(date2, timezone2).add(months, "month").toDate();
|
|
40
|
+
};
|
|
41
|
+
const addYears = (date2, years) => {
|
|
42
|
+
return dayjs.tz(date2, timezone2).add(years, "year").toDate();
|
|
43
|
+
};
|
|
44
|
+
const format = (date2, format2) => {
|
|
45
|
+
return dayjs.tz(date2, timezone2).format(format2);
|
|
46
|
+
};
|
|
47
|
+
const subDays = (date2, days) => {
|
|
48
|
+
return dayjs.tz(date2, timezone2).subtract(days, "day").toDate();
|
|
49
|
+
};
|
|
50
|
+
const subMonths = (date2, months) => {
|
|
51
|
+
return dayjs.tz(date2, timezone2).subtract(months, "month").toDate();
|
|
52
|
+
};
|
|
53
|
+
const subYears = (date2, years) => {
|
|
54
|
+
return dayjs.tz(date2, timezone2).subtract(years, "year").toDate();
|
|
55
|
+
};
|
|
56
|
+
const startOfMonth = (date2) => {
|
|
57
|
+
return dayjs.tz(date2, timezone2).startOf("month").toDate();
|
|
58
|
+
};
|
|
59
|
+
const endOfMonth = (date2) => {
|
|
60
|
+
return dayjs.tz(date2, timezone2).endOf("month").toDate();
|
|
61
|
+
};
|
|
62
|
+
const startOfYear = (date2) => {
|
|
63
|
+
return dayjs.tz(date2, timezone2).startOf("year").toDate();
|
|
64
|
+
};
|
|
65
|
+
const endOfYear = (date2) => {
|
|
66
|
+
return dayjs.tz(date2, timezone2).endOf("year").toDate();
|
|
67
|
+
};
|
|
68
|
+
const isBefore = (date2, other) => {
|
|
69
|
+
return dayjs.tz(date2, timezone2).isBefore(dayjs.tz(other, timezone2));
|
|
70
|
+
};
|
|
71
|
+
const isAfter = (date2, other) => {
|
|
72
|
+
return dayjs.tz(date2, timezone2).isAfter(dayjs.tz(other, timezone2));
|
|
77
73
|
};
|
|
74
|
+
return { now, date, parse, addDays, addMonths, addYears, format, subDays, subMonths, subYears, startOfMonth, endOfMonth, startOfYear, endOfYear, isBefore, isAfter };
|
|
78
75
|
};
|
|
79
76
|
|
|
80
77
|
export { create };
|
package/dist/index58.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index58.js","sources":["../src/util/text-replacer.ts"],"sourcesContent":["/**\n * Text Replacer\n *\n * Performs intelligent text replacements with case preservation and word boundary matching.\n * Core utility for the simple-replace phase.\n *\n * Part of the simple-replace optimization (Phase 2).\n */\n\nimport * as Logging from '@/logging';\nimport { SoundsLikeMapping } from './sounds-like-database';\n\n/**\n * Replacement result for a single occurrence\n */\nexport interface ReplacementOccurrence {\n /** Original text that was replaced */\n original: string;\n\n /** Replacement text */\n replacement: string;\n\n /** Position in the text where replacement occurred */\n position: number;\n\n /** The mapping that was used */\n mapping: SoundsLikeMapping;\n}\n\n/**\n * Result of applying replacements to text\n */\nexport interface ReplacementResult {\n /** The text after replacements */\n text: string;\n\n /** Number of replacements made */\n count: number;\n\n /** Detailed information about each replacement */\n occurrences: ReplacementOccurrence[];\n\n /** Mappings that were applied */\n appliedMappings: SoundsLikeMapping[];\n}\n\n/**\n * Configuration for text replacer\n */\nexport interface TextReplacerConfig {\n /** Preserve case of original text when replacing (default: true) */\n preserveCase?: boolean;\n\n /** Use word boundaries for matching (default: true) */\n useWordBoundaries?: boolean;\n\n /** Case-insensitive matching (default: true) */\n caseInsensitive?: boolean;\n}\n\n/**\n * Instance interface for text replacer\n */\nexport interface Instance {\n /**\n * Apply a set of replacements to text\n */\n applyReplacements(text: string, mappings: SoundsLikeMapping[]): ReplacementResult;\n\n /**\n * Apply a single replacement to text\n */\n applySingleReplacement(text: string, mapping: SoundsLikeMapping): ReplacementResult;\n}\n\n/**\n * Create a text replacer instance\n */\nexport const create = (config?: TextReplacerConfig): Instance => {\n const logger = Logging.getLogger();\n\n const preserveCase = config?.preserveCase ?? true;\n const useWordBoundaries = config?.useWordBoundaries ?? true;\n const caseInsensitive = config?.caseInsensitive ?? true;\n\n /**\n * Determine the case style of a string\n */\n const getCaseStyle = (text: string): 'upper' | 'lower' | 'title' | 'mixed' => {\n // Check for all uppercase first (includes single chars)\n if (text.length > 0 && text === text.toUpperCase() && text.toUpperCase() !== text.toLowerCase()) {\n return 'upper';\n }\n // Check for all lowercase\n if (text === text.toLowerCase()) {\n return 'lower';\n }\n // Check for title case (first char upper, or mixed case starting with upper)\n if (text[0] === text[0].toUpperCase()) {\n return 'title';\n }\n return 'mixed';\n };\n\n /**\n * Apply case style from original to replacement\n *\n * Case preservation means: make the replacement match the case pattern of the original\n * - \"protocol\" (lowercase) → \"protokoll\" (lowercase)\n * - \"Protocol\" (title) → \"Protokoll\" (title)\n * - \"PROTOCOL\" (upper) → \"PROTOKOLL\" (upper)\n */\n const applyCaseStyle = (replacement: string, originalCase: 'upper' | 'lower' | 'title' | 'mixed'): string => {\n switch (originalCase) {\n case 'upper':\n // ALL CAPS in original → ALL CAPS in replacement\n return replacement.toUpperCase();\n case 'lower':\n // all lowercase in original → all lowercase in replacement\n return replacement.toLowerCase();\n case 'title':\n // Title Case in original → Title Case in replacement (first char upper, rest as-is)\n return replacement.charAt(0).toUpperCase() + replacement.slice(1);\n case 'mixed':\n default:\n // Mixed case → preserve replacement's original case\n return replacement;\n }\n };\n\n /**\n * Create a regex pattern for matching\n */\n const createPattern = (soundsLike: string): RegExp => {\n // Escape special regex characters\n const escaped = soundsLike.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n // Add word boundaries if enabled\n const pattern = useWordBoundaries ? `\\\\b${escaped}\\\\b` : escaped;\n\n // Create regex with appropriate flags\n const flags = caseInsensitive ? 'gi' : 'g';\n return new RegExp(pattern, flags);\n };\n\n /**\n * Apply a single replacement to text\n */\n const applySingleReplacement = (text: string, mapping: SoundsLikeMapping): ReplacementResult => {\n const pattern = createPattern(mapping.soundsLike);\n const occurrences: ReplacementOccurrence[] = [];\n let count = 0;\n\n // Track positions to avoid double-replacement issues\n const replacements: { index: number; length: number; replacement: string }[] = [];\n\n // Find all matches\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(text)) !== null) {\n const original = match[0];\n let replacement = mapping.correctText;\n\n // Preserve case if enabled\n if (preserveCase) {\n const caseStyle = getCaseStyle(original);\n replacement = applyCaseStyle(replacement, caseStyle);\n }\n\n replacements.push({\n index: match.index,\n length: original.length,\n replacement,\n });\n\n occurrences.push({\n original,\n replacement,\n position: match.index,\n mapping,\n });\n\n count++;\n }\n\n // Apply replacements in reverse order to preserve positions\n let resultText = text;\n for (let i = replacements.length - 1; i >= 0; i--) {\n const { index, length, replacement } = replacements[i];\n resultText = resultText.slice(0, index) + replacement + resultText.slice(index + length);\n }\n\n if (count > 0) {\n logger.debug(\n `Replaced \"${mapping.soundsLike}\" → \"${mapping.correctText}\" ` +\n `(${count} occurrence${count === 1 ? '' : 's'})`\n );\n }\n\n return {\n text: resultText,\n count,\n occurrences,\n appliedMappings: count > 0 ? [mapping] : [],\n };\n };\n\n /**\n * Apply multiple replacements to text\n */\n const applyReplacements = (text: string, mappings: SoundsLikeMapping[]): ReplacementResult => {\n let resultText = text;\n let totalCount = 0;\n const allOccurrences: ReplacementOccurrence[] = [];\n const appliedMappings: SoundsLikeMapping[] = [];\n\n // Apply each mapping sequentially\n for (const mapping of mappings) {\n const result = applySingleReplacement(resultText, mapping);\n\n if (result.count > 0) {\n resultText = result.text;\n totalCount += result.count;\n allOccurrences.push(...result.occurrences);\n appliedMappings.push(mapping);\n }\n }\n\n logger.debug(\n `Applied ${mappings.length} mappings, made ${totalCount} replacements ` +\n `(${appliedMappings.length} mappings had matches)`\n );\n\n return {\n text: resultText,\n count: totalCount,\n occurrences: allOccurrences,\n appliedMappings,\n };\n };\n\n return {\n applyReplacements,\n applySingleReplacement,\n };\n};\n"],"names":["Logging.getLogger"],"mappings":";;AA8EO,MAAM,MAAA,GAAS,CAAC,MAAA,KAA0C;AAC7D,EAAA,MAAM,MAAA,GAASA,SAAQ,EAAU;AAsDjC,EAAA,MAAM,aAAA,GAAgB,CAAC,UAAA,KAA+B;AAElD,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,OAAA,CAAQ,qBAAA,EAAuB,MAAM,CAAA;AAGhE,IAAA,MAAM,OAAA,GAA8B,CAAA,GAAA,EAAM,OAAO,CAAA,GAAA,CAAA,CAAQ;AAGzD,IAAA,MAAM,KAAA,GAA0B,IAAA,C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AAA;AAAA,MACb;AAAA,KACJ;AAAA,EACJ,CAAA;AAEA,EAAA,OAAO;AAAA,IACH,iBAAA;AAAA,IACA;AAAA,GACJ;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"index58.js","sources":["../src/util/dates.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport dayjs from 'dayjs';\nimport timezone from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n// eslint-disable-next-line no-restricted-imports\nimport moment from 'moment-timezone';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\n\n/**\n * Yes, wrapping dayjs is a bit annoying and might seem overly paranoid. However, I feel strongly\n * about not letting Dayjs instances leak into the rest of the codebase. Having Dayjs objects\n * floating around the application leads to inconsistent timezone handling, makes testing more\n * difficult, and creates subtle bugs that are hard to track down.\n * \n * By wrapping dayjs completely and only exposing plain JavaScript Date objects, we get several\n * key benefits:\n * 1. Consistent timezone handling through a single configuration point\n * 2. Simpler testing since we only need to mock this one library\n * 3. Type safety - the rest of the codebase only deals with standard Date objects\n * 4. No risk of dayjs method chains creating unexpected timezone shifts\n * \n * The Library interface gives us full control over all date operations while keeping the messy\n * details of timezone manipulation contained in one place. Yes it's more code, but the peace of\n * mind is worth it.\n */\nexport interface Utility {\n now: () => Date;\n date: (date: string | number | Date | null | undefined) => Date;\n parse: (date: string | number | Date | null | undefined, format: string) => Date;\n addDays: (date: Date, days: number) => Date;\n addMonths: (date: Date, months: number) => Date;\n addYears: (date: Date, years: number) => Date;\n format: (date: Date, format: string) => string;\n subDays: (date: Date, days: number) => Date;\n subMonths: (date: Date, months: number) => Date;\n subYears: (date: Date, years: number) => Date;\n startOfMonth: (date: Date) => Date;\n endOfMonth: (date: Date) => Date;\n startOfYear: (date: Date) => Date;\n endOfYear: (date: Date) => Date;\n isBefore: (date: Date, other: Date) => boolean;\n isAfter: (date: Date, other: Date) => boolean;\n}\n\nexport const create = (parameters: { timezone: string }) => {\n const { timezone } = parameters;\n const now = () => {\n return date(undefined);\n }\n\n const date = (date: string | number | Date | null | undefined) => {\n let value: dayjs.Dayjs;\n try {\n if (date) {\n value = dayjs.tz(date, timezone);\n } else {\n value = dayjs().tz(timezone);\n }\n } catch (error: any) {\n throw new Error(`Invalid date: ${date}, error: ${error.message}`);\n }\n\n return value.toDate();\n }\n\n const parse = (date: string | number | Date | null | undefined, format: string) => {\n let value: dayjs.Dayjs;\n try {\n value = dayjs.tz(date, format, timezone);\n } catch (error: any) {\n throw new Error(`Invalid date: ${date}, expected format: ${format}, error: ${error.message}`);\n }\n\n return value.toDate();\n }\n\n const addDays = (date: Date, days: number) => {\n return dayjs.tz(date, timezone).add(days, 'day').toDate();\n }\n\n const addMonths = (date: Date, months: number) => {\n return dayjs.tz(date, timezone).add(months, 'month').toDate();\n }\n\n const addYears = (date: Date, years: number) => {\n return dayjs.tz(date, timezone).add(years, 'year').toDate();\n }\n\n const format = (date: Date, format: string) => {\n return dayjs.tz(date, timezone).format(format);\n }\n\n const subDays = (date: Date, days: number) => {\n return dayjs.tz(date, timezone).subtract(days, 'day').toDate();\n }\n\n const subMonths = (date: Date, months: number) => {\n return dayjs.tz(date, timezone).subtract(months, 'month').toDate();\n }\n\n const subYears = (date: Date, years: number) => {\n return dayjs.tz(date, timezone).subtract(years, 'year').toDate();\n }\n\n const startOfMonth = (date: Date) => {\n return dayjs.tz(date, timezone).startOf('month').toDate();\n }\n\n const endOfMonth = (date: Date) => {\n return dayjs.tz(date, timezone).endOf('month').toDate();\n }\n\n const startOfYear = (date: Date) => {\n return dayjs.tz(date, timezone).startOf('year').toDate();\n }\n\n const endOfYear = (date: Date) => {\n return dayjs.tz(date, timezone).endOf('year').toDate();\n }\n\n const isBefore = (date: Date, other: Date) => {\n return dayjs.tz(date, timezone).isBefore(dayjs.tz(other, timezone));\n }\n\n const isAfter = (date: Date, other: Date) => {\n return dayjs.tz(date, timezone).isAfter(dayjs.tz(other, timezone));\n }\n\n return { now, date, parse, addDays, addMonths, addYears, format, subDays, subMonths, subYears, startOfMonth, endOfMonth, startOfYear, endOfYear, isBefore, isAfter };\n}\n\nexport const validTimezones = () => {\n return moment.tz.names();\n}\n"],"names":["timezone","date","format"],"mappings":";;;;;AAOA,KAAA,CAAM,OAAO,GAAG,CAAA;AAChB,KAAA,CAAM,OAAO,QAAQ,CAAA;AAsCd,MAAM,MAAA,GAAS,CAAC,UAAA,KAAqC;AACxD,EAAA,MAAM,EAAE,QAAA,EAAAA,SAAAA,EAAS,GAAI,UAAA;AACrB,EAAA,MAAM,MAAM,MAAM;AACd,IAAA,OAAO,KAAK,MAAS,CAAA;AAAA,EACzB,CAAA;AAEA,EAAA,MAAM,IAAA,GAAO,CAACC,KAAAA,KAAoD;AAC9D,IAAA,IAAI,KAAA;AACJ,IAAA,IAAI;AACA,MAAA,IAAIA,KAAAA,EAAM;AACN,QAAA,KAAA,GAAQ,KAAA,CAAM,EAAA,CAAGA,KAAAA,EAAMD,SAAQ,CAAA;AAAA,MACnC,CAAA,MAAO;AACH,QAAA,KAAA,GAAQ,KAAA,EAAM,CAAE,EAAA,CAAGA,SAAQ,CAAA;AAAA,MAC/B;AAAA,IACJ,SAAS,KAAA,EAAY;AACjB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,cAAA,EAAiBC,KAAI,CAAA,SAAA,EAAY,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,IACpE;AAEA,IAAA,OAAO,MAAM,MAAA,EAAO;AAAA,EACxB,CAAA;AAEA,EAAA,MAAM,KAAA,GAAQ,CAACA,KAAAA,EAAiDC,OAAAA,KAAmB;AAC/E,IAAA,IAAI,KAAA;AACJ,IAAA,IAAI;AACA,MAAA,KAAA,GAAQ,KAAA,CAAM,EAAA,CAAGD,KAAAA,EAAMC,OAAAA,EAAQF,SAAQ,CAAA;AAAA,IAC3C,SAAS,KAAA,EAAY;AACjB,MAAA,MAAM,IAAI,MAAM,CAAA,cAAA,EAAiBC,KAAI,sBAAsBC,OAAM,CAAA,SAAA,EAA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AA,OAAO,KAAA,CAAM,EAAA,CAAGA,KAAAA,EAAMD,SAAQ,CAAA,CAAE,QAAQ,KAAA,CAAM,EAAA,CAAG,KAAA,EAAOA,SAAQ,CAAC,CAAA;AAAA,EACrE,CAAA;AAEA,EAAA,OAAO,EAAE,GAAA,EAAK,IAAA,EAAM,KAAA,EAAO,OAAA,EAAS,WAAW,QAAA,EAAU,MAAA,EAAQ,OAAA,EAAS,SAAA,EAAW,UAAU,YAAA,EAAc,UAAA,EAAY,WAAA,EAAa,SAAA,EAAW,UAAU,OAAA,EAAQ;AACvK;;;;"}
|
package/dist/index59.js
CHANGED
|
@@ -1,77 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import timezone from './index61.js';
|
|
3
|
-
import utc from './index62.js';
|
|
4
|
-
import 'moment-timezone';
|
|
1
|
+
import { create as create$1 } from './index62.js';
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const create = (parameters) => {
|
|
9
|
-
const { timezone: timezone2 } = parameters;
|
|
10
|
-
const now = () => {
|
|
11
|
-
return date(void 0);
|
|
12
|
-
};
|
|
13
|
-
const date = (date2) => {
|
|
14
|
-
let value;
|
|
15
|
-
try {
|
|
16
|
-
if (date2) {
|
|
17
|
-
value = dayjs.tz(date2, timezone2);
|
|
18
|
-
} else {
|
|
19
|
-
value = dayjs().tz(timezone2);
|
|
20
|
-
}
|
|
21
|
-
} catch (error) {
|
|
22
|
-
throw new Error(`Invalid date: ${date2}, error: ${error.message}`);
|
|
23
|
-
}
|
|
24
|
-
return value.toDate();
|
|
25
|
-
};
|
|
26
|
-
const parse = (date2, format2) => {
|
|
27
|
-
let value;
|
|
28
|
-
try {
|
|
29
|
-
value = dayjs.tz(date2, format2, timezone2);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
throw new Error(`Invalid date: ${date2}, expected format: ${format2}, error: ${error.message}`);
|
|
32
|
-
}
|
|
33
|
-
return value.toDate();
|
|
34
|
-
};
|
|
35
|
-
const addDays = (date2, days) => {
|
|
36
|
-
return dayjs.tz(date2, timezone2).add(days, "day").toDate();
|
|
37
|
-
};
|
|
38
|
-
const addMonths = (date2, months) => {
|
|
39
|
-
return dayjs.tz(date2, timezone2).add(months, "month").toDate();
|
|
40
|
-
};
|
|
41
|
-
const addYears = (date2, years) => {
|
|
42
|
-
return dayjs.tz(date2, timezone2).add(years, "year").toDate();
|
|
43
|
-
};
|
|
44
|
-
const format = (date2, format2) => {
|
|
45
|
-
return dayjs.tz(date2, timezone2).format(format2);
|
|
46
|
-
};
|
|
47
|
-
const subDays = (date2, days) => {
|
|
48
|
-
return dayjs.tz(date2, timezone2).subtract(days, "day").toDate();
|
|
49
|
-
};
|
|
50
|
-
const subMonths = (date2, months) => {
|
|
51
|
-
return dayjs.tz(date2, timezone2).subtract(months, "month").toDate();
|
|
52
|
-
};
|
|
53
|
-
const subYears = (date2, years) => {
|
|
54
|
-
return dayjs.tz(date2, timezone2).subtract(years, "year").toDate();
|
|
55
|
-
};
|
|
56
|
-
const startOfMonth = (date2) => {
|
|
57
|
-
return dayjs.tz(date2, timezone2).startOf("month").toDate();
|
|
58
|
-
};
|
|
59
|
-
const endOfMonth = (date2) => {
|
|
60
|
-
return dayjs.tz(date2, timezone2).endOf("month").toDate();
|
|
61
|
-
};
|
|
62
|
-
const startOfYear = (date2) => {
|
|
63
|
-
return dayjs.tz(date2, timezone2).startOf("year").toDate();
|
|
64
|
-
};
|
|
65
|
-
const endOfYear = (date2) => {
|
|
66
|
-
return dayjs.tz(date2, timezone2).endOf("year").toDate();
|
|
67
|
-
};
|
|
68
|
-
const isBefore = (date2, other) => {
|
|
69
|
-
return dayjs.tz(date2, timezone2).isBefore(dayjs.tz(other, timezone2));
|
|
70
|
-
};
|
|
71
|
-
const isAfter = (date2, other) => {
|
|
72
|
-
return dayjs.tz(date2, timezone2).isAfter(dayjs.tz(other, timezone2));
|
|
73
|
-
};
|
|
74
|
-
return { now, date, parse, addDays, addMonths, addYears, format, subDays, subMonths, subYears, startOfMonth, endOfMonth, startOfYear, endOfYear, isBefore, isAfter };
|
|
3
|
+
const create = (config) => {
|
|
4
|
+
return create$1(config);
|
|
75
5
|
};
|
|
76
6
|
|
|
77
7
|
export { create };
|
package/dist/index59.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index59.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index59.js","sources":["../src/out/index.ts"],"sourcesContent":["/**\n * Output Management System\n *\n * Main entry point for the output management system. Handles intermediate\n * files and final output destinations.\n */\n\nimport { OutputConfig, OutputPaths, IntermediateFiles, RawTranscriptData } from './types';\nimport * as Manager from './manager';\nimport * as Metadata from '../util/metadata';\n\nexport interface OutputInstance {\n createOutputPaths(\n audioFile: string,\n routedDestination: string,\n hash: string,\n date: Date\n ): OutputPaths;\n ensureDirectories(paths: OutputPaths): Promise<void>;\n writeIntermediate(\n paths: OutputPaths,\n type: keyof IntermediateFiles,\n content: unknown\n ): Promise<string>;\n /**\n * Write the raw Whisper transcript to the .transcript/ directory alongside final output.\n * This enables compare and reanalyze workflows.\n */\n writeRawTranscript(paths: OutputPaths, data: RawTranscriptData): Promise<string>;\n writeTranscript(paths: OutputPaths, content: string, metadata?: Metadata.TranscriptMetadata): Promise<string>;\n /**\n * Read a previously stored raw transcript from the .transcript/ directory.\n * Returns null if no raw transcript exists.\n */\n readRawTranscript(finalOutputPath: string): Promise<RawTranscriptData | null>;\n cleanIntermediates(paths: OutputPaths): Promise<void>;\n}\n\nexport const create = (config: OutputConfig): OutputInstance => {\n return Manager.create(config);\n};\n\nexport const DEFAULT_OUTPUT_CONFIG: OutputConfig = {\n intermediateDir: './output/protokoll',\n keepIntermediates: true,\n timestampFormat: 'YYMMDD-HHmm',\n};\n\n// Re-export types\nexport * from './types';\n"],"names":["Manager.create"],"mappings":";;AAsCO,MAAM,MAAA,GAAS,CAAC,MAAA,KAAyC;AAC5D,EAAA,OAAOA,SAAe,MAAM,CAAA;AAChC;;;;"}
|