Comparing version 1.1.0 to 1.2.0
918
dist/lgtm.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.LGTM = global.LGTM || {}))); | ||
}(this, function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.LGTM = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
var config = {}; | ||
var config = {}; | ||
/** | ||
* Iteration | ||
*/ | ||
/** | ||
* Iteration | ||
*/ | ||
function forEach(iterable, iterator) { | ||
if (typeof iterable.forEach === 'function') { | ||
iterable.forEach(iterator); | ||
} else if ({}.toString.call(iterable) === '[object Object]') { | ||
var hasOwnProp = {}.hasOwnProperty; | ||
for (var key in iterable) { | ||
if (hasOwnProp.call(iterable, key)) { | ||
iterator(iterable[key], key); | ||
} | ||
} | ||
} else { | ||
for (var i = 0; i < iterable.length; i++) { | ||
iterator(iterable[i], i); | ||
} | ||
} | ||
} | ||
function keys(object) { | ||
if (Object.getOwnPropertyNames) { | ||
return Object.getOwnPropertyNames(object); | ||
} else { | ||
var result = []; | ||
forEach(object, function (key) { | ||
result.push(key); | ||
}); | ||
return result; | ||
} | ||
function keys(object) { | ||
return Object.getOwnPropertyNames(object); | ||
} | ||
/** | ||
* Property access | ||
*/ | ||
function get(object, property) { | ||
if (object === null || object === undefined) { | ||
return; | ||
} else if (typeof object.get === 'function') { | ||
return object.get(property); | ||
} else { | ||
return object[property]; | ||
} | ||
} | ||
/** | ||
* Property access | ||
*/ | ||
function getProperties(object, properties) { | ||
var get = config.get; | ||
function get(object, property) { | ||
if (object === null || object === undefined) { | ||
return; | ||
} else if (typeof object.get === 'function') { | ||
return object.get(property); | ||
} else { | ||
return object[property]; | ||
return properties.map(function (prop) { | ||
return get(object, prop); | ||
}); | ||
} | ||
/** | ||
* Array manipulation | ||
*/ | ||
function contains(array, object) { | ||
return array.indexOf(object) > -1; | ||
} | ||
function uniq(array) { | ||
var result = []; | ||
for (var i = 0; i < array.length; i++) { | ||
var item = array[i]; | ||
if (!contains(result, item)) { | ||
result.push(item); | ||
} | ||
} | ||
function getProperties(object, properties) { | ||
var get = config.get; | ||
return result; | ||
} | ||
return properties.map(function (prop) { | ||
return get(object, prop); | ||
}); | ||
} | ||
/** | ||
* Promises | ||
*/ | ||
/** | ||
* Array manipulation | ||
*/ | ||
function resolve(thenable) { | ||
var Promise = config.Promise; | ||
function contains(array, object) { | ||
return array.indexOf(object) > -1; | ||
return new Promise(function (accept) { | ||
return accept(thenable); | ||
}); | ||
} | ||
function all(thenables) { | ||
var Promise = config.Promise; | ||
return Promise.all(thenables); | ||
} | ||
var asyncGenerator = function () { | ||
function AwaitValue(value) { | ||
this.value = value; | ||
} | ||
function uniq(array) { | ||
var result = []; | ||
function AsyncGenerator(gen) { | ||
var front, back; | ||
for (var i = 0; i < array.length; i++) { | ||
var item = array[i]; | ||
if (!contains(result, item)) { | ||
result.push(item); | ||
function send(key, arg) { | ||
return new Promise(function (resolve, reject) { | ||
var request = { | ||
key: key, | ||
arg: arg, | ||
resolve: resolve, | ||
reject: reject, | ||
next: null | ||
}; | ||
if (back) { | ||
back = back.next = request; | ||
} else { | ||
front = back = request; | ||
resume(key, arg); | ||
} | ||
}); | ||
} | ||
function resume(key, arg) { | ||
try { | ||
var result = gen[key](arg); | ||
var value = result.value; | ||
if (value instanceof AwaitValue) { | ||
Promise.resolve(value.value).then(function (arg) { | ||
resume("next", arg); | ||
}, function (arg) { | ||
resume("throw", arg); | ||
}); | ||
} else { | ||
settle(result.done ? "return" : "normal", result.value); | ||
} | ||
} catch (err) { | ||
settle("throw", err); | ||
} | ||
} | ||
return result; | ||
function settle(type, value) { | ||
switch (type) { | ||
case "return": | ||
front.resolve({ | ||
value: value, | ||
done: true | ||
}); | ||
break; | ||
case "throw": | ||
front.reject(value); | ||
break; | ||
default: | ||
front.resolve({ | ||
value: value, | ||
done: false | ||
}); | ||
break; | ||
} | ||
front = front.next; | ||
if (front) { | ||
resume(front.key, front.arg); | ||
} else { | ||
back = null; | ||
} | ||
} | ||
this._invoke = send; | ||
if (typeof gen.return !== "function") { | ||
this.return = undefined; | ||
} | ||
} | ||
/** | ||
* Promises | ||
*/ | ||
if (typeof Symbol === "function" && Symbol.asyncIterator) { | ||
AsyncGenerator.prototype[Symbol.asyncIterator] = function () { | ||
return this; | ||
}; | ||
} | ||
function resolve(thenable) { | ||
var Promise = config.Promise; | ||
AsyncGenerator.prototype.next = function (arg) { | ||
return this._invoke("next", arg); | ||
}; | ||
return new Promise(function (accept) { | ||
return accept(thenable); | ||
}); | ||
AsyncGenerator.prototype.throw = function (arg) { | ||
return this._invoke("throw", arg); | ||
}; | ||
AsyncGenerator.prototype.return = function (arg) { | ||
return this._invoke("return", arg); | ||
}; | ||
return { | ||
wrap: function (fn) { | ||
return function () { | ||
return new AsyncGenerator(fn.apply(this, arguments)); | ||
}; | ||
}, | ||
await: function (value) { | ||
return new AwaitValue(value); | ||
} | ||
}; | ||
}(); | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
function all(thenables) { | ||
var Promise = config.Promise; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return Promise.all(thenables); | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var ObjectValidator = function () { | ||
function ObjectValidator() { | ||
var _this = this; | ||
classCallCheck(this, ObjectValidator); | ||
this._validations = {}; | ||
this._dependencies = {}; | ||
for (var _len = arguments.length, validations = Array(_len), _key = 0; _key < _len; _key++) { | ||
validations[_key] = arguments[_key]; | ||
} | ||
validations.forEach(function (validation) { | ||
return validation.addToValidator(_this); | ||
}); | ||
} | ||
ObjectValidator.prototype = { | ||
_validations: null, | ||
_dependencies: null, | ||
addValidation: function addValidation(attr, fn, message) { | ||
createClass(ObjectValidator, [{ | ||
key: 'addValidation', | ||
value: function addValidation(attr, fn, message) { | ||
var list = this._validations[attr]; | ||
@@ -120,9 +298,9 @@ | ||
list.push([fn, message]); | ||
}, | ||
} | ||
// e.g. spouseName (dependentAttribute) depends on maritalStatus (parentAttribute) | ||
addDependentsFor: function addDependentsFor() /* parentAttribute, ...dependentAttributes */{ | ||
var dependentAttributes = [].slice.apply(arguments); | ||
var parentAttribute = dependentAttributes.shift(); | ||
}, { | ||
key: 'addDependentsFor', | ||
value: function addDependentsFor(parentAttribute) { | ||
var dependentsForParent = this._dependencies[parentAttribute]; | ||
@@ -134,2 +312,6 @@ | ||
for (var _len2 = arguments.length, dependentAttributes = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
dependentAttributes[_key2 - 1] = arguments[_key2]; | ||
} | ||
for (var i = 0; i < dependentAttributes.length; i++) { | ||
@@ -141,17 +323,21 @@ var attr = dependentAttributes[i]; | ||
} | ||
}, | ||
attributes: function attributes() { | ||
} | ||
}, { | ||
key: 'attributes', | ||
value: function attributes() { | ||
return uniq(keys(this._validations).concat(keys(this._dependencies))); | ||
}, | ||
} | ||
}, { | ||
key: 'validate', | ||
value: function validate(object) { | ||
var _this2 = this; | ||
validate: function validate() /* object, attributes..., callback */{ | ||
var attributes = [].slice.apply(arguments); | ||
var object = attributes.shift(); | ||
var callback = attributes.pop(); | ||
var self = this; | ||
for (var _len3 = arguments.length, attributes = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
attributes[_key3 - 1] = arguments[_key3]; | ||
} | ||
if (typeof callback === 'string') { | ||
attributes.push(callback); | ||
callback = null; | ||
var callback = null; | ||
if (typeof attributes[attributes.length - 1] !== 'string') { | ||
callback = attributes.pop(); | ||
} | ||
@@ -171,3 +357,3 @@ | ||
var promise = all(validationPromises).then(function (results) { | ||
results = self._collectResults(results); | ||
results = _this2._collectResults(results); | ||
if (callback) { | ||
@@ -187,5 +373,6 @@ callback(null, results); | ||
} | ||
}, | ||
_validateAttribute: function _validateAttribute(object, attr, alreadyValidating) { | ||
} | ||
}, { | ||
key: '_validateAttribute', | ||
value: function _validateAttribute(object, attr, alreadyValidating) { | ||
var value = config.get(object, attr); | ||
@@ -222,5 +409,6 @@ var validations = this._validations[attr]; | ||
return results; | ||
}, | ||
_collectResults: function _collectResults(results) { | ||
} | ||
}, { | ||
key: '_collectResults', | ||
value: function _collectResults(results) { | ||
var result = { | ||
@@ -251,31 +439,35 @@ valid: true, | ||
return result; | ||
}, | ||
} | ||
// e.g. getDependents("maritalStatus") # => ["spouseName"] | ||
_getDependentsFor: function _getDependentsFor(parentAttribute) { | ||
}, { | ||
key: '_getDependentsFor', | ||
value: function _getDependentsFor(parentAttribute) { | ||
return (this._dependencies[parentAttribute] || []).slice(); | ||
} | ||
}; | ||
}]); | ||
return ObjectValidator; | ||
}(); | ||
function ValidatorBuilder() { | ||
this._validator = new ObjectValidator(); | ||
var Validation = function () { | ||
function Validation(attr) { | ||
classCallCheck(this, Validation); | ||
this._attr = null; | ||
this._conditions = []; | ||
this._subvalidations = []; | ||
this._dependencies = []; | ||
this._attr = attr; | ||
} | ||
ValidatorBuilder.prototype = { | ||
_attr: null, | ||
_conditions: null, | ||
_conditionDependencies: null, | ||
_validator: null, | ||
createClass(Validation, [{ | ||
key: 'when', | ||
value: function when() /*, predicate */{ | ||
for (var _len = arguments.length, dependencies = Array(_len), _key = 0; _key < _len; _key++) { | ||
dependencies[_key] = arguments[_key]; | ||
} | ||
validates: function validates(attr) { | ||
this._attr = attr; | ||
this._conditions = []; | ||
this._conditionDependencies = []; | ||
return this; | ||
}, | ||
var predicate = dependencies.pop(); | ||
when: function when() /* ...dependencies, condition */{ | ||
var dependencies = [].slice.apply(arguments); | ||
var condition = dependencies.pop(); | ||
if (dependencies.length === 0) { | ||
@@ -285,20 +477,21 @@ dependencies = [this._attr]; | ||
for (var i = 0; i < dependencies.length; i++) { | ||
var dependency = dependencies[i]; | ||
if (dependency !== this._attr) { | ||
this._validator.addDependentsFor(dependency, this._attr); | ||
} | ||
} | ||
this._conditions.push({ | ||
predicate: predicate, | ||
dependencies: dependencies | ||
}); | ||
this._conditions.push(condition); | ||
this._conditionDependencies.push(dependencies); | ||
return this; | ||
}, | ||
and: function and() /* ...dependencies, condition */{ | ||
} | ||
}, { | ||
key: 'and', | ||
value: function and() { | ||
return this.when.apply(this, arguments); | ||
}, | ||
} | ||
}, { | ||
key: 'using', | ||
value: function using() /*, predicate, message */{ | ||
for (var _len2 = arguments.length, dependencies = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
dependencies[_key2] = arguments[_key2]; | ||
} | ||
using: function using() /* ...dependencies, predicate, message */{ | ||
var dependencies = [].slice.apply(arguments); | ||
var message = dependencies.pop(); | ||
@@ -319,24 +512,18 @@ var predicate = dependencies.pop(); | ||
for (var i = 0; i < dependencies.length; i++) { | ||
var dependency = dependencies[i]; | ||
if (dependency !== this._attr) { | ||
this._validator.addDependentsFor(dependency, this._attr); | ||
} | ||
} | ||
function validation(value, attr, object) { | ||
var properties = getProperties(object, dependencies); | ||
return predicate.apply(null, properties.concat([attr, object])); | ||
return predicate.apply(undefined, toConsumableArray(properties).concat([attr, object])); | ||
} | ||
var conditions = this._conditions.slice(); | ||
var conditionDependencies = this._conditionDependencies.slice(); | ||
function validationWithConditions(value, attr, object) { | ||
return all(conditions.map(function (condition, i) { | ||
var dependencies = conditionDependencies[i]; | ||
return all(conditions.map(function (_ref) { | ||
var predicate = _ref.predicate, | ||
dependencies = _ref.dependencies; | ||
var properties = getProperties(object, dependencies); | ||
return condition.apply(null, properties.concat([attr, object])); | ||
return predicate.apply(undefined, toConsumableArray(properties).concat([attr, object])); | ||
})).then(function (results) { | ||
for (var i = 0; i < results.length; i++) { | ||
for (var i = 0; i < results.length; i += 1) { | ||
// a condition resolved to a falsy value; return as valid | ||
@@ -347,2 +534,3 @@ if (!results[i]) { | ||
} | ||
// all conditions resolved to truthy values; continue with validation | ||
@@ -353,227 +541,335 @@ return validation(value, attr, object); | ||
this._validator.addValidation(this._attr, conditions ? validationWithConditions : validation, message); | ||
this._subvalidations.push({ | ||
dependencies: dependencies, | ||
validation: conditions ? validationWithConditions : validation, | ||
message: message | ||
}); | ||
return this; | ||
}, | ||
} | ||
}, { | ||
key: 'addToValidator', | ||
value: function addToValidator(validator) { | ||
var _this = this; | ||
build: function build() { | ||
return this._validator; | ||
this.dependencies().forEach(function (dependency) { | ||
validator.addDependentsFor(dependency, _this._attr); | ||
}); | ||
this._subvalidations.forEach(function (subvalidation) { | ||
validator.addValidation(_this._attr, subvalidation.validation, subvalidation.message); | ||
}); | ||
} | ||
}; | ||
}, { | ||
key: 'dependencies', | ||
value: function dependencies() { | ||
var dependencies = []; | ||
ValidatorBuilder.registerHelper = function (name, fn) { | ||
this.prototype[name] = function () { | ||
fn.apply(this, arguments); | ||
return this; | ||
}; | ||
return null; | ||
}; | ||
this._conditions.forEach(function (condition) { | ||
condition.dependencies.forEach(function (dependency) { | ||
dependencies.push(dependency); | ||
}); | ||
}); | ||
ValidatorBuilder.unregisterHelper = function (name) { | ||
delete this.prototype[name]; | ||
return null; | ||
}; | ||
this._subvalidations.forEach(function (subvalidation) { | ||
subvalidation.dependencies.forEach(function (dependency) { | ||
dependencies.push(dependency); | ||
}); | ||
}); | ||
function present(value) { | ||
if (typeof value === 'string') { | ||
value = value.trim(); | ||
return dependencies; | ||
} | ||
}]); | ||
return Validation; | ||
}(); | ||
return value !== '' && value !== null && value !== undefined; | ||
var ValidatorBuilder = function () { | ||
function ValidatorBuilder() { | ||
classCallCheck(this, ValidatorBuilder); | ||
this._validations = null; | ||
this._validation = null; | ||
for (var _len = arguments.length, validations = Array(_len), _key = 0; _key < _len; _key++) { | ||
validations[_key] = arguments[_key]; | ||
} | ||
this._validations = validations; | ||
} | ||
var STRICT_CHARS = /^[\x20-\x7F]*$/; | ||
// http://stackoverflow.com/a/46181/11236 | ||
var EMAIL = /^(([^<>()\[\]\\.,;:\s@\"]+(\.[^<>()\[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
createClass(ValidatorBuilder, [{ | ||
key: 'validates', | ||
value: function validates(attr) { | ||
this._validation = new Validation(attr); | ||
this._validations.push(this._validation); | ||
return this; | ||
} | ||
}, { | ||
key: 'when', | ||
value: function when() /* ...dependencies, condition */{ | ||
var _validation; | ||
function checkEmail(options) { | ||
if (!options) { | ||
options = {}; | ||
(_validation = this._validation).when.apply(_validation, arguments); | ||
return this; | ||
} | ||
}, { | ||
key: 'and', | ||
value: function and() /* ...dependencies, condition */{ | ||
var _validation2; | ||
return function (value) { | ||
if (typeof value === 'string') { | ||
value = value.trim(); | ||
} | ||
(_validation2 = this._validation).and.apply(_validation2, arguments); | ||
return this; | ||
} | ||
}, { | ||
key: 'using', | ||
value: function using() /* ...dependencies, predicate, message */{ | ||
var _validation3; | ||
if (options.strictCharacters) { | ||
if (!STRICT_CHARS.test(value)) { | ||
return false; | ||
} | ||
} | ||
(_validation3 = this._validation).using.apply(_validation3, arguments); | ||
return this; | ||
} | ||
}, { | ||
key: 'build', | ||
value: function build() { | ||
return new (Function.prototype.bind.apply(ObjectValidator, [null].concat(toConsumableArray(this._validations))))(); | ||
} | ||
}], [{ | ||
key: 'registerHelper', | ||
value: function registerHelper(name, fn) { | ||
this.prototype[name] = function () { | ||
fn.apply(this._validation, arguments); | ||
return this; | ||
}; | ||
return EMAIL.test(value); | ||
}; | ||
Validation.prototype[name] = function () { | ||
fn.apply(this, arguments); | ||
return this; | ||
}; | ||
return null; | ||
} | ||
}, { | ||
key: 'unregisterHelper', | ||
value: function unregisterHelper(name) { | ||
delete this.prototype[name]; | ||
delete Validation.prototype[name]; | ||
return null; | ||
} | ||
}]); | ||
return ValidatorBuilder; | ||
}(); | ||
function present(value) { | ||
if (typeof value === 'string') { | ||
value = value.trim(); | ||
} | ||
function checkMinLength(minLength) { | ||
if (minLength === null || minLength === undefined) { | ||
throw new Error('must specify a min length'); | ||
return value !== '' && value !== null && value !== undefined; | ||
} | ||
var STRICT_CHARS = /^[\x20-\x7F]*$/; | ||
// http://stackoverflow.com/a/46181/11236 | ||
var EMAIL = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
function checkEmail() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return function (value) { | ||
if (typeof value === 'string') { | ||
value = value.trim(); | ||
} | ||
return function (value) { | ||
if (value !== null && value !== undefined) { | ||
return value.length >= minLength; | ||
} else { | ||
if (options.strictCharacters) { | ||
if (!STRICT_CHARS.test(value)) { | ||
return false; | ||
} | ||
}; | ||
} | ||
return EMAIL.test(value); | ||
}; | ||
} | ||
function checkMinLength(minLength) { | ||
if (minLength === null || minLength === undefined) { | ||
throw new Error('must specify a min length'); | ||
} | ||
function checkMaxLength(maxLength) { | ||
if (maxLength === null || maxLength === undefined) { | ||
throw new Error('must specify a max length'); | ||
return function (value) { | ||
if (value !== null && value !== undefined) { | ||
return value.length >= minLength; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
} | ||
return function (value) { | ||
if (value !== null && value !== undefined) { | ||
return value.length <= maxLength; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
function checkMaxLength(maxLength) { | ||
if (maxLength === null || maxLength === undefined) { | ||
throw new Error('must specify a max length'); | ||
} | ||
function register$1() { | ||
ValidatorBuilder.registerHelper('required', function (message) { | ||
this.using(present, message); | ||
}); | ||
return function (value) { | ||
if (value !== null && value !== undefined) { | ||
return value.length <= maxLength; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
} | ||
ValidatorBuilder.registerHelper('optional', function () { | ||
this.when(present); | ||
}); | ||
function register$1() { | ||
ValidatorBuilder.registerHelper('required', function (message) { | ||
this.using(present, message); | ||
}); | ||
ValidatorBuilder.registerHelper('email', function (message, options) { | ||
this.using(checkEmail(options), message); | ||
}); | ||
ValidatorBuilder.registerHelper('optional', function () { | ||
this.when(present); | ||
}); | ||
ValidatorBuilder.registerHelper('minLength', function (minLength, message) { | ||
this.using(checkMinLength(minLength), message); | ||
}); | ||
ValidatorBuilder.registerHelper('email', function (message, options) { | ||
this.using(checkEmail(options), message); | ||
}); | ||
ValidatorBuilder.registerHelper('maxLength', function (maxLength, message) { | ||
this.using(checkMaxLength(maxLength), message); | ||
}); | ||
} | ||
ValidatorBuilder.registerHelper('minLength', function (minLength, message) { | ||
this.using(checkMinLength(minLength), message); | ||
}); | ||
register$1(); | ||
ValidatorBuilder.registerHelper('maxLength', function (maxLength, message) { | ||
this.using(checkMaxLength(maxLength), message); | ||
}); | ||
} | ||
function validator() { | ||
return new ValidatorBuilder(); | ||
} | ||
register$1(); | ||
function register() { | ||
ValidatorBuilder.registerHelper.apply(ValidatorBuilder, arguments); | ||
function validator() { | ||
for (var _len = arguments.length, validations = Array(_len), _key = 0; _key < _len; _key++) { | ||
validations[_key] = arguments[_key]; | ||
} | ||
function unregister() { | ||
ValidatorBuilder.unregisterHelper.apply(ValidatorBuilder, arguments); | ||
} | ||
return new (Function.prototype.bind.apply(ValidatorBuilder, [null].concat(validations)))(); | ||
} | ||
var helpers = { | ||
core: { | ||
present: present, | ||
checkEmail: checkEmail, | ||
checkMinLength: checkMinLength, | ||
checkMaxLength: checkMaxLength, | ||
register: register$1 | ||
}, | ||
register: register, | ||
unregister: unregister | ||
}; | ||
function validates(attr) { | ||
return new Validation(attr); | ||
} | ||
function configure(key, value) { | ||
config[key] = value; | ||
} | ||
function register$$1() { | ||
ValidatorBuilder.registerHelper.apply(ValidatorBuilder, arguments); | ||
} | ||
configure('defer', function () { | ||
var Promise = config['Promise']; | ||
var resolve = void 0; | ||
var reject = void 0; | ||
var promise = new Promise(function (res, rej) { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
function unregister() { | ||
ValidatorBuilder.unregisterHelper.apply(ValidatorBuilder, arguments); | ||
} | ||
if (!resolve || !reject) { | ||
throw new Error('Configured promise does not behave as expected'); | ||
} | ||
var helpers = { | ||
core: { | ||
present: present, | ||
checkEmail: checkEmail, | ||
checkMinLength: checkMinLength, | ||
checkMaxLength: checkMaxLength, | ||
register: register$1 | ||
}, | ||
register: register$$1, | ||
unregister: unregister | ||
}; | ||
return { promise: promise, resolve: resolve, reject: reject }; | ||
function configure(key, value) { | ||
config[key] = value; | ||
} | ||
configure('defer', function () { | ||
var Promise = config['Promise']; | ||
var resolve$$1 = void 0; | ||
var reject = void 0; | ||
var promise = new Promise(function (res, rej) { | ||
resolve$$1 = res; | ||
reject = rej; | ||
}); | ||
function PromiseProxy(callback) { | ||
var Promise = getPromise(); | ||
return new Promise(callback); | ||
if (!resolve$$1 || !reject) { | ||
throw new Error('Configured promise does not behave as expected'); | ||
} | ||
PromiseProxy.all = function () { | ||
var _getPromise; | ||
return { promise: promise, resolve: resolve$$1, reject: reject }; | ||
}); | ||
return (_getPromise = getPromise()).all.apply(_getPromise, arguments); | ||
}; | ||
function PromiseProxy(callback) { | ||
var Promise = getPromise(); | ||
return new Promise(callback); | ||
} | ||
PromiseProxy.race = function () { | ||
var _getPromise2; | ||
PromiseProxy.all = function () { | ||
var _getPromise; | ||
return (_getPromise2 = getPromise()).race.apply(_getPromise2, arguments); | ||
}; | ||
return (_getPromise = getPromise()).all.apply(_getPromise, arguments); | ||
}; | ||
PromiseProxy.resolve = function () { | ||
var _getPromise3; | ||
PromiseProxy.race = function () { | ||
var _getPromise2; | ||
return (_getPromise3 = getPromise()).resolve.apply(_getPromise3, arguments); | ||
}; | ||
return (_getPromise2 = getPromise()).race.apply(_getPromise2, arguments); | ||
}; | ||
PromiseProxy.reject = function () { | ||
var _getPromise4; | ||
PromiseProxy.resolve = function () { | ||
var _getPromise3; | ||
return (_getPromise4 = getPromise()).reject.apply(_getPromise4, arguments); | ||
}; | ||
return (_getPromise3 = getPromise()).resolve.apply(_getPromise3, arguments); | ||
}; | ||
function getPromise() { | ||
var warn = config['warn']; | ||
PromiseProxy.reject = function () { | ||
var _getPromise4; | ||
/* global Promise, RSVP, require */ | ||
if (typeof RSVP !== 'undefined') { | ||
configure('Promise', RSVP.Promise); | ||
warn('Implicitly using RSVP.Promise. This will be removed in LGTM 2.0. ' + 'Instead, use \'LGTM.configure("Promise", RSVP.Promise)\' to ' + 'continue using RSVP promises.'); | ||
return RSVP.Promise; | ||
} | ||
return (_getPromise4 = getPromise()).reject.apply(_getPromise4, arguments); | ||
}; | ||
if (typeof require === 'function') { | ||
try { | ||
var _Promise = require('rsvp').Promise; | ||
configure('Promise', _Promise); | ||
warn('Implicitly using require("rsvp").Promise. This will be removed in LGTM 2.0. ' + 'Instead, use \'LGTM.configure("Promise", require("rsvp").Promise)\' to ' + 'continue using RSVP promises.'); | ||
return _Promise; | ||
} catch (err) { | ||
// Ignore errors, just try built-in Promise or fail. | ||
} | ||
} | ||
function getPromise() { | ||
var warn = config['warn']; | ||
if (typeof Promise === 'function') { | ||
configure('Promise', Promise); | ||
return Promise; | ||
/* global Promise, RSVP, require */ | ||
if (typeof RSVP !== 'undefined') { | ||
configure('Promise', RSVP.Promise); | ||
warn('Implicitly using RSVP.Promise. This will be removed in LGTM 2.0. ' + 'Instead, use \'LGTM.configure("Promise", RSVP.Promise)\' to ' + 'continue using RSVP promises.'); | ||
return RSVP.Promise; | ||
} | ||
if (typeof require === 'function') { | ||
try { | ||
var _require = require('rsvp'), | ||
_Promise = _require.Promise; | ||
configure('Promise', _Promise); | ||
warn('Implicitly using require("rsvp").Promise. This will be removed in LGTM 2.0. ' + 'Instead, use \'LGTM.configure("Promise", require("rsvp").Promise)\' to ' + 'continue using RSVP promises.'); | ||
return _Promise; | ||
} catch (err) { | ||
// Ignore errors, just try built-in Promise or fail. | ||
} | ||
} | ||
throw new Error('\'Promise\' could not be found. Configure LGTM with your promise library using ' + 'e.g. \'LGTM.configure("Promise", RSVP.Promise)\'.'); | ||
if (typeof Promise === 'function') { | ||
configure('Promise', Promise); | ||
return Promise; | ||
} | ||
/* global console */ | ||
configure('Promise', PromiseProxy); | ||
configure('warn', console.warn.bind(console)); // eslint-disable-line no-console | ||
configure('get', function (object, property) { | ||
var warn = config['warn']; | ||
throw new Error('\'Promise\' could not be found. Configure LGTM with your promise library using ' + 'e.g. \'LGTM.configure("Promise", RSVP.Promise)\'.'); | ||
} | ||
configure('get', get); | ||
warn('Implicitly using \'get\' implementation that uses a \'get\' method when available. ' + 'This will be removed in LGTM 2.0. Instead, use e.g. \'LGTM.configure("get", Ember.get)\' ' + 'if you rely on this behavior.'); | ||
return get(object, property); | ||
}); | ||
/* global console */ | ||
configure('Promise', PromiseProxy); | ||
configure('warn', console.warn.bind(console)); // eslint-disable-line no-console | ||
configure('get', function (object, property) { | ||
var warn = config['warn']; | ||
exports.configure = configure; | ||
exports.validator = validator; | ||
exports.helpers = helpers; | ||
exports.ObjectValidator = ObjectValidator; | ||
configure('get', get); | ||
warn('Implicitly using \'get\' implementation that uses a \'get\' method when available. ' + 'This will be removed in LGTM 2.0. Instead, use e.g. \'LGTM.configure("get", Ember.get)\' ' + 'if you rely on this behavior.'); | ||
return get(object, property); | ||
}); | ||
})); | ||
//# sourceMappingURL=lgtm.js.map | ||
exports.configure = configure; | ||
exports.validator = validator; | ||
exports.validates = validates; | ||
exports.helpers = helpers; | ||
exports.ObjectValidator = ObjectValidator; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=lgtm.js.map |
{ | ||
"name": "lgtm", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Simple JavaScript validation for objects.", | ||
@@ -12,7 +12,8 @@ "main": "dist/lgtm.js", | ||
"test": "mocha", | ||
"prepublish": "npm test && npm run build" | ||
"prepublish": "npm test && npm run build", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:square/lgtm.git" | ||
"url": "https://github.com/square/lgtm.git" | ||
}, | ||
@@ -25,11 +26,21 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel": "^6.5.2", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-es2015-rollup": "^1.1.1", | ||
"babel-register": "^6.9.0", | ||
"babelrc-rollup": "^1.0.0", | ||
"eslint": "^2.10.2", | ||
"mocha": "^2.4.5", | ||
"rollup": "^0.26.3", | ||
"rollup-plugin-babel": "^2.4.0" | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^8.0.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-syntax-class-properties": "^6.13.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
"eslint": "^4.7.2", | ||
"eslint-config-prettier": "^2.6.0", | ||
"eslint-plugin-prettier": "^2.3.1", | ||
"file-size": "^1.0.0", | ||
"gzip-size": "^4.0.0", | ||
"mocha": "^3.5.3", | ||
"prettier": "^1.7.0", | ||
"rollup": "^0.50.0", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"semantic-release": "^8.0.3", | ||
"uglify-js": "^3.1.2" | ||
}, | ||
@@ -42,2 +53,2 @@ "files": [ | ||
} | ||
} | ||
} |
@@ -9,1 +9,3 @@ # LGTM | ||
For examples, installation, setup and more [see the wiki](https://github.com/square/lgtm/wiki). | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/square/lgtm.svg)](https://greenkeeper.io/) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
98794
1325
11
0
19