@sharpee/lang-en-us 1.5.0 → 2.1.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/actions/about.d.ts +1 -0
- package/actions/about.d.ts.map +1 -1
- package/actions/about.js +15 -8
- package/actions/about.js.map +1 -1
- package/actions/again.d.ts.map +1 -1
- package/actions/again.js.map +1 -1
- package/actions/answering.d.ts.map +1 -1
- package/actions/answering.js.map +1 -1
- package/actions/asking.d.ts.map +1 -1
- package/actions/asking.js +14 -14
- package/actions/asking.js.map +1 -1
- package/actions/attacking.d.ts.map +1 -1
- package/actions/attacking.js +51 -51
- package/actions/attacking.js.map +1 -1
- package/actions/climbing.d.ts.map +1 -1
- package/actions/climbing.js +4 -4
- package/actions/climbing.js.map +1 -1
- package/actions/closing.d.ts.map +1 -1
- package/actions/closing.js +5 -5
- package/actions/closing.js.map +1 -1
- package/actions/drinking.d.ts.map +1 -1
- package/actions/drinking.js +20 -20
- package/actions/drinking.js.map +1 -1
- package/actions/dropping.d.ts.map +1 -1
- package/actions/dropping.js +3 -3
- package/actions/dropping.js.map +1 -1
- package/actions/eating.d.ts.map +1 -1
- package/actions/eating.js +20 -20
- package/actions/eating.js.map +1 -1
- package/actions/entering.d.ts.map +1 -1
- package/actions/entering.js +10 -10
- package/actions/entering.js.map +1 -1
- package/actions/examining.d.ts.map +1 -1
- package/actions/examining.js +28 -23
- package/actions/examining.js.map +1 -1
- package/actions/exiting.d.ts.map +1 -1
- package/actions/exiting.js +4 -4
- package/actions/exiting.js.map +1 -1
- package/actions/giving.d.ts.map +1 -1
- package/actions/giving.js +12 -12
- package/actions/giving.js.map +1 -1
- package/actions/going.d.ts.map +1 -1
- package/actions/going.js +7 -7
- package/actions/going.js.map +1 -1
- package/actions/help.d.ts +3 -3
- package/actions/help.d.ts.map +1 -1
- package/actions/help.js +9 -7
- package/actions/help.js.map +1 -1
- package/actions/hiding.d.ts.map +1 -1
- package/actions/hiding.js.map +1 -1
- package/actions/index.d.ts +5 -3
- package/actions/index.d.ts.map +1 -1
- package/actions/index.js.map +1 -1
- package/actions/inserting.d.ts.map +1 -1
- package/actions/inserting.js +8 -8
- package/actions/inserting.js.map +1 -1
- package/actions/inventory.d.ts.map +1 -1
- package/actions/inventory.js.map +1 -1
- package/actions/listening.d.ts.map +1 -1
- package/actions/listening.js +7 -7
- package/actions/listening.js.map +1 -1
- package/actions/locking.d.ts.map +1 -1
- package/actions/locking.js +8 -8
- package/actions/locking.js.map +1 -1
- package/actions/looking.d.ts.map +1 -1
- package/actions/looking.js +5 -5
- package/actions/looking.js.map +1 -1
- package/actions/lowering.d.ts.map +1 -1
- package/actions/lowering.js +2 -2
- package/actions/lowering.js.map +1 -1
- package/actions/opening.d.ts.map +1 -1
- package/actions/opening.js +7 -7
- package/actions/opening.js.map +1 -1
- package/actions/pulling.d.ts.map +1 -1
- package/actions/pulling.js +19 -19
- package/actions/pulling.js.map +1 -1
- package/actions/pushing.d.ts.map +1 -1
- package/actions/pushing.js +14 -14
- package/actions/pushing.js.map +1 -1
- package/actions/putting.d.ts.map +1 -1
- package/actions/putting.js +12 -12
- package/actions/putting.js.map +1 -1
- package/actions/quitting.d.ts.map +1 -1
- package/actions/quitting.js.map +1 -1
- package/actions/raising.d.ts.map +1 -1
- package/actions/raising.js +2 -2
- package/actions/raising.js.map +1 -1
- package/actions/reading.d.ts.map +1 -1
- package/actions/reading.js +10 -8
- package/actions/reading.js.map +1 -1
- package/actions/removing.d.ts.map +1 -1
- package/actions/removing.js +8 -8
- package/actions/removing.js.map +1 -1
- package/actions/restoring.d.ts.map +1 -1
- package/actions/restoring.js +6 -6
- package/actions/restoring.js.map +1 -1
- package/actions/saving.d.ts.map +1 -1
- package/actions/saving.js +6 -6
- package/actions/saving.js.map +1 -1
- package/actions/scoring.d.ts.map +1 -1
- package/actions/scoring.js.map +1 -1
- package/actions/searching.d.ts.map +1 -1
- package/actions/searching.js +7 -7
- package/actions/searching.js.map +1 -1
- package/actions/showing.d.ts.map +1 -1
- package/actions/showing.js +11 -11
- package/actions/showing.js.map +1 -1
- package/actions/sleeping.d.ts.map +1 -1
- package/actions/sleeping.js.map +1 -1
- package/actions/smelling.d.ts.map +1 -1
- package/actions/smelling.js +10 -10
- package/actions/smelling.js.map +1 -1
- package/actions/switching-off.d.ts.map +1 -1
- package/actions/switching-off.js +12 -12
- package/actions/switching-off.js.map +1 -1
- package/actions/switching-on.d.ts.map +1 -1
- package/actions/switching-on.js +12 -12
- package/actions/switching-on.js.map +1 -1
- package/actions/taking-off.d.ts.map +1 -1
- package/actions/taking-off.js +4 -4
- package/actions/taking-off.js.map +1 -1
- package/actions/taking.d.ts +1 -0
- package/actions/taking.d.ts.map +1 -1
- package/actions/taking.js +7 -5
- package/actions/taking.js.map +1 -1
- package/actions/talking.d.ts.map +1 -1
- package/actions/talking.js +15 -15
- package/actions/talking.js.map +1 -1
- package/actions/telling.d.ts.map +1 -1
- package/actions/telling.js +13 -13
- package/actions/telling.js.map +1 -1
- package/actions/throwing.d.ts.map +1 -1
- package/actions/throwing.js +21 -21
- package/actions/throwing.js.map +1 -1
- package/actions/touching.d.ts.map +1 -1
- package/actions/touching.js +20 -20
- package/actions/touching.js.map +1 -1
- package/actions/turning.d.ts.map +1 -1
- package/actions/turning.js +24 -24
- package/actions/turning.js.map +1 -1
- package/actions/undoing.d.ts.map +1 -1
- package/actions/undoing.js.map +1 -1
- package/actions/unlocking.d.ts.map +1 -1
- package/actions/unlocking.js +8 -8
- package/actions/unlocking.js.map +1 -1
- package/actions/version.d.ts.map +1 -1
- package/actions/version.js +3 -3
- package/actions/version.js.map +1 -1
- package/actions/waiting.d.ts.map +1 -1
- package/actions/waiting.js +1 -1
- package/actions/waiting.js.map +1 -1
- package/actions/wearing.d.ts.map +1 -1
- package/actions/wearing.js +5 -5
- package/actions/wearing.js.map +1 -1
- package/assembler/english-assembler.d.ts +66 -0
- package/assembler/english-assembler.d.ts.map +1 -0
- package/assembler/english-assembler.js +806 -0
- package/assembler/english-assembler.js.map +1 -0
- package/assembler/errors.d.ts +23 -0
- package/assembler/errors.d.ts.map +1 -0
- package/assembler/errors.js +35 -0
- package/assembler/errors.js.map +1 -0
- package/assembler/index.d.ts +10 -0
- package/assembler/index.d.ts.map +1 -0
- package/assembler/index.js +17 -0
- package/assembler/index.js.map +1 -0
- package/data/events.d.ts.map +1 -1
- package/data/events.js +11 -11
- package/data/events.js.map +1 -1
- package/data/messages.d.ts.map +1 -1
- package/data/messages.js +1 -1
- package/data/messages.js.map +1 -1
- package/data/verbs.d.ts.map +1 -1
- package/data/verbs.js.map +1 -1
- package/data/words.d.ts.map +1 -1
- package/data/words.js.map +1 -1
- package/grammar.d.ts.map +1 -1
- package/grammar.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.d.ts.map +1 -1
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/language-provider.d.ts +50 -24
- package/language-provider.d.ts.map +1 -1
- package/language-provider.js +96 -40
- package/language-provider.js.map +1 -1
- package/npc/conversation.d.ts +5 -0
- package/npc/conversation.d.ts.map +1 -1
- package/npc/conversation.js +24 -19
- package/npc/conversation.js.map +1 -1
- package/npc/index.d.ts.map +1 -1
- package/npc/index.js.map +1 -1
- package/npc/influence.d.ts.map +1 -1
- package/npc/influence.js +4 -4
- package/npc/influence.js.map +1 -1
- package/npc/npc.d.ts +6 -0
- package/npc/npc.d.ts.map +1 -1
- package/npc/npc.js +39 -33
- package/npc/npc.js.map +1 -1
- package/npc/propagation.d.ts.map +1 -1
- package/npc/propagation.js +6 -6
- package/npc/propagation.js.map +1 -1
- package/number-words.d.ts +18 -0
- package/number-words.d.ts.map +1 -1
- package/number-words.js +77 -0
- package/number-words.js.map +1 -1
- package/package.json +3 -3
- package/parser/index.d.ts +8 -0
- package/parser/index.d.ts.map +1 -0
- package/parser/index.js +13 -0
- package/parser/index.js.map +1 -0
- package/parser/parse-phrase-template.d.ts +62 -0
- package/parser/parse-phrase-template.d.ts.map +1 -0
- package/parser/parse-phrase-template.js +384 -0
- package/parser/parse-phrase-template.js.map +1 -0
- package/perspective/index.d.ts.map +1 -1
- package/perspective/index.js.map +1 -1
- package/perspective/placeholder-resolver.d.ts +1 -1
- package/perspective/placeholder-resolver.d.ts.map +1 -1
- package/perspective/placeholder-resolver.js +12 -1
- package/perspective/placeholder-resolver.js.map +1 -1
- package/platform-messages.d.ts +26 -0
- package/platform-messages.d.ts.map +1 -0
- package/platform-messages.js +31 -0
- package/platform-messages.js.map +1 -0
- package/pluralize.d.ts.map +1 -1
- package/pluralize.js.map +1 -1
- package/sound-messages.d.ts +8 -8
- package/sound-messages.d.ts.map +1 -1
- package/sound-messages.js +8 -8
- package/sound-messages.js.map +1 -1
- package/formatters/article.d.ts +0 -41
- package/formatters/article.d.ts.map +0 -1
- package/formatters/article.js +0 -143
- package/formatters/article.js.map +0 -1
- package/formatters/index.d.ts +0 -19
- package/formatters/index.d.ts.map +0 -1
- package/formatters/index.js +0 -42
- package/formatters/index.js.map +0 -1
- package/formatters/list.d.ts +0 -56
- package/formatters/list.d.ts.map +0 -1
- package/formatters/list.js +0 -178
- package/formatters/list.js.map +0 -1
- package/formatters/registry.d.ts +0 -49
- package/formatters/registry.d.ts.map +0 -1
- package/formatters/registry.js +0 -136
- package/formatters/registry.js.map +0 -1
- package/formatters/text.d.ts +0 -33
- package/formatters/text.d.ts.map +0 -1
- package/formatters/text.js +0 -80
- package/formatters/text.js.map +0 -1
- package/formatters/types.d.ts +0 -52
- package/formatters/types.d.ts.map +0 -1
- package/formatters/types.js +0 -14
- package/formatters/types.js.map +0 -1
- package/formatters/verb.d.ts +0 -30
- package/formatters/verb.d.ts.map +0 -1
- package/formatters/verb.js +0 -59
- package/formatters/verb.js.map +0 -1
package/formatters/registry.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Formatter Registry
|
|
4
|
-
*
|
|
5
|
-
* Central registry of all formatters, with support for story extensions.
|
|
6
|
-
*
|
|
7
|
-
* @see ADR-095 Message Templates with Formatters
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.createFormatterRegistry = createFormatterRegistry;
|
|
11
|
-
exports.parsePlaceholder = parsePlaceholder;
|
|
12
|
-
exports.applyFormatters = applyFormatters;
|
|
13
|
-
exports.formatMessage = formatMessage;
|
|
14
|
-
const article_js_1 = require("./article.js");
|
|
15
|
-
const list_js_1 = require("./list.js");
|
|
16
|
-
const text_js_1 = require("./text.js");
|
|
17
|
-
const verb_js_1 = require("./verb.js");
|
|
18
|
-
/**
|
|
19
|
-
* Create the default formatter registry with all built-in formatters
|
|
20
|
-
*/
|
|
21
|
-
function createFormatterRegistry() {
|
|
22
|
-
const registry = new Map();
|
|
23
|
-
// Article formatters
|
|
24
|
-
registry.set('a', article_js_1.aFormatter);
|
|
25
|
-
registry.set('an', article_js_1.aFormatter); // Alias
|
|
26
|
-
registry.set('the', article_js_1.theFormatter);
|
|
27
|
-
registry.set('some', article_js_1.someFormatter);
|
|
28
|
-
registry.set('your', article_js_1.yourFormatter);
|
|
29
|
-
// List formatters
|
|
30
|
-
registry.set('list', list_js_1.listFormatter);
|
|
31
|
-
registry.set('the-list', list_js_1.theListFormatter);
|
|
32
|
-
registry.set('names', list_js_1.namesFormatter);
|
|
33
|
-
registry.set('or-list', list_js_1.orListFormatter);
|
|
34
|
-
registry.set('comma-list', list_js_1.commaListFormatter);
|
|
35
|
-
registry.set('count', list_js_1.countFormatter);
|
|
36
|
-
// Text formatters
|
|
37
|
-
registry.set('cap', text_js_1.capFormatter);
|
|
38
|
-
registry.set('upper', text_js_1.upperFormatter);
|
|
39
|
-
registry.set('lower', text_js_1.lowerFormatter);
|
|
40
|
-
registry.set('title', text_js_1.titleFormatter);
|
|
41
|
-
// Verb-agreement formatters (keyed to a placeholder's grammatical number)
|
|
42
|
-
registry.set('is', verb_js_1.isFormatter);
|
|
43
|
-
registry.set('was', verb_js_1.wasFormatter);
|
|
44
|
-
registry.set('has', verb_js_1.hasFormatter);
|
|
45
|
-
return registry;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parse a placeholder with formatters
|
|
49
|
-
*
|
|
50
|
-
* Syntax: {formatter:formatter:...:placeholder}
|
|
51
|
-
*
|
|
52
|
-
* @returns Object with formatters array and final placeholder name
|
|
53
|
-
*/
|
|
54
|
-
function parsePlaceholder(placeholder) {
|
|
55
|
-
const parts = placeholder.split(':');
|
|
56
|
-
if (parts.length === 1) {
|
|
57
|
-
return { formatters: [], name: parts[0] };
|
|
58
|
-
}
|
|
59
|
-
// Last part is the placeholder name, everything before is formatters
|
|
60
|
-
const name = parts[parts.length - 1];
|
|
61
|
-
const formatters = parts.slice(0, -1);
|
|
62
|
-
return { formatters, name };
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Apply formatters to a value in sequence
|
|
66
|
-
*
|
|
67
|
-
* @param value - The value to format
|
|
68
|
-
* @param formatters - Array of formatter names to apply in order
|
|
69
|
-
* @param registry - The formatter registry
|
|
70
|
-
* @param context - Formatting context
|
|
71
|
-
* @returns Formatted string
|
|
72
|
-
*/
|
|
73
|
-
function applyFormatters(value, formatters, registry, context) {
|
|
74
|
-
// Convert numbers/booleans to strings first
|
|
75
|
-
let result = (typeof value === 'number' || typeof value === 'boolean') ? String(value) : value;
|
|
76
|
-
for (const formatterName of formatters) {
|
|
77
|
-
const formatter = registry.get(formatterName);
|
|
78
|
-
if (formatter) {
|
|
79
|
-
// Apply formatter - result becomes a string
|
|
80
|
-
const formatted = formatter(result, context);
|
|
81
|
-
result = formatted;
|
|
82
|
-
}
|
|
83
|
-
// If formatter not found, skip it (could log warning)
|
|
84
|
-
}
|
|
85
|
-
// Ensure we return a string
|
|
86
|
-
if (Array.isArray(result)) {
|
|
87
|
-
return result.map((v) => (typeof v === 'string' ? v : v.name)).join(', ');
|
|
88
|
-
}
|
|
89
|
-
if (typeof result === 'string') {
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
return result.name;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Format a message template with placeholders
|
|
96
|
-
*
|
|
97
|
-
* Supports both:
|
|
98
|
-
* - Simple placeholders: {item}
|
|
99
|
-
* - Formatted placeholders: {a:item}, {list:items}, {the:cap:item}
|
|
100
|
-
* (the placeholder is the last colon segment)
|
|
101
|
-
*
|
|
102
|
-
* @param template - Message template with {placeholder} syntax
|
|
103
|
-
* @param params - Values for placeholders
|
|
104
|
-
* @param registry - Formatter registry
|
|
105
|
-
* @param context - Formatting context
|
|
106
|
-
* @returns Formatted message
|
|
107
|
-
*/
|
|
108
|
-
function formatMessage(template, params, registry, context = {}) {
|
|
109
|
-
// Match {anything} placeholders
|
|
110
|
-
return template.replace(/\{([^}]+)\}/g, (match, placeholder) => {
|
|
111
|
-
const { formatters, name } = parsePlaceholder(placeholder);
|
|
112
|
-
// Get the value for this placeholder
|
|
113
|
-
const value = params[name];
|
|
114
|
-
if (value === undefined) {
|
|
115
|
-
// Placeholder not found in params - leave it as is
|
|
116
|
-
// (might be a perspective placeholder like {You})
|
|
117
|
-
return match;
|
|
118
|
-
}
|
|
119
|
-
// Apply formatters
|
|
120
|
-
if (formatters.length > 0) {
|
|
121
|
-
return applyFormatters(value, formatters, registry, context);
|
|
122
|
-
}
|
|
123
|
-
// No formatters - just convert to string
|
|
124
|
-
if (Array.isArray(value)) {
|
|
125
|
-
return value.map((v) => (typeof v === 'string' ? v : v.name)).join(', ');
|
|
126
|
-
}
|
|
127
|
-
if (typeof value === 'string') {
|
|
128
|
-
return value;
|
|
129
|
-
}
|
|
130
|
-
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
131
|
-
return String(value);
|
|
132
|
-
}
|
|
133
|
-
return value.name;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","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AAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3E,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/formatters/text.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text Formatters
|
|
3
|
-
*
|
|
4
|
-
* Formatters for case transformation and text manipulation.
|
|
5
|
-
*
|
|
6
|
-
* @see ADR-095 Message Templates with Formatters
|
|
7
|
-
*/
|
|
8
|
-
import type { Formatter } from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* "cap" formatter - capitalize first letter
|
|
11
|
-
*
|
|
12
|
-
* "sword" → "Sword"
|
|
13
|
-
*/
|
|
14
|
-
export declare const capFormatter: Formatter;
|
|
15
|
-
/**
|
|
16
|
-
* "upper" formatter - all uppercase
|
|
17
|
-
*
|
|
18
|
-
* "sword" → "SWORD"
|
|
19
|
-
*/
|
|
20
|
-
export declare const upperFormatter: Formatter;
|
|
21
|
-
/**
|
|
22
|
-
* "lower" formatter - all lowercase
|
|
23
|
-
*
|
|
24
|
-
* "SWORD" → "sword"
|
|
25
|
-
*/
|
|
26
|
-
export declare const lowerFormatter: Formatter;
|
|
27
|
-
/**
|
|
28
|
-
* "title" formatter - title case (capitalize each word)
|
|
29
|
-
*
|
|
30
|
-
* "brass lantern" → "Brass Lantern"
|
|
31
|
-
*/
|
|
32
|
-
export declare const titleFormatter: Formatter;
|
|
33
|
-
//# sourceMappingURL=text.d.ts.map
|
package/formatters/text.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,YAAY,CAAC;AASxD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,SAU1B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAQ5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAQ5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAa5B,CAAC"}
|
package/formatters/text.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Text Formatters
|
|
4
|
-
*
|
|
5
|
-
* Formatters for case transformation and text manipulation.
|
|
6
|
-
*
|
|
7
|
-
* @see ADR-095 Message Templates with Formatters
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.titleFormatter = exports.lowerFormatter = exports.upperFormatter = exports.capFormatter = void 0;
|
|
11
|
-
/**
|
|
12
|
-
* Extract name from value (string or EntityInfo)
|
|
13
|
-
*/
|
|
14
|
-
function getName(value) {
|
|
15
|
-
return typeof value === 'string' ? value : value.name;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* "cap" formatter - capitalize first letter
|
|
19
|
-
*
|
|
20
|
-
* "sword" → "Sword"
|
|
21
|
-
*/
|
|
22
|
-
const capFormatter = (value, _context) => {
|
|
23
|
-
// Handle arrays
|
|
24
|
-
if (Array.isArray(value)) {
|
|
25
|
-
return value.map((v) => (0, exports.capFormatter)(v, _context)).join(', ');
|
|
26
|
-
}
|
|
27
|
-
const text = getName(value);
|
|
28
|
-
if (!text)
|
|
29
|
-
return '';
|
|
30
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
31
|
-
};
|
|
32
|
-
exports.capFormatter = capFormatter;
|
|
33
|
-
/**
|
|
34
|
-
* "upper" formatter - all uppercase
|
|
35
|
-
*
|
|
36
|
-
* "sword" → "SWORD"
|
|
37
|
-
*/
|
|
38
|
-
const upperFormatter = (value, _context) => {
|
|
39
|
-
// Handle arrays
|
|
40
|
-
if (Array.isArray(value)) {
|
|
41
|
-
return value.map((v) => (0, exports.upperFormatter)(v, _context)).join(', ');
|
|
42
|
-
}
|
|
43
|
-
const text = getName(value);
|
|
44
|
-
return text.toUpperCase();
|
|
45
|
-
};
|
|
46
|
-
exports.upperFormatter = upperFormatter;
|
|
47
|
-
/**
|
|
48
|
-
* "lower" formatter - all lowercase
|
|
49
|
-
*
|
|
50
|
-
* "SWORD" → "sword"
|
|
51
|
-
*/
|
|
52
|
-
const lowerFormatter = (value, _context) => {
|
|
53
|
-
// Handle arrays
|
|
54
|
-
if (Array.isArray(value)) {
|
|
55
|
-
return value.map((v) => (0, exports.lowerFormatter)(v, _context)).join(', ');
|
|
56
|
-
}
|
|
57
|
-
const text = getName(value);
|
|
58
|
-
return text.toLowerCase();
|
|
59
|
-
};
|
|
60
|
-
exports.lowerFormatter = lowerFormatter;
|
|
61
|
-
/**
|
|
62
|
-
* "title" formatter - title case (capitalize each word)
|
|
63
|
-
*
|
|
64
|
-
* "brass lantern" → "Brass Lantern"
|
|
65
|
-
*/
|
|
66
|
-
const titleFormatter = (value, _context) => {
|
|
67
|
-
// Handle arrays
|
|
68
|
-
if (Array.isArray(value)) {
|
|
69
|
-
return value.map((v) => (0, exports.titleFormatter)(v, _context)).join(', ');
|
|
70
|
-
}
|
|
71
|
-
const text = getName(value);
|
|
72
|
-
if (!text)
|
|
73
|
-
return '';
|
|
74
|
-
return text
|
|
75
|
-
.split(' ')
|
|
76
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
77
|
-
.join(' ');
|
|
78
|
-
};
|
|
79
|
-
exports.titleFormatter = titleFormatter;
|
|
80
|
-
//# sourceMappingURL=text.js.map
|
package/formatters/text.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/text.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH;;GAEG;AACH,SAAS,OAAO,CAAC,KAA0B;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACI,MAAM,YAAY,GAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IACzD,gBAAgB;IAChB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AAVW,QAAA,YAAY,gBAUvB;AAEF;;;;GAIG;AACI,MAAM,cAAc,GAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IAC3D,gBAAgB;IAChB,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AC;IAErB,OAAO,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SACzE,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC,CAAC;AAbW,QAAA,cAAc,kBAazB"}
|
package/formatters/types.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formatter Types
|
|
3
|
-
*
|
|
4
|
-
* Formatters transform placeholder values in message templates.
|
|
5
|
-
*
|
|
6
|
-
* Syntax: {formatter:formatter:...:placeholder} (the placeholder is the last segment)
|
|
7
|
-
* Example: {a:item} → "a sword"
|
|
8
|
-
* Example: {list:items} → "a sword, a key, and a coin"
|
|
9
|
-
*
|
|
10
|
-
* @see ADR-095 Message Templates with Formatters
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Context passed to formatters
|
|
14
|
-
*/
|
|
15
|
-
export interface FormatterContext {
|
|
16
|
-
/** Get entity by ID for nounType/article lookup */
|
|
17
|
-
getEntity?: (id: string) => EntityInfo | undefined;
|
|
18
|
-
/** Render-time settings the language layer reads (ADR-190). */
|
|
19
|
-
settings?: {
|
|
20
|
-
/** Serial (Oxford) comma in lists. Default true when absent. */
|
|
21
|
-
serialComma?: boolean;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Minimal entity info for formatting
|
|
26
|
-
*/
|
|
27
|
-
export interface EntityInfo {
|
|
28
|
-
name: string;
|
|
29
|
-
nounType?: 'common' | 'proper' | 'mass' | 'unique' | 'plural';
|
|
30
|
-
properName?: boolean;
|
|
31
|
-
article?: string;
|
|
32
|
-
grammaticalNumber?: 'singular' | 'plural';
|
|
33
|
-
/**
|
|
34
|
-
* Author-supplied plural form for irregular nouns (ADR-190). Populated from
|
|
35
|
-
* `IdentityTrait.plural` by `entityInfoFrom`. The `list`/`count` formatters use
|
|
36
|
-
* it when present, else fall back to the `pluralize()` heuristic.
|
|
37
|
-
*/
|
|
38
|
-
plural?: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Formatter function signature
|
|
42
|
-
*
|
|
43
|
-
* @param value - The value to format (string, array, or EntityInfo)
|
|
44
|
-
* @param context - Formatting context with entity lookup
|
|
45
|
-
* @returns Formatted string
|
|
46
|
-
*/
|
|
47
|
-
export type Formatter = (value: string | string[] | EntityInfo | EntityInfo[], context: FormatterContext) => string;
|
|
48
|
-
/**
|
|
49
|
-
* Formatter registry - maps formatter names to functions
|
|
50
|
-
*/
|
|
51
|
-
export type FormatterRegistry = Map<string, Formatter>;
|
|
52
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAC;IACnD,+DAA+D;IAC/D,QAAQ,CAAC,EAAE;QACT,gEAAgE;QAChE,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC1C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,UAAU,EAAE,EACpD,OAAO,EAAE,gBAAgB,KACtB,MAAM,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC"}
|
package/formatters/types.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Formatter Types
|
|
4
|
-
*
|
|
5
|
-
* Formatters transform placeholder values in message templates.
|
|
6
|
-
*
|
|
7
|
-
* Syntax: {formatter:formatter:...:placeholder} (the placeholder is the last segment)
|
|
8
|
-
* Example: {a:item} → "a sword"
|
|
9
|
-
* Example: {list:items} → "a sword, a key, and a coin"
|
|
10
|
-
*
|
|
11
|
-
* @see ADR-095 Message Templates with Formatters
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
//# sourceMappingURL=types.js.map
|
package/formatters/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG"}
|
package/formatters/verb.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Verb-Agreement Formatters
|
|
3
|
-
*
|
|
4
|
-
* Formatters that emit a verb form agreeing in number with the entity they
|
|
5
|
-
* are keyed to, so templates need not hardcode a singular verb. The verb is
|
|
6
|
-
* chosen from the entity's grammatical number, mirroring how the article
|
|
7
|
-
* formatters choose articles from `nounType`.
|
|
8
|
-
*
|
|
9
|
-
* Syntax keys the formatter to a placeholder, e.g. `{is:item}` resolves the
|
|
10
|
-
* `item` value and emits the agreeing copula:
|
|
11
|
-
*
|
|
12
|
-
* "{the:cap:item} {is:item} fixed in place."
|
|
13
|
-
* → "The white house is fixed in place." (singular)
|
|
14
|
-
* → "The pygmy goats are fixed in place." (plural)
|
|
15
|
-
*
|
|
16
|
-
* An entity is treated as plural when its `nounType` is `'plural'` or its
|
|
17
|
-
* `grammaticalNumber` is `'plural'`. A bare string (no EntityInfo metadata)
|
|
18
|
-
* or a missing value falls back to the singular form.
|
|
19
|
-
*
|
|
20
|
-
* @see ADR-095 Message Templates with Formatters
|
|
21
|
-
* @see ADR-089 Grammatical Number
|
|
22
|
-
*/
|
|
23
|
-
import type { Formatter } from './types.js';
|
|
24
|
-
/** "is" formatter — emits "is" (singular) or "are" (plural). */
|
|
25
|
-
export declare const isFormatter: Formatter;
|
|
26
|
-
/** "was" formatter — emits "was" (singular) or "were" (plural). */
|
|
27
|
-
export declare const wasFormatter: Formatter;
|
|
28
|
-
/** "has" formatter — emits "has" (singular) or "have" (plural). */
|
|
29
|
-
export declare const hasFormatter: Formatter;
|
|
30
|
-
//# sourceMappingURL=verb.d.ts.map
|
package/formatters/verb.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verb.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/verb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,YAAY,CAAC;AA+BxD,gEAAgE;AAChE,eAAO,MAAM,WAAW,EAAE,SAA+C,CAAC;AAE1E,mEAAmE;AACnE,eAAO,MAAM,YAAY,EAAE,SAAiD,CAAC;AAE7E,mEAAmE;AACnE,eAAO,MAAM,YAAY,EAAE,SAAiD,CAAC"}
|
package/formatters/verb.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Verb-Agreement Formatters
|
|
4
|
-
*
|
|
5
|
-
* Formatters that emit a verb form agreeing in number with the entity they
|
|
6
|
-
* are keyed to, so templates need not hardcode a singular verb. The verb is
|
|
7
|
-
* chosen from the entity's grammatical number, mirroring how the article
|
|
8
|
-
* formatters choose articles from `nounType`.
|
|
9
|
-
*
|
|
10
|
-
* Syntax keys the formatter to a placeholder, e.g. `{is:item}` resolves the
|
|
11
|
-
* `item` value and emits the agreeing copula:
|
|
12
|
-
*
|
|
13
|
-
* "{the:cap:item} {is:item} fixed in place."
|
|
14
|
-
* → "The white house is fixed in place." (singular)
|
|
15
|
-
* → "The pygmy goats are fixed in place." (plural)
|
|
16
|
-
*
|
|
17
|
-
* An entity is treated as plural when its `nounType` is `'plural'` or its
|
|
18
|
-
* `grammaticalNumber` is `'plural'`. A bare string (no EntityInfo metadata)
|
|
19
|
-
* or a missing value falls back to the singular form.
|
|
20
|
-
*
|
|
21
|
-
* @see ADR-095 Message Templates with Formatters
|
|
22
|
-
* @see ADR-089 Grammatical Number
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.hasFormatter = exports.wasFormatter = exports.isFormatter = void 0;
|
|
26
|
-
/**
|
|
27
|
-
* Decide whether a formatter value should take a plural verb.
|
|
28
|
-
*
|
|
29
|
-
* @param value - The placeholder value (EntityInfo, string, or array thereof).
|
|
30
|
-
* @returns true when the value is grammatically plural.
|
|
31
|
-
*/
|
|
32
|
-
function isPlural(value) {
|
|
33
|
-
// An array of values reads as plural unless it holds exactly one item.
|
|
34
|
-
if (Array.isArray(value)) {
|
|
35
|
-
return value.length !== 1;
|
|
36
|
-
}
|
|
37
|
-
if (typeof value === 'string') {
|
|
38
|
-
return false; // No metadata on a bare string — default to singular.
|
|
39
|
-
}
|
|
40
|
-
return value.nounType === 'plural' || value.grammaticalNumber === 'plural';
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Build a copula/auxiliary formatter that emits `singular` or `plural`
|
|
44
|
-
* depending on the value's grammatical number.
|
|
45
|
-
*
|
|
46
|
-
* @param singular - Verb form for singular subjects (e.g. "is").
|
|
47
|
-
* @param plural - Verb form for plural subjects (e.g. "are").
|
|
48
|
-
* @returns A Formatter that returns the agreeing form.
|
|
49
|
-
*/
|
|
50
|
-
function makeAgreementFormatter(singular, plural) {
|
|
51
|
-
return (value, _context) => (isPlural(value) ? plural : singular);
|
|
52
|
-
}
|
|
53
|
-
/** "is" formatter — emits "is" (singular) or "are" (plural). */
|
|
54
|
-
exports.isFormatter = makeAgreementFormatter('is', 'are');
|
|
55
|
-
/** "was" formatter — emits "was" (singular) or "were" (plural). */
|
|
56
|
-
exports.wasFormatter = makeAgreementFormatter('was', 'were');
|
|
57
|
-
/** "has" formatter — emits "has" (singular) or "have" (plural). */
|
|
58
|
-
exports.hasFormatter = makeAgreementFormatter('has', 'have');
|
|
59
|
-
//# sourceMappingURL=verb.js.map
|
package/formatters/verb.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verb.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/verb.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAIH;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,KAAoD;IACpE,uEAAuE;IACvE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,CAAC,sDAAsD;IACtE,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,iBAAiB,KAAK,QAAQ,CAAC;AAC7E,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAAC,QAAgB,EAAE,MAAc;IAC9D,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AACpE,CAAC;AAED,gEAAgE;AACnD,QAAA,WAAW,GAAc,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAE1E,mEAAmE;AACtD,QAAA,YAAY,GAAc,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAE7E,mEAAmE;AACtD,QAAA,YAAY,GAAc,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC"}
|