@sharpee/lang-en-us 2.0.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 +7 -0
- package/actions/about.js.map +1 -1
- package/actions/help.d.ts +3 -3
- package/actions/help.d.ts.map +1 -1
- package/actions/help.js +8 -6
- package/actions/help.js.map +1 -1
- package/actions/index.d.ts +5 -3
- package/actions/index.d.ts.map +1 -1
- package/actions/reading.d.ts.map +1 -1
- package/actions/reading.js +3 -1
- package/actions/reading.js.map +1 -1
- package/actions/taking.d.ts +1 -0
- package/actions/taking.d.ts.map +1 -1
- package/actions/taking.js +2 -0
- package/actions/taking.js.map +1 -1
- package/language-provider.d.ts +6 -0
- package/language-provider.d.ts.map +1 -1
- package/language-provider.js +13 -0
- package/language-provider.js.map +1 -1
- package/package.json +3 -3
- 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/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/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formatter System
|
|
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" (articles + grouping, ADR-190)
|
|
9
|
-
* Example: {the-list:items} → "the sword, the key, and the coin"
|
|
10
|
-
*
|
|
11
|
-
* @see ADR-095 Message Templates with Formatters
|
|
12
|
-
*/
|
|
13
|
-
export type { Formatter, FormatterRegistry, FormatterContext, EntityInfo, } from './types.js';
|
|
14
|
-
export { createFormatterRegistry, parsePlaceholder, applyFormatters, formatMessage, } from './registry.js';
|
|
15
|
-
export { aFormatter, theFormatter, someFormatter, yourFormatter } from './article.js';
|
|
16
|
-
export { listFormatter, orListFormatter, commaListFormatter, countFormatter } from './list.js';
|
|
17
|
-
export { capFormatter, upperFormatter, lowerFormatter, titleFormatter } from './text.js';
|
|
18
|
-
export { isFormatter, wasFormatter, hasFormatter } from './verb.js';
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,aAAa,GACd,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/formatters/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Formatter System
|
|
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" (articles + grouping, ADR-190)
|
|
10
|
-
* Example: {the-list:items} → "the sword, the key, and the coin"
|
|
11
|
-
*
|
|
12
|
-
* @see ADR-095 Message Templates with Formatters
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.hasFormatter = exports.wasFormatter = exports.isFormatter = exports.titleFormatter = exports.lowerFormatter = exports.upperFormatter = exports.capFormatter = exports.countFormatter = exports.commaListFormatter = exports.orListFormatter = exports.listFormatter = exports.yourFormatter = exports.someFormatter = exports.theFormatter = exports.aFormatter = exports.formatMessage = exports.applyFormatters = exports.parsePlaceholder = exports.createFormatterRegistry = void 0;
|
|
16
|
-
// Registry and utilities
|
|
17
|
-
var registry_js_1 = require("./registry.js");
|
|
18
|
-
Object.defineProperty(exports, "createFormatterRegistry", { enumerable: true, get: function () { return registry_js_1.createFormatterRegistry; } });
|
|
19
|
-
Object.defineProperty(exports, "parsePlaceholder", { enumerable: true, get: function () { return registry_js_1.parsePlaceholder; } });
|
|
20
|
-
Object.defineProperty(exports, "applyFormatters", { enumerable: true, get: function () { return registry_js_1.applyFormatters; } });
|
|
21
|
-
Object.defineProperty(exports, "formatMessage", { enumerable: true, get: function () { return registry_js_1.formatMessage; } });
|
|
22
|
-
// Individual formatters (for direct use or testing)
|
|
23
|
-
var article_js_1 = require("./article.js");
|
|
24
|
-
Object.defineProperty(exports, "aFormatter", { enumerable: true, get: function () { return article_js_1.aFormatter; } });
|
|
25
|
-
Object.defineProperty(exports, "theFormatter", { enumerable: true, get: function () { return article_js_1.theFormatter; } });
|
|
26
|
-
Object.defineProperty(exports, "someFormatter", { enumerable: true, get: function () { return article_js_1.someFormatter; } });
|
|
27
|
-
Object.defineProperty(exports, "yourFormatter", { enumerable: true, get: function () { return article_js_1.yourFormatter; } });
|
|
28
|
-
var list_js_1 = require("./list.js");
|
|
29
|
-
Object.defineProperty(exports, "listFormatter", { enumerable: true, get: function () { return list_js_1.listFormatter; } });
|
|
30
|
-
Object.defineProperty(exports, "orListFormatter", { enumerable: true, get: function () { return list_js_1.orListFormatter; } });
|
|
31
|
-
Object.defineProperty(exports, "commaListFormatter", { enumerable: true, get: function () { return list_js_1.commaListFormatter; } });
|
|
32
|
-
Object.defineProperty(exports, "countFormatter", { enumerable: true, get: function () { return list_js_1.countFormatter; } });
|
|
33
|
-
var text_js_1 = require("./text.js");
|
|
34
|
-
Object.defineProperty(exports, "capFormatter", { enumerable: true, get: function () { return text_js_1.capFormatter; } });
|
|
35
|
-
Object.defineProperty(exports, "upperFormatter", { enumerable: true, get: function () { return text_js_1.upperFormatter; } });
|
|
36
|
-
Object.defineProperty(exports, "lowerFormatter", { enumerable: true, get: function () { return text_js_1.lowerFormatter; } });
|
|
37
|
-
Object.defineProperty(exports, "titleFormatter", { enumerable: true, get: function () { return text_js_1.titleFormatter; } });
|
|
38
|
-
var verb_js_1 = require("./verb.js");
|
|
39
|
-
Object.defineProperty(exports, "isFormatter", { enumerable: true, get: function () { return verb_js_1.isFormatter; } });
|
|
40
|
-
Object.defineProperty(exports, "wasFormatter", { enumerable: true, get: function () { return verb_js_1.wasFormatter; } });
|
|
41
|
-
Object.defineProperty(exports, "hasFormatter", { enumerable: true, get: function () { return verb_js_1.hasFormatter; } });
|
|
42
|
-
//# sourceMappingURL=index.js.map
|
package/formatters/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAUH,yBAAyB;AACzB,6CAKuB;AAJrB,sHAAA,uBAAuB,OAAA;AACvB,+GAAA,gBAAgB,OAAA;AAChB,8GAAA,eAAe,OAAA;AACf,4GAAA,aAAa,OAAA;AAGf,oDAAoD;AACpD,2CAAsF;AAA7E,wGAAA,UAAU,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,2GAAA,aAAa,OAAA;AAAE,2GAAA,aAAa,OAAA;AAC/D,qCAA+F;AAAtF,wGAAA,aAAa,OAAA;AAAE,0GAAA,eAAe,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,yGAAA,cAAc,OAAA;AAC3E,qCAAyF;AAAhF,uGAAA,YAAY,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,yGAAA,cAAc,OAAA;AACrE,qCAAoE;AAA3D,sGAAA,WAAW,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA"}
|
package/formatters/list.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* List Formatters
|
|
3
|
-
*
|
|
4
|
-
* Formatters for joining arrays of items into prose.
|
|
5
|
-
*
|
|
6
|
-
* @see ADR-095 Message Templates with Formatters
|
|
7
|
-
*/
|
|
8
|
-
import type { Formatter } from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* "list" formatter — natural-language list of entities (ADR-190).
|
|
11
|
-
*
|
|
12
|
-
* Each `EntityInfo` element gets its indefinite article ("a goat", "an apple",
|
|
13
|
-
* "some sand"); identical common nouns group and pluralize ("two goats"); the
|
|
14
|
-
* parts join with commas and "and", with the serial (Oxford) comma controlled by
|
|
15
|
-
* the story's `serialComma` setting (default on). Bare strings render as-is.
|
|
16
|
-
* Empty → "nothing".
|
|
17
|
-
*
|
|
18
|
-
* {list:items} → "a goat, two rabbits, and a parrot"
|
|
19
|
-
*/
|
|
20
|
-
export declare const listFormatter: Formatter;
|
|
21
|
-
/**
|
|
22
|
-
* "the-list" formatter — definite variant: "the goat, the rabbit, and the parrot".
|
|
23
|
-
* No count-grouping (definite items are individuated); proper names take no article.
|
|
24
|
-
*/
|
|
25
|
-
export declare const theListFormatter: Formatter;
|
|
26
|
-
/**
|
|
27
|
-
* "names" formatter — plain name join (the pre-ADR-190 `list` behavior) for
|
|
28
|
-
* non-entity string lists: no articles, no grouping. Empty → "".
|
|
29
|
-
*/
|
|
30
|
-
export declare const namesFormatter: Formatter;
|
|
31
|
-
/**
|
|
32
|
-
* "or-list" formatter - join with commas and "or"
|
|
33
|
-
*
|
|
34
|
-
* Single: "north"
|
|
35
|
-
* Two: "north or south"
|
|
36
|
-
* Three+: "north, south, or east"
|
|
37
|
-
*/
|
|
38
|
-
export declare const orListFormatter: Formatter;
|
|
39
|
-
/**
|
|
40
|
-
* "comma-list" formatter - join with commas only (no conjunction)
|
|
41
|
-
*
|
|
42
|
-
* "a sword, a key, a coin"
|
|
43
|
-
*/
|
|
44
|
-
export declare const commaListFormatter: Formatter;
|
|
45
|
-
/**
|
|
46
|
-
* "count" formatter - a count word plus the (pluralized) noun.
|
|
47
|
-
*
|
|
48
|
-
* Spells out 1–10, numeric for 11+ (ADR-190). Uses the entity's `plural` override
|
|
49
|
-
* (from `IdentityTrait.plural`) when present, else the `pluralize()` heuristic.
|
|
50
|
-
*
|
|
51
|
-
* Example: {count:items} with 3 swords → "three swords"
|
|
52
|
-
* Example: {count:items} with 1 sword → "one sword"
|
|
53
|
-
* Example: {count:items} with 0 → "nothing"
|
|
54
|
-
*/
|
|
55
|
-
export declare const countFormatter: Formatter;
|
|
56
|
-
//# sourceMappingURL=list.d.ts.map
|
package/formatters/list.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/list.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAgC,MAAM,YAAY,CAAC;AAwF1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAE,SAC6C,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,SACwC,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAI5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,SAU7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAGhC,CAAC;AAaF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC"}
|
package/formatters/list.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* List Formatters
|
|
4
|
-
*
|
|
5
|
-
* Formatters for joining arrays of items into prose.
|
|
6
|
-
*
|
|
7
|
-
* @see ADR-095 Message Templates with Formatters
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.countFormatter = exports.commaListFormatter = exports.orListFormatter = exports.namesFormatter = exports.theListFormatter = exports.listFormatter = void 0;
|
|
11
|
-
const article_js_1 = require("./article.js");
|
|
12
|
-
const pluralize_js_1 = require("../pluralize.js");
|
|
13
|
-
const number_words_js_1 = require("../number-words.js");
|
|
14
|
-
/**
|
|
15
|
-
* Extract name from value (string or EntityInfo)
|
|
16
|
-
*/
|
|
17
|
-
function getName(value) {
|
|
18
|
-
return typeof value === 'string' ? value : value.name;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Ensure value is an array
|
|
22
|
-
*/
|
|
23
|
-
function ensureArray(value) {
|
|
24
|
-
if (Array.isArray(value)) {
|
|
25
|
-
return value.map((v) => getName(v));
|
|
26
|
-
}
|
|
27
|
-
return [getName(value)];
|
|
28
|
-
}
|
|
29
|
-
/** True for a bare string element (no entity metadata to article/group). */
|
|
30
|
-
function isBare(v) {
|
|
31
|
-
return typeof v === 'string';
|
|
32
|
-
}
|
|
33
|
-
/** A common noun groups by name; proper/mass/unique/plural do not. */
|
|
34
|
-
function isCommonNoun(ei) {
|
|
35
|
-
const nounType = ei.nounType ?? (ei.properName ? 'proper' : 'common');
|
|
36
|
-
return nounType === 'common';
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Render each element into a phrase. In indefinite mode, identical common-noun
|
|
40
|
-
* entities group and pluralize ("two goats"); bare strings render as-is (no
|
|
41
|
-
* article), preserving plain name lists. In definite mode, every entity becomes
|
|
42
|
-
* "the X" with no grouping.
|
|
43
|
-
*/
|
|
44
|
-
function renderListParts(value, mode, context) {
|
|
45
|
-
const arr = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
46
|
-
if (mode === 'definite') {
|
|
47
|
-
return arr.map((v) => (isBare(v) ? v : (0, article_js_1.theFormatter)(v, context)));
|
|
48
|
-
}
|
|
49
|
-
const parts = [];
|
|
50
|
-
const groupIndex = new Map();
|
|
51
|
-
for (const v of arr) {
|
|
52
|
-
if (!isBare(v) && isCommonNoun(v)) {
|
|
53
|
-
const ei = v;
|
|
54
|
-
const existing = groupIndex.get(ei.name);
|
|
55
|
-
if (existing !== undefined) {
|
|
56
|
-
parts[existing].count++;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
groupIndex.set(ei.name, parts.length);
|
|
60
|
-
parts.push({ value: v, ei, count: 1 });
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
parts.push({ value: v, count: 1 });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return parts.map((p) => {
|
|
67
|
-
if (p.count > 1 && p.ei) {
|
|
68
|
-
const plural = p.ei.plural ?? (0, pluralize_js_1.pluralize)(p.ei.name);
|
|
69
|
-
return `${(0, number_words_js_1.countWord)(p.count)} ${plural}`;
|
|
70
|
-
}
|
|
71
|
-
return isBare(p.value) ? p.value : (0, article_js_1.aFormatter)(p.value, context);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/** Join rendered parts with commas and a conjunction; serial comma per setting. */
|
|
75
|
-
function joinList(parts, conjunction, context) {
|
|
76
|
-
if (parts.length === 0)
|
|
77
|
-
return 'nothing';
|
|
78
|
-
if (parts.length === 1)
|
|
79
|
-
return parts[0];
|
|
80
|
-
if (parts.length === 2)
|
|
81
|
-
return `${parts[0]} ${conjunction} ${parts[1]}`;
|
|
82
|
-
const serial = context?.settings?.serialComma ?? true;
|
|
83
|
-
const head = parts.slice(0, -1).join(', ');
|
|
84
|
-
const last = parts[parts.length - 1];
|
|
85
|
-
return serial ? `${head}, ${conjunction} ${last}` : `${head} ${conjunction} ${last}`;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* "list" formatter — natural-language list of entities (ADR-190).
|
|
89
|
-
*
|
|
90
|
-
* Each `EntityInfo` element gets its indefinite article ("a goat", "an apple",
|
|
91
|
-
* "some sand"); identical common nouns group and pluralize ("two goats"); the
|
|
92
|
-
* parts join with commas and "and", with the serial (Oxford) comma controlled by
|
|
93
|
-
* the story's `serialComma` setting (default on). Bare strings render as-is.
|
|
94
|
-
* Empty → "nothing".
|
|
95
|
-
*
|
|
96
|
-
* {list:items} → "a goat, two rabbits, and a parrot"
|
|
97
|
-
*/
|
|
98
|
-
const listFormatter = (value, context) => joinList(renderListParts(value, 'indefinite', context), 'and', context);
|
|
99
|
-
exports.listFormatter = listFormatter;
|
|
100
|
-
/**
|
|
101
|
-
* "the-list" formatter — definite variant: "the goat, the rabbit, and the parrot".
|
|
102
|
-
* No count-grouping (definite items are individuated); proper names take no article.
|
|
103
|
-
*/
|
|
104
|
-
const theListFormatter = (value, context) => joinList(renderListParts(value, 'definite', context), 'and', context);
|
|
105
|
-
exports.theListFormatter = theListFormatter;
|
|
106
|
-
/**
|
|
107
|
-
* "names" formatter — plain name join (the pre-ADR-190 `list` behavior) for
|
|
108
|
-
* non-entity string lists: no articles, no grouping. Empty → "".
|
|
109
|
-
*/
|
|
110
|
-
const namesFormatter = (value, context) => {
|
|
111
|
-
const items = ensureArray(value);
|
|
112
|
-
if (items.length === 0)
|
|
113
|
-
return '';
|
|
114
|
-
return joinList(items, 'and', context);
|
|
115
|
-
};
|
|
116
|
-
exports.namesFormatter = namesFormatter;
|
|
117
|
-
/**
|
|
118
|
-
* "or-list" formatter - join with commas and "or"
|
|
119
|
-
*
|
|
120
|
-
* Single: "north"
|
|
121
|
-
* Two: "north or south"
|
|
122
|
-
* Three+: "north, south, or east"
|
|
123
|
-
*/
|
|
124
|
-
const orListFormatter = (value, _context) => {
|
|
125
|
-
const items = ensureArray(value);
|
|
126
|
-
if (items.length === 0)
|
|
127
|
-
return '';
|
|
128
|
-
if (items.length === 1)
|
|
129
|
-
return items[0];
|
|
130
|
-
if (items.length === 2)
|
|
131
|
-
return `${items[0]} or ${items[1]}`;
|
|
132
|
-
const allButLast = items.slice(0, -1);
|
|
133
|
-
const last = items[items.length - 1];
|
|
134
|
-
return `${allButLast.join(', ')}, or ${last}`;
|
|
135
|
-
};
|
|
136
|
-
exports.orListFormatter = orListFormatter;
|
|
137
|
-
/**
|
|
138
|
-
* "comma-list" formatter - join with commas only (no conjunction)
|
|
139
|
-
*
|
|
140
|
-
* "a sword, a key, a coin"
|
|
141
|
-
*/
|
|
142
|
-
const commaListFormatter = (value, _context) => {
|
|
143
|
-
const items = ensureArray(value);
|
|
144
|
-
return items.join(', ');
|
|
145
|
-
};
|
|
146
|
-
exports.commaListFormatter = commaListFormatter;
|
|
147
|
-
/** First element's noun name and optional plural override (EntityInfo or string). */
|
|
148
|
-
function firstNoun(value) {
|
|
149
|
-
const arr = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
150
|
-
const first = arr[0];
|
|
151
|
-
if (first && typeof first === 'object' && 'name' in first) {
|
|
152
|
-
const ei = first;
|
|
153
|
-
return { name: ei.name, plural: ei.plural };
|
|
154
|
-
}
|
|
155
|
-
return { name: first == null ? '' : String(first) };
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* "count" formatter - a count word plus the (pluralized) noun.
|
|
159
|
-
*
|
|
160
|
-
* Spells out 1–10, numeric for 11+ (ADR-190). Uses the entity's `plural` override
|
|
161
|
-
* (from `IdentityTrait.plural`) when present, else the `pluralize()` heuristic.
|
|
162
|
-
*
|
|
163
|
-
* Example: {count:items} with 3 swords → "three swords"
|
|
164
|
-
* Example: {count:items} with 1 sword → "one sword"
|
|
165
|
-
* Example: {count:items} with 0 → "nothing"
|
|
166
|
-
*/
|
|
167
|
-
const countFormatter = (value, _context) => {
|
|
168
|
-
const count = Array.isArray(value) ? value.length : value == null ? 0 : 1;
|
|
169
|
-
if (count === 0)
|
|
170
|
-
return 'nothing';
|
|
171
|
-
const { name, plural } = firstNoun(value);
|
|
172
|
-
if (count === 1)
|
|
173
|
-
return `one ${name}`;
|
|
174
|
-
const pluralNoun = plural ?? (0, pluralize_js_1.pluralize)(name);
|
|
175
|
-
return `${(0, number_words_js_1.countWord)(count)} ${pluralNoun}`;
|
|
176
|
-
};
|
|
177
|
-
exports.countFormatter = countFormatter;
|
|
178
|
-
//# sourceMappingURL=list.js.map
|
package/formatters/list.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/list.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,6CAAwD;AACxD,kDAA4C;AAC5C,wDAA+C;AAE/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,KAAK,CAAC;QAAE,OAAO,OAAO,IAAI,EAAE,CAAC;IAEtC,MAAM,UAAU,GAAG,MAAM,IAAI,IAAA,wBAAS,EAAC,IAAI,CAAC,CAAC;IAC7C,OAAO,GAAG,IAAA,2BAAS,EAAC,KAAK,CAAC,IAAI,UAAU,EAAE,CAAC;AAC7C,CAAC,CAAC;AATW,QAAA,cAAc,kBASzB"}
|
package/formatters/registry.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formatter Registry
|
|
3
|
-
*
|
|
4
|
-
* Central registry of all formatters, with support for story extensions.
|
|
5
|
-
*
|
|
6
|
-
* @see ADR-095 Message Templates with Formatters
|
|
7
|
-
*/
|
|
8
|
-
import type { FormatterRegistry, FormatterContext, EntityInfo } from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* Create the default formatter registry with all built-in formatters
|
|
11
|
-
*/
|
|
12
|
-
export declare function createFormatterRegistry(): FormatterRegistry;
|
|
13
|
-
/**
|
|
14
|
-
* Parse a placeholder with formatters
|
|
15
|
-
*
|
|
16
|
-
* Syntax: {formatter:formatter:...:placeholder}
|
|
17
|
-
*
|
|
18
|
-
* @returns Object with formatters array and final placeholder name
|
|
19
|
-
*/
|
|
20
|
-
export declare function parsePlaceholder(placeholder: string): {
|
|
21
|
-
formatters: string[];
|
|
22
|
-
name: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Apply formatters to a value in sequence
|
|
26
|
-
*
|
|
27
|
-
* @param value - The value to format
|
|
28
|
-
* @param formatters - Array of formatter names to apply in order
|
|
29
|
-
* @param registry - The formatter registry
|
|
30
|
-
* @param context - Formatting context
|
|
31
|
-
* @returns Formatted string
|
|
32
|
-
*/
|
|
33
|
-
export declare function applyFormatters(value: string | number | boolean | string[] | EntityInfo | EntityInfo[], formatters: string[], registry: FormatterRegistry, context: FormatterContext): string;
|
|
34
|
-
/**
|
|
35
|
-
* Format a message template with placeholders
|
|
36
|
-
*
|
|
37
|
-
* Supports both:
|
|
38
|
-
* - Simple placeholders: {item}
|
|
39
|
-
* - Formatted placeholders: {a:item}, {list:items}, {the:cap:item}
|
|
40
|
-
* (the placeholder is the last colon segment)
|
|
41
|
-
*
|
|
42
|
-
* @param template - Message template with {placeholder} syntax
|
|
43
|
-
* @param params - Values for placeholders
|
|
44
|
-
* @param registry - Formatter registry
|
|
45
|
-
* @param context - Formatting context
|
|
46
|
-
* @returns Formatted message
|
|
47
|
-
*/
|
|
48
|
-
export declare function formatMessage(template: string, params: Record<string, string | number | boolean | string[] | EntityInfo | EntityInfo[]>, registry: FormatterRegistry, context?: FormatterContext): string;
|
|
49
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAa,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7F;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,iBAAiB,CA8B3D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG;IACrD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd,CAYA;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,UAAU,EAAE,EACvE,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,MAAM,CAuBR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,UAAU,EAAE,CAAC,EACxF,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CA8BR"}
|
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":"","sources":["../../../../../../../repos/sharpee_v1/packages/lang-en-us/src/formatters/registry.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAWH,0DA8BC;AASD,4CAeC;AAWD,0CA4BC;AAgBD,sCAmCC;AAxJD,6CAAsF;AACtF,uCAAiI;AACjI,uCAAyF;AACzF,uCAAoE;AAEpE;;GAEG;AACH,SAAgB,uBAAuB;IACrC,MAAM,QAAQ,GAAsB,IAAI,GAAG,EAAE,CAAC;IAE9C,qBAAqB;IACrB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,uBAAU,CAAC,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,uBAAU,CAAC,CAAC,CAAC,QAAQ;IACxC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,yBAAY,CAAC,CAAC;IAClC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,0BAAa,CAAC,CAAC;IACpC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,0BAAa,CAAC,CAAC;IAEpC,kBAAkB;IAClB,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,uBAAa,CAAC,CAAC;IACpC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,0BAAgB,CAAC,CAAC;IAC3C,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,wBAAc,CAAC,CAAC;IACtC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,yBAAe,CAAC,CAAC;I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,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,mDAAmD;YACnD,kDAAkD;YAClD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,mBAAmB;QACnB,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/D,CAAC;QAED,yCAAyC;QACzC,IAAI,KAAK,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,OAA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