Skip to content

Commit

Permalink
Release v0.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Aug 29, 2016
1 parent 8a8cc5b commit 258f30b
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 91 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v0.21.0 - Mon, 29 Aug 2016 18:29:31 GMT
---------------------------------------

- [8a8cc5b](../../commit/8a8cc5b) [changed] remove case aliases and simplify camelCase



v0.20.0 - Wed, 20 Jul 2016 02:02:08 GMT
---------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ json separate from validating it, via the `cast` method.
- [`object.shape(fields: object, noSortEdges: ?Array<[string, string]>): Schema`](#objectshapefields-object-nosortedges-arraystring-string-schema)
- [`object.from(fromKey: string, toKey: string, alias: boolean = false): Schema`](#objectfromfromkey-string-tokey-string-alias-boolean--false-schema)
- [`object.noUnknown(onlyKnownKeys: boolean = true, message: ?string): Schema`](#objectnounknownonlyknownkeys-boolean--true-message-string-schema)
- [`object.camelCase(): Schema`](#objectcamelCase-schema)
- [`object.constantCase(): Schema`](#objectconstantCase-schema)
- [`object.camelCase(): Schema`](#objectcamelcase-schema)
- [`object.constantCase(): Schema`](#objectconstantcase-schema)
- [Extending Schema Types](#extending-schema-types)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down
8 changes: 5 additions & 3 deletions lib/ValidationError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

exports.__esModule = true;
exports.default = ValidationError;

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var strReg = /\$\{\s*(\w+)\s*\}/g;
Expand All @@ -12,8 +15,6 @@ var replace = function replace(str) {
};
};

module.exports = ValidationError;

function ValidationError(errors, value, field, type) {
var _this = this;

Expand Down Expand Up @@ -58,4 +59,5 @@ ValidationError.formatError = function (message, params) {
};

return arguments.length === 1 ? fn : fn(params);
};
};
module.exports = exports['default'];
101 changes: 73 additions & 28 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

exports.__esModule = true;
exports.ValidationError = exports.addMethod = exports.isSchema = exports.reach = exports.lazy = exports.ref = exports.array = exports.object = exports.date = exports.boolean = exports.bool = exports.number = exports.string = exports.mixed = undefined;

var _mixed = require('./mixed');

Expand All @@ -10,6 +11,26 @@ var _boolean = require('./boolean');

var _boolean2 = _interopRequireDefault(_boolean);

var _string = require('./string');

var _string2 = _interopRequireDefault(_string);

var _number = require('./number');

var _number2 = _interopRequireDefault(_number);

var _date = require('./date');

var _date2 = _interopRequireDefault(_date);

var _object = require('./object');

var _object2 = _interopRequireDefault(_object);

var _array = require('./array');

var _array2 = _interopRequireDefault(_array);

var _Reference = require('./Reference');

var _Reference2 = _interopRequireDefault(_Reference);
Expand All @@ -18,41 +39,65 @@ var _Lazy = require('./Lazy');

var _Lazy2 = _interopRequireDefault(_Lazy);

var _ValidationError = require('./ValidationError');

var _ValidationError2 = _interopRequireDefault(_ValidationError);

var _reach = require('./util/reach');

var _reach2 = _interopRequireDefault(_reach);

var _isSchema = require('./util/isSchema');

var _isSchema2 = _interopRequireDefault(_isSchema);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var boolean = _boolean2.default;
var ref = function ref(key, options) {
return new _Reference2.default(key, options);
};

var lazy = function lazy(fn) {
return new _Lazy2.default(fn);
};

function addMethod(schemaType, name, fn) {
if (!schemaType || !(0, _isSchema2.default)(schemaType.prototype)) throw new TypeError('You must provide a yup schema constructor function');

if (typeof name !== 'string') throw new TypeError('A Method name must be provided');
if (typeof fn !== 'function') throw new TypeError('Method function must be provided');

schemaType.prototype[name] = fn;
}

exports.mixed = _mixed2.default;
exports.string = _string2.default;
exports.number = _number2.default;
exports.bool = _boolean2.default;
exports.boolean = boolean;
exports.date = _date2.default;
exports.object = _object2.default;
exports.array = _array2.default;
exports.ref = ref;
exports.lazy = lazy;
exports.reach = _reach2.default;
exports.isSchema = _isSchema2.default;
exports.addMethod = addMethod;
exports.ValidationError = _ValidationError2.default;
exports.default = {
mixed: _mixed2.default,
string: require('./string'),
number: require('./number'),
boolean: _boolean2.default,
string: _string2.default,
number: _number2.default,
bool: _boolean2.default,
date: require('./date'),
object: require('./object'),
array: require('./array'),

reach: require('./util/reach'),

ValidationError: require('./ValidationError'),
ref: function ref(key, options) {
return new _Reference2.default(key, options);
},
lazy: function lazy(fn) {
return new _Lazy2.default(fn);
},

boolean: boolean,
date: _date2.default,
object: _object2.default,
array: _array2.default,
ref: ref,
lazy: lazy,
reach: _reach2.default,
isSchema: _isSchema2.default,

addMethod: function addMethod(schemaType, name, fn) {
if (!schemaType || !(0, _isSchema2.default)(schemaType.prototype)) throw new TypeError('You must provide a yup schema constructor function');

if (typeof name !== 'string') throw new TypeError('A Method name must be provided');
if (typeof fn !== 'function') throw new TypeError('Method function must be provided');

schemaType.prototype[name] = fn;
}
};
module.exports = exports['default'];
addMethod: addMethod,
ValidationError: _ValidationError2.default
};
17 changes: 12 additions & 5 deletions lib/mixed.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

exports.__esModule = true;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = SchemaType;

var _has = require('lodash/has');

var _has2 = _interopRequireDefault(_has);
Expand Down Expand Up @@ -49,9 +53,13 @@ var notEmpty = function notEmpty(value) {
function extractTestParams(name, message, test, useCallback) {
var opts = name;

if (typeof message === 'function') test = message, message = _locale.mixed.default, name = null;
if (typeof message === 'function') {
test = message;message = _locale.mixed.default;name = null;
}

if (typeof name === 'function') test = name, message = _locale.mixed.default, name = null;
if (typeof name === 'function') {
test = name;message = _locale.mixed.default;name = null;
}

if (typeof name === 'string' || name === null) opts = { name: name, test: test, message: message, useCallback: useCallback, exclusive: false };

Expand All @@ -60,8 +68,6 @@ function extractTestParams(name, message, test, useCallback) {
return opts;
}

module.exports = SchemaType;

function SchemaType() {
var _this = this;

Expand Down Expand Up @@ -443,4 +449,5 @@ function nodeify(promise, cb) {
}, function (err) {
return cb(err);
});
}
}
module.exports = exports['default'];
8 changes: 5 additions & 3 deletions lib/number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

exports.__esModule = true;
exports.default = NumberSchema;

var _inherits = require('./util/inherits');

var _inherits2 = _interopRequireDefault(_inherits);
Expand All @@ -16,8 +19,6 @@ var _isAbsent2 = _interopRequireDefault(_isAbsent);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = NumberSchema;

var isNaN = function isNaN(value) {
return value != +value;
};
Expand Down Expand Up @@ -102,4 +103,5 @@ function NumberSchema() {
return !(0, _isAbsent2.default)(value) ? Math[method](value) : value;
});
}
});
});
module.exports = exports['default'];
52 changes: 26 additions & 26 deletions lib/object.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

