/
intl-messageformat-parser.js
59 lines (47 loc) · 1.26 KB
/
intl-messageformat-parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import defaultParserInterface from '../utils/defaultParserInterface';
import pkg from 'intl-messageformat-parser/package.json';
const ID = 'intl-messageformat-parser';
const TYPES = {}
export const parserSettingsConfiguration = {
fields: [
'captureLocation',
'normalizeHashtagInPlural',
],
};
const defaultOptions = {
captureLocation: true,
normalizeHashtagInPlural: true,
}
export default {
...defaultParserInterface,
id: ID,
displayName: ID,
version: pkg.version,
homepage: pkg.homepage || 'https://github.com/formatjs/formatjs/tree/master/packages/intl-messageformat-parser',
locationProps: new Set(['location']),
loadParser(callback) {
require(['intl-messageformat-parser'], all => {
Object.keys(all.TYPE).forEach(k => {
TYPES[k] = all.TYPE[k]
})
callback(all)
});
},
parse(parser, code, opts) {
return parser.parse(code, opts);
},
_getSettingsConfiguration() {
return parserSettingsConfiguration;
},
getDefaultOptions() {
return defaultOptions;
},
getNodeName(node) {
return node.type != null && TYPES[node.type]
},
nodeToRange({ location }) {
if (location && location.start && location.end) {
return [location.start.offset, location.end.offset];
}
},
};