@e-mc/document 0.3.3 → 0.4.1
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/LICENSE +10 -10
- package/asset.d.ts +7 -7
- package/asset.js +11 -11
- package/index.d.ts +4 -4
- package/index.js +1291 -1291
- package/package.json +5 -5
- package/parse/dom.d.ts +8 -8
- package/parse/dom.js +256 -256
- package/parse/index.d.ts +8 -8
- package/parse/index.js +1452 -1452
- package/transform/index.d.ts +7 -7
- package/transform/index.js +321 -321
- package/util.js +203 -203
package/util.js
CHANGED
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = void 0;
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
|
|
7
|
-
function loadPlugins(name, plugins = []) {
|
|
8
|
-
if (Array.isArray(name)) {
|
|
9
|
-
plugins = name;
|
|
10
|
-
}
|
|
11
|
-
const result = [];
|
|
12
|
-
for (const plugin of plugins.map(item => (0, types_1.isString)(item) ? [item] : Array.isArray(item) && (0, types_1.isString)(item[0]) ? item : null)) {
|
|
13
|
-
if (plugin) {
|
|
14
|
-
const [pkg, options] = plugin;
|
|
15
|
-
result.push(require(pkg)(options));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
exports.loadPlugins = loadPlugins;
|
|
21
|
-
function replaceAll(source, valueOf, opening = '{{', closing = '}}') {
|
|
22
|
-
return source.split(opening).reduce((a, b, i) => {
|
|
23
|
-
if (i > 0) {
|
|
24
|
-
const j = b.indexOf(closing);
|
|
25
|
-
if (j !== -1) {
|
|
26
|
-
b = valueOf(b.substring(0, j)) + b.substring(j + closing.length);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return a + b;
|
|
30
|
-
}, '');
|
|
31
|
-
}
|
|
32
|
-
exports.replaceAll = replaceAll;
|
|
33
|
-
function concatString(values, newline) {
|
|
34
|
-
if ((0, types_1.isArray)(values)) {
|
|
35
|
-
newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n');
|
|
36
|
-
return values.reduce((a, b) => a + newline + b, '');
|
|
37
|
-
}
|
|
38
|
-
return typeof values === 'string' ? values : '';
|
|
39
|
-
}
|
|
40
|
-
exports.concatString = concatString;
|
|
41
|
-
function splitEnclosing(value, pattern, options, opening = '(', closing = ')') {
|
|
42
|
-
pattern || (pattern = opening);
|
|
43
|
-
let position = 0, index = -1, end = 0, char;
|
|
44
|
-
if (typeof pattern === 'string') {
|
|
45
|
-
if (pattern !== opening) {
|
|
46
|
-
char = pattern + opening;
|
|
47
|
-
end = pattern.length;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
char = opening;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (!pattern.global) {
|
|
54
|
-
pattern = new RegExp(pattern, pattern.flags + 'g');
|
|
55
|
-
}
|
|
56
|
-
const result = [];
|
|
57
|
-
const length = value.length;
|
|
58
|
-
const nextIndex = () => {
|
|
59
|
-
if (char) {
|
|
60
|
-
return value.indexOf(char, position);
|
|
61
|
-
}
|
|
62
|
-
pattern.lastIndex = position;
|
|
63
|
-
let match;
|
|
64
|
-
while (match = pattern.exec(value)) {
|
|
65
|
-
const i = match.index;
|
|
66
|
-
if (value[i + (end = match[0].length)] === opening) {
|
|
67
|
-
return i;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return -1;
|
|
71
|
-
};
|
|
72
|
-
complete: {
|
|
73
|
-
let j = 0, count = 0, countAll = 0, trim;
|
|
74
|
-
if (options !== undefined) {
|
|
75
|
-
switch (typeof options) {
|
|
76
|
-
case 'number':
|
|
77
|
-
countAll = options;
|
|
78
|
-
break;
|
|
79
|
-
case 'boolean':
|
|
80
|
-
trim = options;
|
|
81
|
-
break;
|
|
82
|
-
default: {
|
|
83
|
-
let start, startWith;
|
|
84
|
-
({ trim, start, startWith, count = 0 } = options);
|
|
85
|
-
if (startWith !== undefined) {
|
|
86
|
-
result.push(value.substring(0, position = startWith));
|
|
87
|
-
}
|
|
88
|
-
else if (start !== undefined) {
|
|
89
|
-
position = start;
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
while ((index = nextIndex()) !== -1) {
|
|
96
|
-
if (index !== position) {
|
|
97
|
-
result.push(value.substring(position, index));
|
|
98
|
-
}
|
|
99
|
-
found: {
|
|
100
|
-
for (let i = index + end + 1, open = 1, close = 0; i < length; ++i) {
|
|
101
|
-
switch (value[i]) {
|
|
102
|
-
case opening:
|
|
103
|
-
++open;
|
|
104
|
-
break;
|
|
105
|
-
case closing:
|
|
106
|
-
++close;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
if (open === close) {
|
|
110
|
-
if (trim) {
|
|
111
|
-
index += opening.length;
|
|
112
|
-
}
|
|
113
|
-
position = i + 1;
|
|
114
|
-
result.push(value.substring(index, position - (trim ? closing.length : 0)));
|
|
115
|
-
if (position === length) {
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
if (++j === countAll) {
|
|
119
|
-
break complete;
|
|
120
|
-
}
|
|
121
|
-
if (j === count) {
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
break found;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
position = index;
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (position === 0) {
|
|
133
|
-
return [value];
|
|
134
|
-
}
|
|
135
|
-
if (position < length) {
|
|
136
|
-
result.push(value.substring(position));
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
exports.splitEnclosing = splitEnclosing;
|
|
141
|
-
function appendSuffix(filename, value, separator = '-') {
|
|
142
|
-
const ext = path.extname(filename);
|
|
143
|
-
return ext && value ? filename.substring(0, filename.length - ext.length) + separator + value + ext : filename;
|
|
144
|
-
}
|
|
145
|
-
exports.appendSuffix = appendSuffix;
|
|
146
|
-
function getIndent(value, spaces = 4) {
|
|
147
|
-
const match = /^(\t|[ ]{2,}[^\s])/m.exec(value);
|
|
148
|
-
if (match) {
|
|
149
|
-
if (match[1] === '\t') {
|
|
150
|
-
return '\t';
|
|
151
|
-
}
|
|
152
|
-
spaces = match[1].length - 1;
|
|
153
|
-
}
|
|
154
|
-
return ' '.repeat(spaces);
|
|
155
|
-
}
|
|
156
|
-
exports.getIndent = getIndent;
|
|
157
|
-
function getNewline(value) {
|
|
158
|
-
const index = value.indexOf('\n');
|
|
159
|
-
return index > 0 && value[index - 1] === '\r' ? '\r\n' : '\n';
|
|
160
|
-
}
|
|
161
|
-
exports.getNewline = getNewline;
|
|
162
|
-
function getHashData(value) {
|
|
163
|
-
const match = /^(md5|sha1|sha224|sha384|sha256|sha512)(?:\[(\d+)\])?$/.exec(value.trim().toLowerCase());
|
|
164
|
-
return match ? [match[1], match[2] ? Math.max(4, +match[2]) : 0] : ['', 0];
|
|
165
|
-
}
|
|
166
|
-
exports.getHashData = getHashData;
|
|
167
|
-
function hasValue(target, ...values) {
|
|
168
|
-
if (target) {
|
|
169
|
-
if (typeof target === 'string') {
|
|
170
|
-
return values.includes(target);
|
|
171
|
-
}
|
|
172
|
-
if ((0, types_1.isArray)(target)) {
|
|
173
|
-
return target.some(item => values.includes(item));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
exports.hasValue = hasValue;
|
|
179
|
-
function getModuleName(err) {
|
|
180
|
-
const match = err instanceof Error && /Cannot find module '([^']+)'/.exec(err.message);
|
|
181
|
-
if (match) {
|
|
182
|
-
return match[1];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
exports.getModuleName = getModuleName;
|
|
186
|
-
function removeInternalProperties(value, retaining) {
|
|
187
|
-
if ((0, types_1.isObject)(value)) {
|
|
188
|
-
for (const prop in value) {
|
|
189
|
-
if (Object.prototype.hasOwnProperty.call(value, prop)) {
|
|
190
|
-
if (retaining) {
|
|
191
|
-
if (!retaining.includes(prop)) {
|
|
192
|
-
delete value[prop];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else if (prop.startsWith('__') && prop.endsWith('__')) {
|
|
196
|
-
delete value[prop];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return value;
|
|
202
|
-
}
|
|
203
|
-
exports.removeInternalProperties = removeInternalProperties;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
|
|
7
|
+
function loadPlugins(name, plugins = []) {
|
|
8
|
+
if (Array.isArray(name)) {
|
|
9
|
+
plugins = name;
|
|
10
|
+
}
|
|
11
|
+
const result = [];
|
|
12
|
+
for (const plugin of plugins.map(item => (0, types_1.isString)(item) ? [item] : Array.isArray(item) && (0, types_1.isString)(item[0]) ? item : null)) {
|
|
13
|
+
if (plugin) {
|
|
14
|
+
const [pkg, options] = plugin;
|
|
15
|
+
result.push(require(pkg)(options));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
exports.loadPlugins = loadPlugins;
|
|
21
|
+
function replaceAll(source, valueOf, opening = '{{', closing = '}}') {
|
|
22
|
+
return source.split(opening).reduce((a, b, i) => {
|
|
23
|
+
if (i > 0) {
|
|
24
|
+
const j = b.indexOf(closing);
|
|
25
|
+
if (j !== -1) {
|
|
26
|
+
b = valueOf(b.substring(0, j)) + b.substring(j + closing.length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return a + b;
|
|
30
|
+
}, '');
|
|
31
|
+
}
|
|
32
|
+
exports.replaceAll = replaceAll;
|
|
33
|
+
function concatString(values, newline) {
|
|
34
|
+
if ((0, types_1.isArray)(values)) {
|
|
35
|
+
newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n');
|
|
36
|
+
return values.reduce((a, b) => a + newline + b, '');
|
|
37
|
+
}
|
|
38
|
+
return typeof values === 'string' ? values : '';
|
|
39
|
+
}
|
|
40
|
+
exports.concatString = concatString;
|
|
41
|
+
function splitEnclosing(value, pattern, options, opening = '(', closing = ')') {
|
|
42
|
+
pattern || (pattern = opening);
|
|
43
|
+
let position = 0, index = -1, end = 0, char;
|
|
44
|
+
if (typeof pattern === 'string') {
|
|
45
|
+
if (pattern !== opening) {
|
|
46
|
+
char = pattern + opening;
|
|
47
|
+
end = pattern.length;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
char = opening;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (!pattern.global) {
|
|
54
|
+
pattern = new RegExp(pattern, pattern.flags + 'g');
|
|
55
|
+
}
|
|
56
|
+
const result = [];
|
|
57
|
+
const length = value.length;
|
|
58
|
+
const nextIndex = () => {
|
|
59
|
+
if (char) {
|
|
60
|
+
return value.indexOf(char, position);
|
|
61
|
+
}
|
|
62
|
+
pattern.lastIndex = position;
|
|
63
|
+
let match;
|
|
64
|
+
while (match = pattern.exec(value)) {
|
|
65
|
+
const i = match.index;
|
|
66
|
+
if (value[i + (end = match[0].length)] === opening) {
|
|
67
|
+
return i;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return -1;
|
|
71
|
+
};
|
|
72
|
+
complete: {
|
|
73
|
+
let j = 0, count = 0, countAll = 0, trim;
|
|
74
|
+
if (options !== undefined) {
|
|
75
|
+
switch (typeof options) {
|
|
76
|
+
case 'number':
|
|
77
|
+
countAll = options;
|
|
78
|
+
break;
|
|
79
|
+
case 'boolean':
|
|
80
|
+
trim = options;
|
|
81
|
+
break;
|
|
82
|
+
default: {
|
|
83
|
+
let start, startWith;
|
|
84
|
+
({ trim, start, startWith, count = 0 } = options);
|
|
85
|
+
if (startWith !== undefined) {
|
|
86
|
+
result.push(value.substring(0, position = startWith));
|
|
87
|
+
}
|
|
88
|
+
else if (start !== undefined) {
|
|
89
|
+
position = start;
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
while ((index = nextIndex()) !== -1) {
|
|
96
|
+
if (index !== position) {
|
|
97
|
+
result.push(value.substring(position, index));
|
|
98
|
+
}
|
|
99
|
+
found: {
|
|
100
|
+
for (let i = index + end + 1, open = 1, close = 0; i < length; ++i) {
|
|
101
|
+
switch (value[i]) {
|
|
102
|
+
case opening:
|
|
103
|
+
++open;
|
|
104
|
+
break;
|
|
105
|
+
case closing:
|
|
106
|
+
++close;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (open === close) {
|
|
110
|
+
if (trim) {
|
|
111
|
+
index += opening.length;
|
|
112
|
+
}
|
|
113
|
+
position = i + 1;
|
|
114
|
+
result.push(value.substring(index, position - (trim ? closing.length : 0)));
|
|
115
|
+
if (position === length) {
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
if (++j === countAll) {
|
|
119
|
+
break complete;
|
|
120
|
+
}
|
|
121
|
+
if (j === count) {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
break found;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
position = index;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (position === 0) {
|
|
133
|
+
return [value];
|
|
134
|
+
}
|
|
135
|
+
if (position < length) {
|
|
136
|
+
result.push(value.substring(position));
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
exports.splitEnclosing = splitEnclosing;
|
|
141
|
+
function appendSuffix(filename, value, separator = '-') {
|
|
142
|
+
const ext = path.extname(filename);
|
|
143
|
+
return ext && value ? filename.substring(0, filename.length - ext.length) + separator + value + ext : filename;
|
|
144
|
+
}
|
|
145
|
+
exports.appendSuffix = appendSuffix;
|
|
146
|
+
function getIndent(value, spaces = 4) {
|
|
147
|
+
const match = /^(\t|[ ]{2,}[^\s])/m.exec(value);
|
|
148
|
+
if (match) {
|
|
149
|
+
if (match[1] === '\t') {
|
|
150
|
+
return '\t';
|
|
151
|
+
}
|
|
152
|
+
spaces = match[1].length - 1;
|
|
153
|
+
}
|
|
154
|
+
return ' '.repeat(spaces);
|
|
155
|
+
}
|
|
156
|
+
exports.getIndent = getIndent;
|
|
157
|
+
function getNewline(value) {
|
|
158
|
+
const index = value.indexOf('\n');
|
|
159
|
+
return index > 0 && value[index - 1] === '\r' ? '\r\n' : '\n';
|
|
160
|
+
}
|
|
161
|
+
exports.getNewline = getNewline;
|
|
162
|
+
function getHashData(value) {
|
|
163
|
+
const match = /^(md5|sha1|sha224|sha384|sha256|sha512)(?:\[(\d+)\])?$/.exec(value.trim().toLowerCase());
|
|
164
|
+
return match ? [match[1], match[2] ? Math.max(4, +match[2]) : 0] : ['', 0];
|
|
165
|
+
}
|
|
166
|
+
exports.getHashData = getHashData;
|
|
167
|
+
function hasValue(target, ...values) {
|
|
168
|
+
if (target) {
|
|
169
|
+
if (typeof target === 'string') {
|
|
170
|
+
return values.includes(target);
|
|
171
|
+
}
|
|
172
|
+
if ((0, types_1.isArray)(target)) {
|
|
173
|
+
return target.some(item => values.includes(item));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
exports.hasValue = hasValue;
|
|
179
|
+
function getModuleName(err) {
|
|
180
|
+
const match = err instanceof Error && /Cannot find module '([^']+)'/.exec(err.message);
|
|
181
|
+
if (match) {
|
|
182
|
+
return match[1];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.getModuleName = getModuleName;
|
|
186
|
+
function removeInternalProperties(value, retaining) {
|
|
187
|
+
if ((0, types_1.isObject)(value)) {
|
|
188
|
+
for (const prop in value) {
|
|
189
|
+
if (Object.prototype.hasOwnProperty.call(value, prop)) {
|
|
190
|
+
if (retaining) {
|
|
191
|
+
if (!retaining.includes(prop)) {
|
|
192
|
+
delete value[prop];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (prop.startsWith('__') && prop.endsWith('__')) {
|
|
196
|
+
delete value[prop];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
exports.removeInternalProperties = removeInternalProperties;
|