exports.__esModule = true;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _templateObject = _taggedTemplateLiteralLoose(['', '.', ''], ['', '.', '']);

var _case = require('case');

var _case2 = _interopRequireDefault(_case);
exports.default = ObjectSchema;

var _has = require('lodash/has');

Expand All @@ -16,6 +16,14 @@ var _omit = require('lodash/omit');

var _omit2 = _interopRequireDefault(_omit);

var _snakeCase2 = require('lodash/snakeCase');

var _snakeCase3 = _interopRequireDefault(_snakeCase2);

var _camelCase2 = require('lodash/camelCase');

var _camelCase3 = _interopRequireDefault(_camelCase2);

var _mapKeys = require('lodash/mapKeys');

var _mapKeys2 = _interopRequireDefault(_mapKeys);
Expand Down Expand Up @@ -65,19 +73,6 @@ function unknown(ctx, value) {
});
}

/**
* maintain "private" fields
* `"__FOO_BAR"` becomes `"__fooBar"` not `"fooBar"`
*/
function camelize(str) {
var result = _case2.default.camel(str),
idx = str.search(/[^_]/);

return idx === 0 ? result : str.substr(0, idx) + result;
}

module.exports = ObjectSchema;

function ObjectSchema(spec) {
var _this2 = this;

Expand Down Expand Up @@ -265,7 +260,10 @@ function ObjectSchema(spec) {
var noAllow = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
var message = arguments.length <= 1 || arguments[1] === undefined ? _locale.object.noUnknown : arguments[1];

if (typeof noAllow === 'string') message = noAllow, noAllow = true;
if (typeof noAllow === 'string') {
message = noAllow;
noAllow = true;
}

var next = this.test({
name: 'noUnknown',
Expand All @@ -280,21 +278,23 @@ function ObjectSchema(spec) {

return next;
},
camelCase: function camelCase() {
transformKeys: function transformKeys(fn) {
return this.transform(function (obj) {
return obj && (0, _mapKeys2.default)(obj, function (_, key) {
return camelize(key);
return fn(key);
});
});
},
camelCase: function camelCase() {
return this.transformKeys(_camelCase3.default);
},
snakeCase: function snakeCase() {
return this.transformKeys(_snakeCase3.default);
},
constantCase: function constantCase() {
return this.transform(function (obj) {
return obj && (0, _mapKeys2.default)(obj, function (_, key) {
return _case2.default.constant(key);
});
return this.transformKeys(function (key) {
return (0, _snakeCase3.default)(key).toUpperCase();
});
}
});

ObjectSchema.prototype.camelCase = ObjectSchema.prototype.camelCase;
ObjectSchema.prototype.constantCase = ObjectSchema.prototype.constantCase;
module.exports = exports['default'];
15 changes: 11 additions & 4 deletions lib/string.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

exports.__esModule = true;
exports.default = StringSchema;

var _inherits = require('./util/inherits');

var _inherits2 = _interopRequireDefault(_inherits);
Expand All @@ -26,8 +29,6 @@ var isTrimmed = function isTrimmed(value) {
return (0, _isAbsent2.default)(value) || value === value.trim();
};

module.exports = StringSchema;

function StringSchema() {
var _this = this;

Expand Down Expand Up @@ -77,11 +78,16 @@ function StringSchema() {
});
},
matches: function matches(regex, msg) {
var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

var _ref$excludeEmptyStri = _ref.excludeEmptyString;
var excludeEmptyString = _ref$excludeEmptyStri === undefined ? true : _ref$excludeEmptyStri;

return this.test({
message: msg || _locale.string.matches,
params: { regex: regex },
test: function test(value) {
return (0, _isAbsent2.default)(value) || regex.test(value);
return (0, _isAbsent2.default)(value) || value === '' && excludeEmptyString || regex.test(value);
}
});
},
Expand Down Expand Up @@ -130,4 +136,5 @@ function StringSchema() {
}
});
}
});
});
module.exports = exports['default'];
Loading

0 comments on commit 258f30b

Please sign in to comment.