@tachybase/plugin-wechat-official-account 0.23.8

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.
@@ -0,0 +1,395 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ "use strict";
4
+ var bom, defaults, defineProperty, events, isEmpty, processItem, processors, sax, setImmediate,
5
+ bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
6
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
7
+ hasProp = {}.hasOwnProperty;
8
+
9
+ sax = require('sax');
10
+
11
+ events = require('events');
12
+
13
+ bom = require('./bom');
14
+
15
+ processors = require('./processors');
16
+
17
+ setImmediate = require('timers').setImmediate;
18
+
19
+ defaults = require('./defaults').defaults;
20
+
21
+ isEmpty = function(thing) {
22
+ return typeof thing === "object" && (thing != null) && Object.keys(thing).length === 0;
23
+ };
24
+
25
+ processItem = function(processors, item, key) {
26
+ var i, len, process;
27
+ for (i = 0, len = processors.length; i < len; i++) {
28
+ process = processors[i];
29
+ item = process(item, key);
30
+ }
31
+ return item;
32
+ };
33
+
34
+ defineProperty = function(obj, key, value) {
35
+ var descriptor;
36
+ descriptor = Object.create(null);
37
+ descriptor.value = value;
38
+ descriptor.writable = true;
39
+ descriptor.enumerable = true;
40
+ descriptor.configurable = true;
41
+ return Object.defineProperty(obj, key, descriptor);
42
+ };
43
+
44
+ exports.Parser = (function(superClass) {
45
+ extend(Parser, superClass);
46
+
47
+ function Parser(opts) {
48
+ this.parseStringPromise = bind(this.parseStringPromise, this);
49
+ this.parseString = bind(this.parseString, this);
50
+ this.reset = bind(this.reset, this);
51
+ this.assignOrPush = bind(this.assignOrPush, this);
52
+ this.processAsync = bind(this.processAsync, this);
53
+ var key, ref, value;
54
+ if (!(this instanceof exports.Parser)) {
55
+ return new exports.Parser(opts);
56
+ }
57
+ this.options = {};
58
+ ref = defaults["0.2"];
59
+ for (key in ref) {
60
+ if (!hasProp.call(ref, key)) continue;
61
+ value = ref[key];
62
+ this.options[key] = value;
63
+ }
64
+ for (key in opts) {
65
+ if (!hasProp.call(opts, key)) continue;
66
+ value = opts[key];
67
+ this.options[key] = value;
68
+ }
69
+ if (this.options.xmlns) {
70
+ this.options.xmlnskey = this.options.attrkey + "ns";
71
+ }
72
+ if (this.options.normalizeTags) {
73
+ if (!this.options.tagNameProcessors) {
74
+ this.options.tagNameProcessors = [];
75
+ }
76
+ this.options.tagNameProcessors.unshift(processors.normalize);
77
+ }
78
+ this.reset();
79
+ }
80
+
81
+ Parser.prototype.processAsync = function() {
82
+ var chunk, err;
83
+ try {
84
+ if (this.remaining.length <= this.options.chunkSize) {
85
+ chunk = this.remaining;
86
+ this.remaining = '';
87
+ this.saxParser = this.saxParser.write(chunk);
88
+ return this.saxParser.close();
89
+ } else {
90
+ chunk = this.remaining.substr(0, this.options.chunkSize);
91
+ this.remaining = this.remaining.substr(this.options.chunkSize, this.remaining.length);
92
+ this.saxParser = this.saxParser.write(chunk);
93
+ return setImmediate(this.processAsync);
94
+ }
95
+ } catch (error1) {
96
+ err = error1;
97
+ if (!this.saxParser.errThrown) {
98
+ this.saxParser.errThrown = true;
99
+ return this.emit(err);
100
+ }
101
+ }
102
+ };
103
+
104
+ Parser.prototype.assignOrPush = function(obj, key, newValue) {
105
+ if (!(key in obj)) {
106
+ if (!this.options.explicitArray) {
107
+ return defineProperty(obj, key, newValue);
108
+ } else {
109
+ return defineProperty(obj, key, [newValue]);
110
+ }
111
+ } else {
112
+ if (!(obj[key] instanceof Array)) {
113
+ defineProperty(obj, key, [obj[key]]);
114
+ }
115
+ return obj[key].push(newValue);
116
+ }
117
+ };
118
+
119
+ Parser.prototype.reset = function() {
120
+ var attrkey, charkey, ontext, stack;
121
+ this.removeAllListeners();
122
+ this.saxParser = sax.parser(this.options.strict, {
123
+ trim: false,
124
+ normalize: false,
125
+ xmlns: this.options.xmlns
126
+ });
127
+ this.saxParser.errThrown = false;
128
+ this.saxParser.onerror = (function(_this) {
129
+ return function(error) {
130
+ _this.saxParser.resume();
131
+ if (!_this.saxParser.errThrown) {
132
+ _this.saxParser.errThrown = true;
133
+ return _this.emit("error", error);
134
+ }
135
+ };
136
+ })(this);
137
+ this.saxParser.onend = (function(_this) {
138
+ return function() {
139
+ if (!_this.saxParser.ended) {
140
+ _this.saxParser.ended = true;
141
+ return _this.emit("end", _this.resultObject);
142
+ }
143
+ };
144
+ })(this);
145
+ this.saxParser.ended = false;
146
+ this.EXPLICIT_CHARKEY = this.options.explicitCharkey;
147
+ this.resultObject = null;
148
+ stack = [];
149
+ attrkey = this.options.attrkey;
150
+ charkey = this.options.charkey;
151
+ this.saxParser.onopentag = (function(_this) {
152
+ return function(node) {
153
+ var key, newValue, obj, processedKey, ref;
154
+ obj = {};
155
+ obj[charkey] = "";
156
+ if (!_this.options.ignoreAttrs) {
157
+ ref = node.attributes;
158
+ for (key in ref) {
159
+ if (!hasProp.call(ref, key)) continue;
160
+ if (!(attrkey in obj) && !_this.options.mergeAttrs) {
161
+ obj[attrkey] = {};
162
+ }
163
+ newValue = _this.options.attrValueProcessors ? processItem(_this.options.attrValueProcessors, node.attributes[key], key) : node.attributes[key];
164
+ processedKey = _this.options.attrNameProcessors ? processItem(_this.options.attrNameProcessors, key) : key;
165
+ if (_this.options.mergeAttrs) {
166
+ _this.assignOrPush(obj, processedKey, newValue);
167
+ } else {
168
+ defineProperty(obj[attrkey], processedKey, newValue);
169
+ }
170
+ }
171
+ }
172
+ obj["#name"] = _this.options.tagNameProcessors ? processItem(_this.options.tagNameProcessors, node.name) : node.name;
173
+ if (_this.options.xmlns) {
174
+ obj[_this.options.xmlnskey] = {
175
+ uri: node.uri,
176
+ local: node.local
177
+ };
178
+ }
179
+ return stack.push(obj);
180
+ };
181
+ })(this);
182
+ this.saxParser.onclosetag = (function(_this) {
183
+ return function() {
184
+ var cdata, emptyStr, key, node, nodeName, obj, objClone, old, s, xpath;
185
+ obj = stack.pop();
186
+ nodeName = obj["#name"];
187
+ if (!_this.options.explicitChildren || !_this.options.preserveChildrenOrder) {
188
+ delete obj["#name"];
189
+ }
190
+ if (obj.cdata === true) {
191
+ cdata = obj.cdata;
192
+ delete obj.cdata;
193
+ }
194
+ s = stack[stack.length - 1];
195
+ if (obj[charkey].match(/^\s*$/) && !cdata) {
196
+ emptyStr = obj[charkey];
197
+ delete obj[charkey];
198
+ } else {
199
+ if (_this.options.trim) {
200
+ obj[charkey] = obj[charkey].trim();
201
+ }
202
+ if (_this.options.normalize) {
203
+ obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim();
204
+ }
205
+ obj[charkey] = _this.options.valueProcessors ? processItem(_this.options.valueProcessors, obj[charkey], nodeName) : obj[charkey];
206
+ if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) {
207
+ obj = obj[charkey];
208
+ }
209
+ }
210
+ if (isEmpty(obj)) {
211
+ if (typeof _this.options.emptyTag === 'function') {
212
+ obj = _this.options.emptyTag();
213
+ } else {
214
+ obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr;
215
+ }
216
+ }
217
+ if (_this.options.validator != null) {
218
+ xpath = "/" + ((function() {
219
+ var i, len, results;
220
+ results = [];
221
+ for (i = 0, len = stack.length; i < len; i++) {
222
+ node = stack[i];
223
+ results.push(node["#name"]);
224
+ }
225
+ return results;
226
+ })()).concat(nodeName).join("/");
227
+ (function() {
228
+ var err;
229
+ try {
230
+ return obj = _this.options.validator(xpath, s && s[nodeName], obj);
231
+ } catch (error1) {
232
+ err = error1;
233
+ return _this.emit("error", err);
234
+ }
235
+ })();
236
+ }
237
+ if (_this.options.explicitChildren && !_this.options.mergeAttrs && typeof obj === 'object') {
238
+ if (!_this.options.preserveChildrenOrder) {
239
+ node = {};
240
+ if (_this.options.attrkey in obj) {
241
+ node[_this.options.attrkey] = obj[_this.options.attrkey];
242
+ delete obj[_this.options.attrkey];
243
+ }
244
+ if (!_this.options.charsAsChildren && _this.options.charkey in obj) {
245
+ node[_this.options.charkey] = obj[_this.options.charkey];
246
+ delete obj[_this.options.charkey];
247
+ }
248
+ if (Object.getOwnPropertyNames(obj).length > 0) {
249
+ node[_this.options.childkey] = obj;
250
+ }
251
+ obj = node;
252
+ } else if (s) {
253
+ s[_this.options.childkey] = s[_this.options.childkey] || [];
254
+ objClone = {};
255
+ for (key in obj) {
256
+ if (!hasProp.call(obj, key)) continue;
257
+ defineProperty(objClone, key, obj[key]);
258
+ }
259
+ s[_this.options.childkey].push(objClone);
260
+ delete obj["#name"];
261
+ if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) {
262
+ obj = obj[charkey];
263
+ }
264
+ }
265
+ }
266
+ if (stack.length > 0) {
267
+ return _this.assignOrPush(s, nodeName, obj);
268
+ } else {
269
+ if (_this.options.explicitRoot) {
270
+ old = obj;
271
+ obj = {};
272
+ defineProperty(obj, nodeName, old);
273
+ }
274
+ _this.resultObject = obj;
275
+ _this.saxParser.ended = true;
276
+ return _this.emit("end", _this.resultObject);
277
+ }
278
+ };
279
+ })(this);
280
+ ontext = (function(_this) {
281
+ return function(text) {
282
+ var charChild, s;
283
+ s = stack[stack.length - 1];
284
+ if (s) {
285
+ s[charkey] += text;
286
+ if (_this.options.explicitChildren && _this.options.preserveChildrenOrder && _this.options.charsAsChildren && (_this.options.includeWhiteChars || text.replace(/\\n/g, '').trim() !== '')) {
287
+ s[_this.options.childkey] = s[_this.options.childkey] || [];
288
+ charChild = {
289
+ '#name': '__text__'
290
+ };
291
+ charChild[charkey] = text;
292
+ if (_this.options.normalize) {
293
+ charChild[charkey] = charChild[charkey].replace(/\s{2,}/g, " ").trim();
294
+ }
295
+ s[_this.options.childkey].push(charChild);
296
+ }
297
+ return s;
298
+ }
299
+ };
300
+ })(this);
301
+ this.saxParser.ontext = ontext;
302
+ return this.saxParser.oncdata = (function(_this) {
303
+ return function(text) {
304
+ var s;
305
+ s = ontext(text);
306
+ if (s) {
307
+ return s.cdata = true;
308
+ }
309
+ };
310
+ })(this);
311
+ };
312
+
313
+ Parser.prototype.parseString = function(str, cb) {
314
+ var err;
315
+ if ((cb != null) && typeof cb === "function") {
316
+ this.on("end", function(result) {
317
+ this.reset();
318
+ return cb(null, result);
319
+ });
320
+ this.on("error", function(err) {
321
+ this.reset();
322
+ return cb(err);
323
+ });
324
+ }
325
+ try {
326
+ str = str.toString();
327
+ if (str.trim() === '') {
328
+ this.emit("end", null);
329
+ return true;
330
+ }
331
+ str = bom.stripBOM(str);
332
+ if (this.options.async) {
333
+ this.remaining = str;
334
+ setImmediate(this.processAsync);
335
+ return this.saxParser;
336
+ }
337
+ return this.saxParser.write(str).close();
338
+ } catch (error1) {
339
+ err = error1;
340
+ if (!(this.saxParser.errThrown || this.saxParser.ended)) {
341
+ this.emit('error', err);
342
+ return this.saxParser.errThrown = true;
343
+ } else if (this.saxParser.ended) {
344
+ throw err;
345
+ }
346
+ }
347
+ };
348
+
349
+ Parser.prototype.parseStringPromise = function(str) {
350
+ return new Promise((function(_this) {
351
+ return function(resolve, reject) {
352
+ return _this.parseString(str, function(err, value) {
353
+ if (err) {
354
+ return reject(err);
355
+ } else {
356
+ return resolve(value);
357
+ }
358
+ });
359
+ };
360
+ })(this));
361
+ };
362
+
363
+ return Parser;
364
+
365
+ })(events);
366
+
367
+ exports.parseString = function(str, a, b) {
368
+ var cb, options, parser;
369
+ if (b != null) {
370
+ if (typeof b === 'function') {
371
+ cb = b;
372
+ }
373
+ if (typeof a === 'object') {
374
+ options = a;
375
+ }
376
+ } else {
377
+ if (typeof a === 'function') {
378
+ cb = a;
379
+ }
380
+ options = {};
381
+ }
382
+ parser = new exports.Parser(options);
383
+ return parser.parseString(str, cb);
384
+ };
385
+
386
+ exports.parseStringPromise = function(str, a) {
387
+ var options, parser;
388
+ if (typeof a === 'object') {
389
+ options = a;
390
+ }
391
+ parser = new exports.Parser(options);
392
+ return parser.parseStringPromise(str);
393
+ };
394
+
395
+ }).call(this);
@@ -0,0 +1,34 @@
1
+ // Generated by CoffeeScript 1.12.7
2
+ (function() {
3
+ "use strict";
4
+ var prefixMatch;
5
+
6
+ prefixMatch = new RegExp(/(?!xmlns)^.*:/);
7
+
8
+ exports.normalize = function(str) {
9
+ return str.toLowerCase();
10
+ };
11
+
12
+ exports.firstCharLowerCase = function(str) {
13
+ return str.charAt(0).toLowerCase() + str.slice(1);
14
+ };
15
+
16
+ exports.stripPrefix = function(str) {
17
+ return str.replace(prefixMatch, '');
18
+ };
19
+
20
+ exports.parseNumbers = function(str) {
21
+ if (!isNaN(str)) {
22
+ str = str % 1 === 0 ? parseInt(str, 10) : parseFloat(str);
23
+ }
24
+ return str;
25
+ };
26
+
27
+ exports.parseBooleans = function(str) {
28
+ if (/^(?:true|false)$/i.test(str)) {
29
+ str = str.toLowerCase() === 'true';
30
+ }
31
+ return str;
32
+ };
33
+
34
+ }).call(this);