config 4.1.0 → 4.2.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.
Files changed (3) hide show
  1. package/lib/config.js +0 -413
  2. package/package.json +4 -6
  3. package/parser.js +12 -23
package/lib/config.js CHANGED
@@ -231,46 +231,6 @@ util.setModuleDefaults = function (moduleName, defaultProperties) {
231
231
  return util.attachProtoDeep(Util.getPath(t, path));
232
232
  };
233
233
 
234
- /**
235
- * <p>Make a configuration property hidden so it doesn't appear when enumerating
236
- * elements of the object.</p>
237
- *
238
- * <p>
239
- * The property still exists and can be read from and written to, but it won't
240
- * show up in for ... in loops, Object.keys(), or JSON.stringify() type methods.
241
- * </p>
242
- *
243
- * <p>
244
- * If the property already exists, it will be made hidden. Otherwise it will
245
- * be created as a hidden property with the specified value.
246
- * </p>
247
- *
248
- * <p><i>
249
- * This method was built for hiding configuration values, but it can be applied
250
- * to <u>any</u> javascript object.
251
- * </i></p>
252
- *
253
- * <p>Example:</p>
254
- * <pre>
255
- * const CONFIG = require('config');
256
- * ...
257
- *
258
- * // Hide the Amazon S3 credentials
259
- * CONFIG.util.makeHidden(CONFIG.amazonS3, 'access_id');
260
- * CONFIG.util.makeHidden(CONFIG.amazonS3, 'secret_key');
261
- * </pre>
262
- *
263
- * @deprecated use Util.makeHidden
264
- * @method makeHidden
265
- * @param object {Object} - The object to make a hidden property into.
266
- * @param property {string} - The name of the property to make hidden.
267
- * @param value {*} - (optional) Set the property value to this (otherwise leave alone)
268
- * @return object {Object} - The original object is returned - for chaining.
269
- */
270
- util.makeHidden = function(object, property, value) {
271
- return Util.makeHidden(object, property, value);
272
- }
273
-
274
234
  /**
275
235
  * <p>Make a javascript object property immutable (assuring it cannot be changed
276
236
  * from the current value).</p>
@@ -421,26 +381,6 @@ util.getConfigSources = function() {
421
381
  return FIRST_LOAD.getSources();
422
382
  };
423
383
 
424
- /**
425
- * Looks into an options object for a specific attribute
426
- *
427
- * <p>
428
- * This method looks into the options object, and if an attribute is defined, returns it,
429
- * and if not, returns the default value
430
- * </p>
431
- *
432
- * @method getOption
433
- * @deprecated use Util.getOption
434
- * @param options {Object | undefined} the options object
435
- * @param optionName {string} the attribute name to look for
436
- * @param defaultValue { any } the default in case the options object is empty, or the attribute does not exist.
437
- * @return options[optionName] if defined, defaultValue if not.
438
- */
439
- util.getOption = function(options, optionName, defaultValue) {
440
- return Util.getOption(options, optionName, defaultValue);
441
- };
442
-
443
-
444
384
  /**
445
385
  * Load the individual file configurations.
446
386
  *
@@ -557,98 +497,6 @@ function _init(load) {
557
497
  load.scan(additional);
558
498
  }
559
499
 
560
- /**
561
- * Return a list of fullFilenames who exists in allowedFiles
562
- * Ordered according to allowedFiles argument specifications
563
- *
564
- * @protected
565
- * @deprecated use Util.locateMatchingFiles
566
- * @method locateMatchingFiles
567
- * @param configDirs {string} the config dir, or multiple dirs separated by a column (:)
568
- * @param allowedFiles {Object} an object. keys and supported filenames
569
- * and values are the position in the resolution order
570
- * @returns {string[]} fullFilenames - path + filename
571
- */
572
- util.locateMatchingFiles = function(configDirs, allowedFiles) {
573
- return Util.locateMatchingFiles(configDirs, allowedFiles);
574
- };
575
-
576
- /**
577
- * @deprecated use Util.resolveDeferredConfigs
578
- * @param config
579
- */
580
- // Using basic recursion pattern, find all the deferred values and resolve them.
581
- util.resolveDeferredConfigs = function (config) {
582
- return Util.resolveDeferredConfigs(config);
583
- };
584
-
585
- /**
586
- * Parse and return the specified configuration file.
587
- *
588
- * If the file exists in the application config directory, it will
589
- * parse and return it as a JavaScript object.
590
- *
591
- * The file extension determines the parser to use.
592
- *
593
- * .js = File to run that has a module.exports containing the config object
594
- * .coffee = File to run that has a module.exports with coffee-script containing the config object
595
- * .iced = File to run that has a module.exports with iced-coffee-script containing the config object
596
- * All other supported file types (yaml, toml, json, cson, hjson, json5, properties, xml)
597
- * are parsed with util.parseString.
598
- *
599
- * If the file doesn't exist, a null will be returned. If the file can't be
600
- * parsed, an exception will be thrown.
601
- *
602
- * This method performs synchronous file operations, and should not be called
603
- * after synchronous module loading.
604
- *
605
- * @protected
606
- * @deprecated
607
- * @method parseFile
608
- * @param fullFilename {string} The full file path and name
609
- * @param options { object | undefined } parsing options. Current supported option: skipConfigSources: true|false
610
- * @return configObject {object|null} The configuration object parsed from the file
611
- */
612
- util.parseFile = function(fullFilename, options = {}) {
613
- let loadOpts = {...FIRST_LOAD.options}; //TODO: Support full LoadOptions?
614
- let loadInfo = new Load(loadOpts);
615
-
616
- loadInfo.loadFile(fullFilename);
617
-
618
- return loadInfo.config;
619
- }
620
-
621
- /**
622
- * Parse and return the specified string with the specified format.
623
- *
624
- * The format determines the parser to use.
625
- *
626
- * json = File is parsed using JSON.parse()
627
- * yaml (or yml) = Parsed with a YAML parser
628
- * toml = Parsed with a TOML parser
629
- * cson = Parsed with a CSON parser
630
- * hjson = Parsed with a HJSON parser
631
- * json5 = Parsed with a JSON5 parser
632
- * properties = Parsed with the 'properties' node package
633
- * xml = Parsed with a XML parser
634
- *
635
- * If the file doesn't exist, a null will be returned. If the file can't be
636
- * parsed, an exception will be thrown.
637
- *
638
- * This method performs synchronous file operations, and should not be called
639
- * after synchronous module loading.
640
- *
641
- * @protected
642
- * @deprecated
643
- * @method parseString
644
- * @param content {string} The full content
645
- * @param format {string} The format to be parsed
646
- * @return {configObject} The configuration object parsed from the string
647
- */
648
- util.parseString = function (content, format) {
649
- return FIRST_LOAD.parseString(content, format);
650
- };
651
-
652
500
  /**
653
501
  * Attach the Config class prototype to all config objects recursively.
654
502
  *
@@ -698,267 +546,6 @@ util.attachProtoDeep = function(toObject, depth) {
698
546
  return toObject;
699
547
  };
700
548
 
701
- /**
702
- * Return a deep copy of the specified object.
703
- *
704
- * This returns a new object with all elements copied from the specified
705
- * object. Deep copies are made of objects and arrays so you can do anything
706
- * with the returned object without affecting the input object.
707
- *
708
- * @protected
709
- * @deprecated please see Util.cloneDeep
710
- * @method cloneDeep
711
- * @param parent {Object} The original object to copy from
712
- * @param [depth=20] {number} Maximum depth (default 20)
713
- * @return {Object} A new object with the elements copied from the copyFrom object
714
- */
715
- util.cloneDeep = function cloneDeep(parent, depth, circular, prototype) {
716
- return Util.cloneDeep(parent, depth, circular, prototype);
717
- };
718
-
719
- /**
720
- * Set objects given a path as a string list
721
- *
722
- * @protected
723
- * @deprecated see Util.setPath()
724
- *
725
- * @method setPath
726
- * @param object {Object} - Object to set the property on
727
- * @param path {array[string]} - Array path to the property
728
- * @param value {*} - value to set, ignoring null
729
- */
730
- util.setPath = function (object, path, value) {
731
- Util.setPath(object, path, value);
732
- };
733
-
734
- /**
735
- * Create a new object patterned after substitutionMap, where:
736
- * 1. Terminal string values in substitutionMap are used as keys
737
- * 2. To look up values in a key-value store, variables
738
- * 3. And parent keys are created as necessary to retain the structure of substitutionMap.
739
- *
740
- * @protected
741
- * @deprecated
742
- *
743
- * @method substituteDeep
744
- * @param substitutionMap {Object} - an object whose terminal (non-subobject) values are strings
745
- * @param variables {object[string:value]} - usually process.env, a flat object used to transform
746
- * terminal values in a copy of substitutionMap.
747
- * @returns {Object} - deep copy of substitutionMap with only those paths whose terminal values
748
- * corresponded to a key in `variables`
749
- */
750
- util.substituteDeep = function (substitutionMap, variables) {
751
- return FIRST_LOAD.substituteDeep(substitutionMap, variables);
752
- };
753
-
754
- /**
755
- * Map environment variables into the configuration if a mapping file,
756
- * `custom-environment-variables.EXT` exists.
757
- *
758
- * @protected
759
- * @deprecated
760
- * @method getCustomEnvVars
761
- * @param configDir {string} - the passed configuration directory
762
- * @param extNames {Array[string]} - acceptable configuration file extension names.
763
- * @returns {Object} - mapped environment variables or {} if there are none
764
- */
765
- util.getCustomEnvVars = function (configDir, extNames) {
766
- let options = {...FIRST_LOAD.options, configDir};
767
- let load = new Load(options);
768
-
769
- load.loadCustomEnvVars(extNames);
770
-
771
- return load.config;
772
- };
773
-
774
- /**
775
- * Return true if two objects have equal contents.
776
- *
777
- * @protected
778
- * @deprecated see Util.equalsDeep()
779
- *
780
- * @method equalsDeep
781
- * @param object1 {Object} The object to compare from
782
- * @param object2 {Object} The object to compare with
783
- * @param depth {integer} An optional depth to prevent recursion. Default: 20.
784
- * @return {boolean} True if both objects have equivalent contents
785
- */
786
- util.equalsDeep = function(object1, object2, depth) {
787
- return Util.equalsDeep(object1, object2, depth);
788
- };
789
-
790
- /**
791
- * Returns an object containing all elements that differ between two objects.
792
- * <p>
793
- * This method was designed to be used to create the runtime.json file
794
- * contents, but can be used to get the diffs between any two Javascript objects.
795
- * </p>
796
- * <p>
797
- * It works best when object2 originated by deep copying object1, then
798
- * changes were made to object2, and you want an object that would give you
799
- * the changes made to object1 which resulted in object2.
800
- * </p>
801
- *
802
- * <b>This function has a number of issues and you may be better off with lodash</b>
803
- *
804
- * @protected
805
- * @deprecated please investigate lodash or similar tools for object traversal
806
- * @method diffDeep
807
- * @param object1 {Object} The base object to compare to
808
- * @param object2 {Object} The object to compare with
809
- * @param depth {integer} An optional depth to prevent recursion. Default: 20.
810
- * @return {Object} A differential object, which if extended onto object1 would
811
- * result in object2.
812
- */
813
- util.diffDeep = function(object1, object2, depth) {
814
- // Recursion detection
815
- const diff = {};
816
- depth = (depth === null ? DEFAULT_CLONE_DEPTH : depth);
817
- if (depth < 0) {
818
- return {};
819
- }
820
-
821
- // Process each element from object2, adding any element that's different
822
- // from object 1.
823
- for (const parm in object2) {
824
- const value1 = object1[parm];
825
- const value2 = object2[parm];
826
- if (value1 && value2 && Util.isObject(value2)) {
827
- if (!(Util.equalsDeep(value1, value2))) {
828
- diff[parm] = util.diffDeep(value1, value2, depth - 1);
829
- }
830
- }
831
- else if (Array.isArray(value1) && Array.isArray(value2)) {
832
- if(!Util.equalsDeep(value1, value2)) {
833
- diff[parm] = value2;
834
- }
835
- }
836
- else if (value1 !== value2){
837
- diff[parm] = value2;
838
- }
839
- }
840
-
841
- // Return the diff object
842
- return diff;
843
- };
844
-
845
- /**
846
- * Extend an object, and any object it contains.
847
- *
848
- * This does not replace deep objects, but dives into them
849
- * replacing individual elements instead.
850
- *
851
- * @protected
852
- * @deprecated please use Util.extendDeep()
853
- * @method extendDeep
854
- * @param mergeInto {Object} The object to merge into
855
- * @param mergeFrom... {object[]} - Any number of objects to merge from
856
- * @param depth {integer} An optional depth to prevent recursion. Default: 20.
857
- * @return {Object} The altered mergeInto object is returned
858
- */
859
- util.extendDeep = function(mergeInto, ...vargs) {
860
- return Util.extendDeep(mergeInto, ...vargs);
861
- };
862
-
863
- /**
864
- * Is the specified argument a regular javascript object?
865
- *
866
- * The argument is an object if it's a JS object, but not an array.
867
- *
868
- * @protected
869
- * @deprecated please use Util.isObject()
870
- * @method isObject
871
- * @param obj {*} An argument of any type.
872
- * @return {boolean} TRUE if the arg is an object, FALSE if not
873
- */
874
- util.isObject = function(obj) {
875
- return Util.isObject(obj);
876
- };
877
-
878
- /**
879
- * Is the specified argument a javascript promise?
880
- *
881
- * @protected
882
- * @deprecated please use Util.isPromise()
883
- * @method isPromise
884
- * @param obj {*} An argument of any type.
885
- * @returns {boolean}
886
- */
887
- util.isPromise = function(obj) {
888
- return Util.isPromise(obj);
889
- };
890
-
891
- /**
892
- * <p>Initialize a parameter from the command line or process environment</p>
893
- *
894
- * <p>
895
- * This method looks for the parameter from the command line in the format
896
- * --PARAMETER=VALUE, then from the process environment, then from the
897
- * default specified as an argument.
898
- * </p>
899
- *
900
- * @method initParam
901
- * @deprecated
902
- * @param paramName {String} Name of the parameter
903
- * @param [defaultValue] {*} Default value of the parameter
904
- * @return {*} The found value, or default value
905
- */
906
- util.initParam = function (paramName, defaultValue) {
907
- return FIRST_LOAD.initParam(paramName, defaultValue);
908
- }
909
-
910
- /**
911
- * <p>Get Command Line Arguments</p>
912
- *
913
- * <p>
914
- * This method allows you to retrieve the value of the specified command line argument.
915
- * </p>
916
- *
917
- * <p>
918
- * The argument is case sensitive, and must be of the form '--ARG_NAME=value'
919
- * </p>
920
- *
921
- * @method getCmdLineArg
922
- * @deprecated
923
- * @param searchFor {String} The argument name to search for
924
- * @return {*} false if the argument was not found, the argument value if found
925
- */
926
- util.getCmdLineArg = function (searchFor) {
927
- return FIRST_LOAD.getCmdLineArg(searchFor);
928
- }
929
-
930
-
931
- /**
932
- * <p>Get a Config Environment Variable Value</p>
933
- *
934
- * <p>
935
- * This method returns the value of the specified config environment variable,
936
- * including any defaults or overrides.
937
- * </p>
938
- *
939
- * @method getEnv
940
- * @deprecated
941
- * @param varName {String} The environment variable name
942
- * @return {String} The value of the environment variable
943
- */
944
- util.getEnv = function (varName) {
945
- return FIRST_LOAD.getEnv(varName);
946
- }
947
-
948
-
949
-
950
- /**
951
- * Returns a string of flags for regular expression `re`.
952
- *
953
- * @protected
954
- * @deprecated This is an internal implementation detail
955
- * @param {RegExp} re Regular expression
956
- * @returns {string} Flags
957
- */
958
- util.getRegExpFlags = function (re) {
959
- return Util.getRegExpFlags(re);
960
- };
961
-
962
549
  /**
963
550
  * Returns a new deep copy of the current config object, or any part of the config if provided.
964
551
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "config",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "main": "./lib/config.js",
5
5
  "description": "Configuration control for production node deployments",
6
6
  "author": "Loren West <open_source@lorenwest.com>",
@@ -30,7 +30,6 @@
30
30
  "coffeescript": "2.2.4",
31
31
  "cson": "^3.0.1",
32
32
  "hjson": "^1.2.0",
33
- "js-yaml": "^3.2.2",
34
33
  "properties": "~1.2.1",
35
34
  "request": "^2.88.2",
36
35
  "semver": "5.3.0",
@@ -38,8 +37,8 @@
38
37
  "ts-node": "^3.3.0",
39
38
  "typescript": "^2.4.2",
40
39
  "underscore": "^1.8.3",
41
- "vows": ">=0.8.1",
42
- "x2js": "^2.0.1"
40
+ "x2js": "^2.0.1",
41
+ "yaml": "^2.8.2"
43
42
  },
44
43
  "repository": {
45
44
  "type": "git",
@@ -57,7 +56,6 @@
57
56
  "reporter": "lcov"
58
57
  },
59
58
  "scripts": {
60
- "test": "c8 vows test/*.js --spec",
61
- "vows": "c8 vows"
59
+ "test": "NODE_OPTIONS='--no-experimental-strip-types' c8 node --test"
62
60
  }
63
61
  }
package/parser.js CHANGED
@@ -11,7 +11,7 @@ const JSON5Module = require('json5');
11
11
  const JSON5 = JSON5Module.default || JSON5Module;
12
12
 
13
13
  var Yaml = null,
14
- VisionmediaYaml = null,
14
+ JSYaml = null,
15
15
  Coffee = null,
16
16
  Iced = null,
17
17
  CSON = null,
@@ -135,34 +135,23 @@ Parser.icedParser = function(filename, content) {
135
135
  };
136
136
 
137
137
  Parser.yamlParser = function(filename, content) {
138
- if (!Yaml && !VisionmediaYaml) {
138
+ if (!Yaml && !JSYaml) {
139
139
  // Lazy loading
140
140
  try {
141
- // Try to load the better js-yaml module
142
- Yaml = require(JS_YAML_DEP);
143
- }
144
- catch (e) {
141
+ Yaml = require(YAML_DEP);
142
+ } catch (e) {
145
143
  try {
146
- // If it doesn't exist, load the fallback visionmedia yaml module.
147
- VisionmediaYaml = require(YAML_DEP);
148
- }
149
- catch (e) { }
144
+ JSYaml = require(JS_YAML_DEP);
145
+ } catch (e) {}
150
146
  }
151
147
  }
148
+
152
149
  if (Yaml) {
153
- return Yaml.load(content);
154
- }
155
- else if (VisionmediaYaml) {
156
- // The yaml library doesn't like strings that have newlines but don't
157
- // end in a newline: https://github.com/visionmedia/js-yaml/issues/issue/13
158
- content += '\n';
159
- if (typeof VisionmediaYaml.eval === 'function') {
160
- return VisionmediaYaml.eval(Parser.stripYamlComments(content));
161
- }
162
- return VisionmediaYaml.parse(Parser.stripYamlComments(content));
163
- }
164
- else {
165
- console.error('No YAML parser loaded. Suggest adding js-yaml dependency to your package.json file.')
150
+ return Yaml.parse(content);
151
+ } else if (JSYaml) {
152
+ return JSYaml.load(content);
153
+ } else {
154
+ console.error('No YAML parser loaded. Suggest adding yaml dependency to your package.json file.')
166
155
  }
167
156
  };
168
157