Permalink
Browse files

Drop `getOption` and `getSetting` utility functions.

  • Loading branch information...
dervus committed Feb 9, 2013
1 parent 7e1cafc commit 23ab38b6315e25be0d0f4170eb6371eabdfde87d
Showing with 30 additions and 44 deletions.
  1. +0 −23 lib/js-yaml/common.js
  2. +6 −4 lib/js-yaml/dumper.js
  3. +8 −6 lib/js-yaml/loader.js
  4. +16 −11 lib/js-yaml/type.js
View
@@ -1,9 +1,6 @@
'use strict';
-var YAMLException = require('./exception');
-
-
var NIL = {};
@@ -28,24 +25,6 @@ function toArray(sequence) {
}
-function getSetting(settings, name) {
- if (!isNothing(settings) && !isNothing(settings[name])) {
- return settings[name];
- } else {
- throw new YAMLException('Required "' + name + '" setting is missed.');
- }
-}
-
-
-function getOption(options, name, alternative) {
- if (!isNothing(options) && !isNothing(options[name])) {
- return options[name];
- } else {
- return alternative;
- }
-}
-
-
function extend(target, source) {
var index, length, key, sourceKeys;
@@ -77,7 +56,5 @@ module.exports.NIL = NIL;
module.exports.isNothing = isNothing;
module.exports.isObject = isObject;
module.exports.toArray = toArray;
-module.exports.getSetting = getSetting;
-module.exports.getOption = getOption;
module.exports.repeat = repeat;
module.exports.extend = extend;
View
@@ -126,10 +126,12 @@ function encodeHex(character) {
function dump(input, options) {
- var schema = common.getOption(options, 'schema', DEFAULT_SCHEMA),
- indent = Math.max(1, common.getOption(options, 'indent', 2)),
- flowLevel = common.getOption(options, 'flowLevel', -1),
- styleMap = compileStyleMap(schema, common.getOption(options, 'styles', null)),
+ options = options || {};
+
+ var schema = options['schema'] || DEFAULT_SCHEMA,
+ indent = Math.max(1, (options['indent'] || 2)),
+ flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']),
+ styleMap = compileStyleMap(schema, options['styles'] || null),
implicitTypes = schema.compiledImplicit,
explicitTypes = schema.compiledExplicit,
View
@@ -115,12 +115,14 @@ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\
function loadAll(input, output, options) {
- var filename = common.getOption(options, 'filename', null),
- schema = common.getOption(options, 'schema', DEFAULT_SCHEMA),
- resolve = common.getOption(options, 'resolve', true),
- validate = common.getOption(options, 'validate', true),
- strict = common.getOption(options, 'strict', false),
- legacy = common.getOption(options, 'legacy', false),
+ options = options || {};
+
+ var filename = options['filename'] || null,
+ schema = options['schema'] || DEFAULT_SCHEMA,
+ resolve = options['resolve'] || true,
+ validate = options['validate'] || true,
+ strict = options['strict'] || false,
+ legacy = options['legacy'] || false,
directiveHandlers = {},
implicitTypes = schema.compiledImplicit,
View
@@ -1,15 +1,16 @@
'use strict';
-var common = require('./common');
var YAMLException = require('./exception');
// TODO: Add tag format check.
function Type(tag, options) {
+ options = options || {};
+
this.tag = tag;
- this.loader = common.getOption(options, 'loader', null);
- this.dumper = common.getOption(options, 'dumper', null);
+ this.loader = options['loader'] || null;
+ this.dumper = options['dumper'] || null;
if (null === this.loader && null === this.dumper) {
throw new YAMLException('Incomplete YAML type definition. "loader" or "dumper" setting must be specified.');
@@ -26,8 +27,10 @@ function Type(tag, options) {
Type.Loader = function TypeLoader(options) {
- this.kind = common.getSetting(options, 'kind');
- this.resolver = common.getOption(options, 'resolver', null);
+ options = options || {};
+
+ this.kind = options['kind'] || null;
+ this.resolver = options['resolver'] || null;
if ('string' !== this.kind &&
'array' !== this.kind &&
@@ -53,12 +56,14 @@ function compileAliases(map) {
Type.Dumper = function TypeDumper(options) {
- this.kind = common.getSetting(options, 'kind');
- this.defaultStyle = common.getOption(options, 'defaultStyle', null);
- this.instanceOf = common.getOption(options, 'instanceOf', null);
- this.predicate = common.getOption(options, 'predicate', null);
- this.representer = common.getOption(options, 'representer', null);
- this.styleAliases = compileAliases(common.getOption(options, 'styleAliases', null));
+ options = options || {};
+
+ this.kind = options['kind'] || null;
+ this.defaultStyle = options['defaultStyle'] || null;
+ this.instanceOf = options['instanceOf'] || null;
+ this.predicate = options['predicate'] || null;
+ this.representer = options['representer'] || null;
+ this.styleAliases = compileAliases(options['styleAliases'] || null);
if ('undefined' !== this.kind &&
'null' !== this.kind &&

0 comments on commit 23ab38b

Please sign in to comment.