extra-utilities
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -33,2 +33,3 @@ (function(global, factory) { | ||
camel: changeCase.camelCase, | ||
capital: changeCase.capitalCase, | ||
constant: changeCase.constantCase, | ||
@@ -45,2 +46,3 @@ dot: changeCase.dotCase, | ||
snake: changeCase.snakeCase, | ||
sponge: changeCase.spongeCase, | ||
swap: changeCase.swapCase, | ||
@@ -720,3 +722,3 @@ title: changeCase.titleCase, | ||
format.case = changeCase.camel(format.case.trim()); | ||
format.case = changeCase.camelCase(format.case.trim()); | ||
@@ -2330,1 +2332,3 @@ if(!utilities.isFunction(stringCaseFunctions[format.case])) { | ||
})); | ||
//# sourceMappingURL=extra-utilities.js.map |
@@ -1,1 +0,2 @@ | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.utilities=factory()}(this,function(){"use strict";"undefined"!=typeof require&&("undefined"==typeof validator&&(global.validator=require("validator")),"undefined"==typeof changeCase&&(global.changeCase=require("change-case-bundled")));var utilities={},regExpFlags={global:"g",multiline:"m",ignoreCase:"i",sticky:"y",unicode:"u"},formatTypes=["boolean","bool","integer","int","float","number","string","object","array","date","regex","regexp","regularexpression","function","func"],stringCaseFunctions={camel:changeCase.camelCase,constant:changeCase.constantCase,dot:changeCase.dotCase,header:changeCase.headerCase,lower:changeCase.lowerCase,lowerFirst:changeCase.lowerCaseFirst,no:changeCase.noCase,param:changeCase.paramCase,pascal:changeCase.pascalCase,path:changeCase.pathCase,sentence:changeCase.sentenceCase,snake:changeCase.snakeCase,swap:changeCase.swapCase,title:changeCase.titleCase,upper:changeCase.upperCase,upperFirst:changeCase.upperCaseFirst};return utilities.isValid=function(value){return null!=value},utilities.isInvalid=function(value){return null==value},utilities.isBoolean=function(value,allowObjects){return!0===value||!1===value||!!allowObjects&&value instanceof Boolean},utilities.isValidNumber=function(value){return"number"==typeof value&&!isNaN(value)&&value!==-1/0&&value!==1/0},utilities.isInvalidNumber=function(value){return"number"!=typeof value||isNaN(value)||value===-1/0||value===1/0},utilities.isEmptyString=function(value,trim){return"string"!=typeof value||(utilities.parseBoolean(trim,!0)?0===value.trim().length:0===value.length)},utilities.isNonEmptyString=function(value,trim){return"string"==typeof value&&(utilities.parseBoolean(trim,!0)?0!==value.trim().length:0!==value.length)},utilities.isObject=function(value,strict){return void 0!==value&&(strict?null!==value&&value.constructor===Object:value instanceof Object&&!(value instanceof Function))},utilities.isObjectStrict=function(value){return null!=value&&value.constructor===Object},utilities.isEmptyObject=function(value){return null!=value&&value.constructor===Object&&0===Object.keys(value).length},utilities.isNonEmptyObject=function(value){return null!=value&&value.constructor===Object&&0!==Object.keys(value).length},utilities.isEmptyArray=function(value){return!Array.isArray(value)||0===value.length},utilities.isNonEmptyArray=function(value){return Array.isArray(value)&&0!==value.length},utilities.isDate=function(value){return value instanceof Date},utilities.isError=function(value){return value instanceof Error},utilities.isRegularExpression=function(value){return value instanceof RegExp},utilities.isFunction=function(value){return value instanceof Function},utilities.isComment=function(value,comment){if(utilities.isEmptyString(value))return!1;utilities.isEmptyString(comment)&&(comment="//");for(var commentStartIndex=-1,i=0;i<value.length;i++)if(" "!==value[i]&&"\t"!=value[i]){if(value[i]==comment[0]){commentStartIndex=i;break}return!1}if(commentStartIndex<0||value.length-commentStartIndex<comment.length)return!1;for(i=commentStartIndex;i<value.length&&!(i-commentStartIndex>=comment.length);i++)if(value[i]!=comment[i-commentStartIndex])return!1;return!0},utilities.isVisible=function(element){return!!utilities.isObject(element)&&(utilities.isBoolean(element.visible)?element.visible:utilities.isFunction(element.visible)?element.visible():utilities.isBoolean(element.hidden)?!element.hidden:!utilities.isFunction(element.hidden)||!element.hidden())},utilities.isHidden=function(element){return!utilities.isObject(element)||(utilities.isBoolean(element.visible)?!element.visible:utilities.isFunction(element.visible)?!element.visible():utilities.isBoolean(element.hidden)?element.hidden:!!utilities.isFunction(element.hidden)&&element.hidden())},utilities.isEnabled=function(element){return!!utilities.isObject(element)&&(utilities.isBoolean(element.enabled)?element.enabled:utilities.isFunction(element.enabled)?element.enabled():utilities.isBoolean(element.disabled)?!element.disabled:!utilities.isFunction(element.disabled)||!element.disabled())},utilities.isDisabled=function(element){return!utilities.isObject(element)||(utilities.isBoolean(element.enabled)?!element.enabled:utilities.isFunction(element.enabled)?!element.enabled():utilities.isBoolean(element.disabled)?element.disabled:!!utilities.isFunction(element.disabled)&&element.disabled())},utilities.equalsIgnoreCase=function(stringA,stringB){return"string"==typeof stringA&&"string"==typeof stringB&&0===stringA.localeCompare(stringB,void 0,{sensitivity:"accent"})},utilities.parseBoolean=function(value,defaultValue){if(utilities.isBoolean(value))return value;if(utilities.isBoolean(value,!0))return value.valueOf();if(utilities.isBoolean(defaultValue)||(defaultValue=null),utilities.isInvalid(value))return defaultValue;if(0===value)return!1;if(1===value)return!0;if("string"!=typeof value)return defaultValue;var formattedValue=value.trim().toLowerCase();if(0===formattedValue.length)return defaultValue;if(1===formattedValue.length){var character=formattedValue.charAt(0);return"t"===character||"y"===character||"f"!==character&&"n"!==character&&("0"!==character&&("1"===character||defaultValue))}return"true"===formattedValue||"yes"===formattedValue||"on"===formattedValue||"false"!==formattedValue&&"no"!==formattedValue&&"off"!==formattedValue&&defaultValue},utilities.parseInteger=function(value,defaultValue){var newValue=NaN;return"number"==typeof value?newValue=parseInt(value):"string"==typeof value&&validator.isFloat(value)&&(newValue=parseInt(value)),utilities.isInvalidNumber(newValue)?(defaultValue=parseInt(defaultValue),utilities.isValidNumber(defaultValue)?defaultValue:NaN):newValue},utilities.parseFloatingPointNumber=function(value,defaultValue){var newValue=NaN;return"number"==typeof value?newValue=value:"string"==typeof value&&validator.isFloat(value)&&(newValue=parseFloat(value)),utilities.isInvalidNumber(newValue)?utilities.isValidNumber(defaultValue)?defaultValue:NaN:newValue},utilities.parseDate=function(value,defaultValue){if(utilities.isDate(defaultValue)||(defaultValue=null),"number"==typeof value)return utilities.isInvalidNumber(value)||!Number.isInteger(value)?defaultValue:new Date(parseInt(value));if("string"==typeof value){var formattedValue=value.trim();if(0===formattedValue.length)return defaultValue;var timestamp=null;return timestamp=validator.isInt(formattedValue)?parseInt(formattedValue):Date.parse(formattedValue),utilities.isInvalidNumber(timestamp)?defaultValue:new Date(timestamp)}return value instanceof Date?value:defaultValue},utilities.parseTime=function(value,throwErrors){if(throwErrors=utilities.parseBoolean(throwErrors),utilities.isEmptyString(value)){if(throwErrors)throw new Error("Invalid or empty time value.");return null}var formattedValue=value.trim(),hour=null,minutes=null,regularTime=formattedValue.match(/^[ \t]*(([2-9]|[1][0-2]?)(:([0-5][0-9]))?[ \t]*([ap]m))[ \t]*$/i);if(regularTime){var regularHour=utilities.parseInteger(utilities.trimLeadingZeroes(regularTime[2]));if(utilities.isInvalidNumber(regularHour)){if(throwErrors)throw new Error('Invalid regular hour: "'+regularTime[2]+'".');return null}minutes=utilities.parseInteger(utilities.trimLeadingZeroes(regularTime[4])),utilities.isInvalidNumber(minutes)&&(minutes=0);var morning="AM"===(period=regularTime[5].toUpperCase())||"PM"!==period&&null;if(null===morning){if(throwErrors)throw new Error('Invalid period: "'+regularTime[5]+'".');return null}24===(hour=morning?regularHour+(12===regularHour?12:0):regularHour+(12===regularHour?0:12))&&(hour=0)}else{var militaryTime=formattedValue.match(/^[ \t]*(((([0-1][0-9])|(2[0-3])):?([0-5][0-9]))|((24):?(00)))[ \t]*$/i);if(!militaryTime){if(throwErrors)throw new Error('Invalid time: "'+formattedValue+'".');return null}var militaryHour=militaryTime[3],militaryMinutes=militaryTime[6];if((utilities.isInvalid(militaryHour)||utilities.isInvalid(militaryMinutes))&&(militaryHour=militaryTime[8],utilities.isNonEmptyString(militaryTime[9])&&(militaryMinutes=militaryTime[9])),utilities.isInvalid(militaryHour)||utilities.isInvalid(militaryMinutes)){if(throwErrors)throw new Error('Invalid military time: "'+formattedValue+'".');return null}if(hour=utilities.parseInteger(utilities.trimLeadingZeroes(militaryHour)),utilities.isInvalidNumber(hour)){if(throwErrors)throw new Error('Invalid military time hour: "'+militaryHour+'".');return null}if(minutes=utilities.parseInteger(utilities.trimLeadingZeroes(militaryMinutes)),utilities.isInvalidNumber(minutes)){if(throwErrors)throw new Error('Invalid military time minutes: "'+militaryMinutes+'".');return null}24===hour&&0===minutes&&(hour=0)}if(hour<0||23<hour){if(throwErrors)throw new Error('Time hour is out of range (0 - 23): "'+hour+'".');return null}if(minutes<0||59<minutes){if(throwErrors)throw new Error('Time minutes is out of range (0 - 59): "'+minutes+'".');return null}var period=hour<12?"AM":"PM";return{regular:{raw:(regularHour=0===hour?12:hour<=12?hour:hour-12)+":"+utilities.addLeadingZeroes(minutes,2)+" "+period,hour:regularHour,minutes:minutes,period:period,morning:hour<12},military:{raw:utilities.addLeadingZeroes(hour,2)+utilities.addLeadingZeroes(minutes,2),hour:hour,minutes:minutes}}},utilities.parseEmail=function(value){if(utilities.isEmptyString(value))return null;var emailData=value.trim().toLowerCase().match(/([^+@]+)(\+.*)?(@.+\..+)/);return utilities.isInvalid(emailData)||emailData.length<4?null:emailData[1]+emailData[3]},utilities.parseEmailDomain=function(value){if(utilities.isEmptyString(value))return null;var emailDomainData=value.trim().toLowerCase().match(/([^+@]+)(\+.*)?@(.+\..+)/);return utilities.isInvalid(emailDomainData)||emailDomainData.length<4?null:emailDomainData[3]},utilities.parseStringList=function(value){if("string"!=typeof value)return null;if(0===value.length)return[];for(var data=value.split(/[;,]+/),formattedList=[],formattedValue=null,i=0;i<data.length;i++)0!==(formattedValue=data[i].trim()).length&&formattedList.push(formattedValue);return formattedList},utilities.parseRegularExpression=function(value,throwErrors){if(throwErrors=utilities.parseBoolean(throwErrors,!1),utilities.isRegularExpression(value))return value;if(utilities.isEmptyString(value)){if(throwErrors)throw new Error("Regular expression cannot be empty.");return null}var regExpData=value.match(/\s*\/(.*)\/(.*)\s*/);if(!regExpData){if(throwErrors)throw new Error("Invalid regular expression value.");return null}if(throwErrors)return new RegExp(regExpData[1],regExpData[2]);try{return new RegExp(regExpData[1],regExpData[2])}catch(error){return null}},utilities.parseYouTubeLink=function(value){if(utilities.isEmptyString(value))return null;var formattedValue=value.trim(),linkData=formattedValue.match(/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/i);return linkData&&11<=linkData[1].length?linkData[1]:formattedValue.match(/[A-Z0-9_-]{11,}/i)?formattedValue:null},utilities.formatValue=function(value,format,options){if(utilities.isObjectStrict(options)?(options={throwErrors:utilities.parseBoolean(options.throwErrors,!1)}).verbose=utilities.parseBoolean(options.verbose,!options.throwErrors):options={throwErrors:!1,verbose:!0},!utilities.isObjectStrict(format))return utilities.clone(value);format=utilities.clone(format);var errorMessage=null;if(utilities.isEmptyString(format.type))errorMessage="Invalid required type format value - expected non-empty string.";else{var originalType=format.type;format.type=format.type.trim().toLowerCase();for(var validFormatType=!1,i=0;i<formatTypes.length;i++)if(format.type===formatTypes[i]){validFormatType=!0;break}if(validFormatType){if("bool"===format.type)format.type="boolean";else if("int"===format.type)format.type="integer";else if("number"===format.type)format.type="float";else if("string"===format.type){if(void 0!==format.trim){var originalTrim=format.trim;format.trim=utilities.parseBoolean(format.trim),null===format.trim&&(errorMessage='Invalid optional trim string format value - expected boolean, received "'+utilities.toString(originalTrim)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.case)if(utilities.isEmptyString(format.case))errorMessage="Invalid optional string case format value - expected non-empty string.";else{var originalCase=format.case;format.case=changeCase.camel(format.case.trim()),utilities.isFunction(stringCaseFunctions[format.case])||(errorMessage="Invalid optional case format value - expected one of "+Object.keys(stringCaseFunctions).join(", ")+', received "'+utilities.toString(originalCase)+'".')}}else if("object"===format.type){if(void 0!==format.strict){var originalStrict=format.strict;format.strict=utilities.parseBoolean(format.strict),null===format.strict&&(errorMessage='Invalid optional strict object format value - expected boolean, received "'+utilities.toString(originalStrict)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.autopopulate){var originalAutopopulate=format.autopopulate;format.autopopulate=utilities.parseBoolean(format.autopopulate),null===format.autopopulate&&(errorMessage='Invalid optional autopopulate object format value - expected boolean, received "'+utilities.toString(originalAutopopulate)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.order){var originalOrder=format.order;format.order=utilities.parseBoolean(format.order),null===format.order&&(errorMessage='Invalid optional order object format value - expected boolean, received "'+utilities.toString(originalOrder)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.removeExtra){var originalRemoveExtra=format.removeExtra;format.removeExtra=utilities.parseBoolean(format.removeExtra),null===format.removeExtra&&(errorMessage='Invalid optional removeExtra object format value - expected boolean, received "'+utilities.toString(originalRemoveExtra)+'".')}}else"regexp"===format.type||"regularexpression"===format.type?format.type="regex":"func"===format.type&&(format.type="function");if(utilities.isInvalid(errorMessage)&&("object"!==format.type&&"array"!==format.type||void 0===format.format||utilities.isObjectStrict(format.format)||(errorMessage='Invalid optional format format value - expected object, received "'+utilities.toString(format.format)+'".')),utilities.isInvalid(errorMessage)&&("string"===format.type||"object"===format.type||"array"===format.type)&&void 0!==format.nonEmpty){var originalNonEmpty=format.nonEmpty;format.nonEmpty=utilities.parseBoolean(format.nonEmpty),null===format.nonEmpty&&(errorMessage='Invalid optional nonEmpty format value - expected boolean, received "'+utilities.toString(originalNonEmpty)+'".')}}else errorMessage="Invalid required type format value - expected one of "+formatTypes.join(", ")+', received "'+utilities.toString(originalType)+'".'}if(utilities.isInvalid(errorMessage)&&void 0!==format.nullable){var originalNullable=format.nullable;format.nullable=utilities.parseBoolean(format.nullable),null===format.nullable&&(errorMessage='Invalid optional nullable format value - expected boolean, received "'+utilities.toString(originalNullable)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.required){var originalRequired=format.required;format.required=utilities.parseBoolean(format.required),null===format.required&&(errorMessage='Invalid optional required format value - expected boolean, received "'+utilities.toString(originalRequired)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.parser&&(utilities.isFunction(format.parser)||(errorMessage='Invalid optional parser format value - expected function, received "'+utilities.toString(format.parser)+'".')),utilities.isInvalid(errorMessage)&&void 0!==format.validator&&(utilities.isFunction(format.validator)||(errorMessage='Invalid optional validator format value - expected function, received "'+utilities.toString(format.validator)+'".')),utilities.isInvalid(errorMessage)&&void 0!==format.formatter&&(utilities.isFunction(format.formatter)||(errorMessage='Invalid optional formatter format value - expected function, received "'+utilities.toString(format.formatter)+'".')),utilities.isValid(errorMessage)){if(options.throwErrors)throw new Error(errorMessage);return options.verbose&&console.error(errorMessage),null}if(utilities.isFunction(format.parser))if(options.throwErrors)value=format.parser(value,format,options);else try{value=format.parser(value,format,options)}catch(error){return options.verbose&&console.error(error.message),null}var formattedValue=void 0;if(void 0===value)formattedValue=utilities.clone(format.default);else if(null===value)format.nullable?formattedValue=null:void 0!==format.default?formattedValue=utilities.clone(format.default):errorMessage="Value cannot be null!";else if("boolean"===format.type)null===(formattedValue=utilities.parseBoolean(value))&&(errorMessage='Invalid boolean value: "'+utilities.toString(value)+'".');else if("integer"===format.type)formattedValue=utilities.parseInteger(value),utilities.isInvalidNumber(formattedValue)&&(errorMessage='Invalid integer value: "'+utilities.toString(value)+'".');else if("float"===format.type)formattedValue=utilities.parseFloatingPointNumber(value),utilities.isInvalidNumber(formattedValue)&&(errorMessage='Invalid float value: "'+utilities.toString(value)+'".');else if("string"===format.type){if(formattedValue="string"==typeof value?value:utilities.toString(value),format.trim&&(formattedValue=formattedValue.trim()),void 0!==format.case&&(formattedValue=stringCaseFunctions[format.case](formattedValue)),format.nonEmpty&&0===formattedValue.length){var message="String value cannot be empty.";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}}else if("array"===format.type){if("string"==typeof value)try{formattedValue=JSON.parse(value),Array.isArray(formattedValue)||(errorMessage='Invalid stringified array value type - expected array: "'+utilities.toString(value)+'".')}catch(error){errorMessage='Invalid stringified array value: "'+utilities.toString(value)+'".'}else Array.isArray(value)?formattedValue=utilities.clone(value):errorMessage='Invalid value type - expected array or stringified array: "'+utilities.toString(value)+'".';if(utilities.isInvalid(errorMessage)&&Array.isArray(formattedValue)){var formattedArray=[];if(utilities.isObjectStrict(format.format)){var formattedElement=null;for(i=0;i<formattedValue.length;i++)if(void 0!==formattedValue[i]){if(options.throwErrors)formattedElement=utilities.formatValue(formattedValue[i],format.format,options);else{(subOptions=utilities.clone(options)).throwErrors=!0;try{formattedElement=utilities.formatValue(formattedValue[i],format.format,subOptions)}catch(error){return options.verbose&&console.error(error.message),null}}formattedArray.push(formattedElement)}}else for(i=0;i<formattedValue.length;i++)void 0!==formattedValue[i]&&formattedArray.push(utilities.clone(formattedValue[i]));if(formattedValue=formattedArray,format.nonEmpty&&0===formattedValue.length){message="Array value cannot be empty.";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}}}else if("date"===format.type)formattedValue=utilities.parseDate(value),utilities.isDate(formattedValue)||(errorMessage='Invalid date value: "'+utilities.toString(value)+'".');else if("regex"===format.type){if(utilities.isRegularExpression(value))formattedValue=utilities.clone(value);else if(options.throwErrors)formattedValue=utilities.parseRegularExpression(value,!0);else try{formattedValue=utilities.parseRegularExpression(value,!0)}catch(error){errorMessage=error.message}utilities.isInvalid(formattedValue)&&(errorMessage='Invalid regular expression value: "'+utilities.toString(value)+'".')}else"function"===format.type&&(formattedValue=value,utilities.isFunction(formattedValue)||(errorMessage='Invalid function value: "'+utilities.toString(value)+'".'));if(utilities.isInvalid(errorMessage)&&"object"===format.type){if(utilities.isValid(value))if("string"==typeof value)try{formattedValue=JSON.parse(value),utilities.isObject(formattedValue,format.strict)||(errorMessage="Invalid stringified object value type - expected "+(format.strict?"strict ":"")+'object: "'+utilities.toString(value)+'".')}catch(error){errorMessage='Invalid stringified object value: "'+utilities.toString(value)+'".'}else utilities.isObject(value,format.strict)?formattedValue=utilities.clone(value):errorMessage="Invalid value type - expected "+(format.strict?"strict ":"")+'object or stringified object: "'+utilities.toString(value)+'".';if(utilities.isInvalid(errorMessage)){if(utilities.isInvalid(formattedValue)&&format.autopopulate&&!utilities.isObject(formattedValue,format.strict)&&(formattedValue={}),utilities.isObjectStrict(format.format)&&utilities.isObject(formattedValue)){var attribute=null,attributes=Object.keys(format.format);for(i=0;i<attributes.length;i++)if(attribute=attributes[i],options.throwErrors){void 0!==(formattedAttribute=utilities.formatValue(formattedValue[attribute],format.format[attribute],options))&&(formattedValue[attribute]=formattedAttribute)}else{var subOptions;(subOptions=utilities.clone(options)).throwErrors=!0;try{var formattedAttribute;void 0!==(formattedAttribute=utilities.formatValue(formattedValue[attribute],format.format[attribute],subOptions))&&(formattedValue[attribute]=formattedAttribute)}catch(error){return options.verbose&&console.error(error.message),null}}if(format.removeExtra){var newValue={};attributes=Object.keys(formattedValue);for(i=0;i<attributes.length;i++)attribute=attributes[i],utilities.isValid(format.format[attribute])&&(newValue[attribute]=formattedValue[attribute]);formattedValue=newValue}if(format.order){var orderedObject={};attributes=Object.keys(format.format);for(i=0;i<attributes.length;i++)void 0!==formattedValue[attribute=attributes[i]]&&(orderedObject[attribute]=formattedValue[attribute],delete formattedValue[attribute]);var extraAttributes=Object.keys(formattedValue);for(i=0;i<extraAttributes.length;i++)orderedObject[attribute=extraAttributes[i]]=formattedValue[attribute];formattedValue=orderedObject}}if(format.nonEmpty&&utilities.isEmptyObject(formattedValue)){message="Object value must contain at least one attribute.";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}}}if(utilities.isValid(errorMessage)){if(options.throwErrors)throw new Error(errorMessage);return options.verbose&&console.error(errorMessage),null}if(void 0===formattedValue){if(format.required){message="Missing required value!";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}void 0!==format.default&&(formattedValue=utilities.clone(format.default))}if(utilities.isFunction(format.validator))if(options.throwErrors){if(!format.validator(formattedValue,format,options))throw new Error("Validation check failed!")}else try{if(!format.validator(formattedValue,format,options)){message="Validation check failed!";return options.verbose&&console.error(message),null}}catch(error){return options.verbose&&console.error(error.message),null}if(utilities.isFunction(format.formatter))if(options.throwErrors)formattedValue=format.formatter(formattedValue,format,options);else try{formattedValue=format.formatter(formattedValue,format,options)}catch(error){return options.verbose&&console.error(error.message),null}return formattedValue},utilities.formatObject=function(object,format,removeExtra,throwErrors){if(!(utilities.isObjectStrict(object)||utilities.isObjectStrict(removeExtra)&&utilities.isFunction(removeExtra.parser)))return{};var options=null;options=utilities.isObjectStrict(removeExtra)?{throwErrors:utilities.parseBoolean(removeExtra.throwErrors,utilities.parseBoolean(throwErrors,!1)),verbose:utilities.parseBoolean(removeExtra.verbose,!1)}:{throwErrors:utilities.parseBoolean(throwErrors,!1),verbose:!1};var subFormat={type:"object",strict:!1,autopopulate:!!utilities.isObjectStrict(removeExtra)&&utilities.parseBoolean(removeExtra.autopopulate,!1),order:!!utilities.isObjectStrict(removeExtra)&&utilities.parseBoolean(removeExtra.order,!1),removeExtra:utilities.isObjectStrict(removeExtra)?utilities.parseBoolean(removeExtra.removeExtra,utilities.parseBoolean(removeExtra,!1)):utilities.parseBoolean(removeExtra,!1),nullable:!0,required:!1,format:format};utilities.isObjectStrict(removeExtra)&&(utilities.isFunction(removeExtra.parser)&&(subFormat.parser=removeExtra.parser),utilities.isFunction(removeExtra.validator)&&(subFormat.validator=removeExtra.validator),utilities.isFunction(removeExtra.formatter)&&(subFormat.formatter=removeExtra.formatter));var formattedObject=null;if(options.throwErrors)formattedObject=utilities.formatValue(object,subFormat,options);else{var subOptions=utilities.clone(options);subOptions.throwErrors=!0;try{formattedObject=utilities.formatValue(object,subFormat,subOptions)}catch(error){return options.verbose&&console.error(error.message),null}}return utilities.isObjectStrict(formattedObject)||utilities.isObjectStrict(removeExtra)&&utilities.isFunction(removeExtra.parser)?formattedObject:{}},utilities.formatStringList=function(value,stringify){var data=null;if(utilities.isNonEmptyString(value))data=utilities.parseStringList(value);else{if(!utilities.isNonEmptyArray(value))return"string"==typeof value||Array.isArray(value)?"":null;data=value}var formattedList="",formattedValue=null;stringify=utilities.parseBoolean(stringify);for(var i=0;i<data.length;i++){if("string"!=typeof data[i]){if(null===stringify)continue;formattedValue=stringify?utilities.toString(data[i]):data[i]}else formattedValue=data[i].trim();0!==formattedValue.length&&(0<formattedList.length&&(formattedList+=", "),formattedList+=formattedValue)}return formattedList},utilities.leftShift=function(number,bits){return Number.isInteger(number)&&Number.isInteger(bits)?number*Math.pow(2,bits):NaN},utilities.rightShift=function(number,bits){return Number.isInteger(number)&&Number.isInteger(bits)?number/Math.pow(2,bits):NaN},utilities.trimString=function(value,defaultValue){return"string"==typeof value?value.trim():void 0===defaultValue?null:defaultValue},utilities.trimNullTerminatedString=function(value,defaultValue){if("string"!=typeof value)return void 0===defaultValue?null:defaultValue;var nullTerminatorIndex=value.indexOf("\0");return 0<=nullTerminatorIndex?value.substr(0,nullTerminatorIndex):value},utilities.trimWhitespace=function(value,trimNewlines){if("string"!=typeof value)return null;var trimmedString=value.replace(/^[ \t]+|[ \t]+$/gm,"");return utilities.parseBoolean(trimNewlines,!1)&&(trimmedString=trimmedString.replace(/\r\n?|\n/g,"")),trimmedString},utilities.trimTrailingNewlines=function(value){return"string"!=typeof value?null:utilities.isEmptyString(value)?value:value.replace(/[ \t\r\n]+$/,"")},utilities.replaceNonBreakingSpaces=function(value){return"string"==typeof value?value.replace(/ /gi," "):null},utilities.indentText=function(value,amount,indentation,clearEmptyLines){if("string"!=typeof value)return null;clearEmptyLines=utilities.parseBoolean(clearEmptyLines,!0),(amount=utilities.parseInteger(amount,1))<0&&(amount=0),indentation="string"==typeof indentation?indentation:"\t";for(var totalIndentation="",i=0;i<amount;i++)totalIndentation+=indentation;var line=null,lines=value.split(/\r\n?|\n/g),indentedParagraph="";for(i=0;i<lines.length;i++)line=lines[i],indentedParagraph+=(utilities.isEmptyString(line)&&clearEmptyLines?"":totalIndentation+line)+(i<lines.length-1?"\n":"");return indentedParagraph},utilities.trimLeadingZeroes=function(value){if("string"!=typeof value)return null;if(0===value.length)return value;var formattedValue=value.trim();return 0===formattedValue.length?formattedValue:formattedValue.match(/^[0]+$/)?"0":formattedValue.replace(/^0+/,"")},utilities.addLeadingZeroes=function(value,expectedLength){if(utilities.isInvalid(value))return null;if(value=value.toString(),expectedLength=utilities.parseInteger(expectedLength),utilities.isInvalidNumber(expectedLength)||expectedLength<0)return value;for(var numberOfZeroes=expectedLength-value.length,i=0;i<numberOfZeroes;i++)value="0"+value;return value},utilities.toString=function(value){if(void 0===value)return"undefined";if(null===value)return"null";if("string"==typeof value)return value;if(value===1/0)return"Infinity";if(value===-1/0)return"-Infinity";if("number"==typeof value&&isNaN(value))return"NaN";if(utilities.isDate(value))return value.toString();if(utilities.isRegularExpression(value)){var flags="";for(var flag in regExpFlags)value[flag]&&(flags+=regExpFlags[flag]);return"/"+value.source+"/"+flags}if(utilities.isFunction(value))return value.toString();if(utilities.isError(value)){var error={message:value.message};for(var attribute in value)error[attribute]=value[attribute];return JSON.stringify(error)}return JSON.stringify(value)},utilities.compareDates=function(a,b){return a=utilities.parseDate(a),b=utilities.parseDate(b),null===a&&null===b?0:null===a?-1:null===b?1:a.getTime()-b.getTime()},utilities.compareCasePercentage=function(value){if(utilities.isEmptyString(value))return 0;for(var c=null,upper=0,lower=0,lowerA="a".charCodeAt(),lowerZ="z".charCodeAt(),upperA="A".charCodeAt(),upperZ="Z".charCodeAt(),i=0;i<value.length;i++)lowerA<=(c=value.charCodeAt(i))&&c<=lowerZ?lower++:upperA<=c&&c<=upperZ&&upper++;return upper-lower},utilities.reverseString=function(value){if("string"!=typeof value)return null;for(var reverse="",i=(value=value.replace(/([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g,function($0,$1,$2){return utilities.reverseString($2)+$1}).replace(/([\uD800-\uDBFF])([\uDC00-\uDFFF])/g,"$2$1")).length-1;0<=i;i--)reverse+=value[i];return reverse},utilities.createError=function(message,status){var error=new Error(message);return error.status=utilities.parseInteger(status,500),error},utilities.clone=function(value){if(!utilities.isObject(value))return value;if(value instanceof Boolean)return new Boolean(value.valueOf());if(value instanceof Date)return(copy=new Date).setTime(value.getTime()),copy;if(value instanceof Array){for(var copy=[],i=0,length=value.length;i<length;i++)copy[i]=utilities.clone(value[i]);return copy}if(value instanceof Set)return new Set(value);if(value instanceof Map)return new Map(value);if(value instanceof RegExp){var flags="";for(var flag in regExpFlags)value[flag]&&(flags+=regExpFlags[flag]);return new RegExp(value.source,flags)}if("undefined"!=typeof Buffer&&value instanceof Buffer)return Buffer.from instanceof Function?Buffer.from(value):new Buffer(value);if(value instanceof Object){copy=null;if(value instanceof Error){(copy=new Error(value.message)).stack=utilities.clone(value.stack);var properties=Object.keys(value);for(i=0;i<properties.length;i++)copy[properties[i]]=utilities.clone(value[properties[i]])}else copy={};for(var attribute in value)Object.prototype.hasOwnProperty.call(value,attribute)&&(copy[attribute]=utilities.clone(value[attribute]));return copy}return value},utilities.merge=function(a,b,copy,deepMerge){if(!utilities.isObject(a)||Array.isArray(a))return null;var newObject=null;if(newObject=(copy=utilities.parseBoolean(copy,!0))?utilities.clone(a):a,!utilities.isObject(a)||Array.isArray(a)||!utilities.isObject(b)||Array.isArray(b))return newObject;var attribute=null,value=null,newValue=null,attributes=Object.keys(b);deepMerge=utilities.parseBoolean(deepMerge,!0);for(var i=0;i<attributes.length;i++)value=newObject[attribute=attributes[i]],newValue=copy?utilities.clone(b[attribute]):b[attribute],deepMerge&&utilities.isObject(value)&&!Array.isArray(value)&&utilities.isObject(newValue)&&!Array.isArray(newValue)?newObject[attribute]=utilities.merge(value,newValue):newObject[attribute]=newValue;return newObject},utilities.getFileName=function(filePath){if("string"!=typeof filePath)return null;for(var i=(filePath=filePath.trim()).length-1;0<=i;i--)if("/"===filePath[i]||"\\"===filePath[i])return filePath.substring(i+1,filePath.length).trim();return filePath},utilities.getFilePath=function(filePath){if("string"!=typeof filePath)return null;for(var i=(filePath=filePath.trim()).length-1;0<=i;i--)if("/"===filePath[i]||"\\"===filePath[i])return filePath.substring(0,i).trim();return""},utilities.getFileNameNoExtension=function(fileName){if("string"!=typeof fileName)return null;for(var i=(fileName=utilities.getFileName(fileName)).length-1;0<=i;i--)if("."===fileName[i])return fileName.substring(0,i).trim();return fileName},utilities.getFileExtension=function(fileName){if("string"!=typeof fileName)return null;for(var i=(fileName=utilities.getFileName(fileName)).length-1;0<=i;i--)if("."===fileName[i])return fileName.substring(i+1,fileName.length).trim();return""},utilities.fileHasExtension=function(fileName,extension){if(utilities.isEmptyString(fileName)||utilities.isEmptyString(extension))return!1;var actualFileExtension=utilities.getFileExtension(fileName);return!utilities.isEmptyString(actualFileExtension)&&actualFileExtension.toLowerCase()===extension.trim().toLowerCase()},utilities.reverseFileExtension=function(fileName){if("string"!=typeof fileName)return null;for(var i=(fileName=fileName.trim()).length-1;0<=i;i--)if("."===fileName[i])return fileName.substring(0,i)+"."+utilities.reverseString(fileName.substring(i+1,fileName.length));return fileName},utilities.truncateFileName=function(fileName,maxLength){if("string"!=typeof fileName)return null;if(fileName=utilities.getFileName(fileName),utilities.isEmptyString(fileName))return"";if(maxLength=utilities.parseInteger(maxLength),utilities.isInvalidNumber(maxLength)||maxLength<0)return fileName;if(0===maxLength)return"";if(fileName.length<=maxLength)return fileName;for(var extension="",originalFileName=fileName,i=fileName.length-1;0<=i;i--)if("."===fileName[i]){extension=fileName.substring(i+1,fileName.length),originalFileName=fileName.substring(0,i);break}return maxLength-(extension.length+(0<extension.length?1:0))<1?originalFileName.substring(0,maxLength):originalFileName.substring(0,maxLength-extension.length-(0<extension.length?1:0))+(0<extension.length?"."+extension:"")},utilities.prependSlash=function(value){if("string"!=typeof value)return null;var formattedValue=value.trim();return 0===formattedValue.length||"/"!==formattedValue[0]&&"\\"!==formattedValue[0]&&(formattedValue="/"+formattedValue),formattedValue},utilities.appendSlash=function(value){if("string"!=typeof value)return null;var formattedValue=value.trim();return 0===formattedValue.length||"/"!==formattedValue[formattedValue.length-1]&&"\\"!==formattedValue[formattedValue.length-1]&&(formattedValue+="/"),formattedValue},utilities.joinPaths=function(base,path){var formattedBase="string"==typeof base?base.trim().replace(/[\/\\]+$/,""):null,formattedPath="string"==typeof path?path.trim().replace(/^[\/\\]+/,""):null,newPath="";return utilities.isNonEmptyString(formattedBase)&&(newPath+=formattedBase,utilities.isNonEmptyString(formattedPath)&&(newPath+="/")),utilities.isNonEmptyString(formattedPath)&&(newPath+=formattedPath),newPath},utilities.createQueryString=function(value,includeQuestionMark){if(!utilities.isObjectStrict(value))return"";var parameters=Object.keys(value).map(function(key){return encodeURIComponent(key)+"="+encodeURIComponent(utilities.toString(value[key]))}).join("&");return 0===parameters.length?"":(utilities.parseBoolean(includeQuestionMark,!1)?"?":"")+parameters},utilities.createRange=function(start,end){var formattedStart=utilities.parseInteger(start),formattedEnd=utilities.parseInteger(end);if(1===arguments.length&&(formattedEnd=formattedStart,formattedStart=0),utilities.isInvalidNumber(formattedStart)||utilities.isInvalidNumber(formattedEnd)||formattedEnd<formattedStart)return[];for(var range=[],i=formattedStart;i<=formattedEnd;i++)range.push(i);return range},utilities.futureMonths=function(date,prependZero){if(null===(date=utilities.parseDate(date)))return null;var currentDate=new Date,month=0;date.getFullYear()===currentDate.getFullYear()&&(month=currentDate.getMonth());var months=[];prependZero=utilities.parseBoolean(prependZero,!1);for(var i=0;i<12;i++)month<=i&&(prependZero?months.push((i<=8?"0":"")+(i+1)):months.push(i+1));return months},utilities.visibleElements=function(elements){if(!Array.isArray(elements))return[];for(var visibleElements=[],i=0;i<elements.length;i++)utilities.isVisible(elements[i])&&visibleElements.push(elements[i]);return visibleElements},utilities.hiddenElements=function(elements){if(!Array.isArray(elements))return[];for(var hiddenElements=[],i=0;i<elements.length;i++)utilities.isHidden(elements[i])&&hiddenElements.push(elements[i]);return hiddenElements},utilities.enabledElements=function(elements){if(!Array.isArray(elements))return[];for(var enabledElements=[],i=0;i<elements.length;i++)utilities.isEnabled(elements[i])&&enabledElements.push(elements[i]);return enabledElements},utilities.disabledElements=function(elements){if(!Array.isArray(elements))return[];for(var disabledElements=[],i=0;i<elements.length;i++)utilities.isDisabled(elements[i])&&disabledElements.push(elements[i]);return disabledElements},utilities.elementsWithAttribute=function(elements,attribute,hasAttribute){if(!Array.isArray(elements)||utilities.isEmptyString(attribute))return[];var element=null,filteredElements=[];attribute=attribute.trim(),hasAttribute=utilities.parseBoolean(hasAttribute,!0);for(var i=0;i<elements.length;i++)element=elements[i],utilities.isObject(element)&&(utilities.isInvalid(elements[i][attribute])?hasAttribute||filteredElements.push(element):hasAttribute&&filteredElements.push(elements[i]));return filteredElements},utilities.elementsWithoutAttribute=function(elements,attribute){return utilities.elementsWithAttribute(elements,attribute,!1)},utilities.matchAttribute=function(element,attribute,value){return!!utilities.isObject(element)&&(!!utilities.isEmptyString(attribute)||element[attribute.trim()]===value)},utilities.generateVersions=function(version,prefix,suffix){if(null===(version=utilities.parseVersion(version)))return null;prefix=utilities.trimString(prefix),suffix=utilities.trimString(suffix);for(var versions=[],value=null,i=0;i<version.length;i++){value="",utilities.isNonEmptyString(prefix)&&(value+=prefix);for(var j=0;j<=i;j++)0<j&&(value+="_"),value+=version[j];utilities.isNonEmptyString(suffix)&&(value+=suffix),versions.push(value)}return versions},utilities.parseVersion=function(value,trimTrailingZeroes){var formattedValue=utilities.isValidNumber(value)?value.toString():value;if("string"!=typeof formattedValue)return null;var version=[],versionData=formattedValue.match(/[^. \t]+/g);if(null===versionData||0===versionData.length)return null;for(var part=null,i=0;i<versionData.length;i++)if(validator.isInt(versionData[i])){if(part=utilities.parseInteger(versionData[i]),utilities.isInvalidNumber(part)||part<0)continue;version.push(part.toString())}else version.push(versionData[i]);if(utilities.parseBoolean(trimTrailingZeroes,!1))for(;!(version.length<=1)&&"0"===version[version.length-1];)version.pop();return 0===version.length?null:version},utilities.compareVersions=function(v1,v2,caseSensitive,throwErrors){if(caseSensitive=utilities.parseBoolean(caseSensitive,!1),throwErrors=utilities.parseBoolean(throwErrors,!1),null===(v1=utilities.parseVersion(v1))){if(throwErrors)throw new Error("Cannot compare invalid or empty first version.");return null}if(null===(v2=utilities.parseVersion(v2))){if(throwErrors)throw new Error("Cannot compare invalid or empty second version.");return null}for(var index=0;;){if(index>=v1.length){if(v1.length===v2.length)return 0;for(var i=index;i<v2.length;i++)if("0"!==v2[i])return-1;return 0}if(index>=v2.length){for(i=index;i<v1.length;i++)if("0"!==v1[i])return 1;return 0}var formattedA=utilities.parseInteger(v1[index]),formattedB=utilities.parseInteger(v2[index]);if(utilities.isInvalidNumber(formattedA)&&(formattedA=caseSensitive?v1[index]:v1[index].toUpperCase()),utilities.isInvalidNumber(formattedB)&&(formattedB=caseSensitive?v2[index]:v2[index].toUpperCase()),Number.isInteger(formattedA)){if(!Number.isInteger(formattedB))return-1}else if(Number.isInteger(formattedB))return 1;if(formattedB<formattedA)return 1;if(formattedA<formattedB)return-1;index++}},utilities}); | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.utilities=factory()}(this,function(){"use strict";"undefined"!=typeof require&&("undefined"==typeof validator&&(global.validator=require("validator")),"undefined"==typeof changeCase&&(global.changeCase=require("change-case-bundled")));var utilities={},regExpFlags={global:"g",multiline:"m",ignoreCase:"i",sticky:"y",unicode:"u"},formatTypes=["boolean","bool","integer","int","float","number","string","object","array","date","regex","regexp","regularexpression","function","func"],stringCaseFunctions={camel:changeCase.camelCase,capital:changeCase.capitalCase,constant:changeCase.constantCase,dot:changeCase.dotCase,header:changeCase.headerCase,lower:changeCase.lowerCase,lowerFirst:changeCase.lowerCaseFirst,no:changeCase.noCase,param:changeCase.paramCase,pascal:changeCase.pascalCase,path:changeCase.pathCase,sentence:changeCase.sentenceCase,snake:changeCase.snakeCase,sponge:changeCase.spongeCase,swap:changeCase.swapCase,title:changeCase.titleCase,upper:changeCase.upperCase,upperFirst:changeCase.upperCaseFirst};return utilities.isValid=function(value){return null!=value},utilities.isInvalid=function(value){return null==value},utilities.isBoolean=function(value,allowObjects){return!0===value||!1===value||!!allowObjects&&value instanceof Boolean},utilities.isValidNumber=function(value){return"number"==typeof value&&!isNaN(value)&&value!==-1/0&&value!==1/0},utilities.isInvalidNumber=function(value){return"number"!=typeof value||isNaN(value)||value===-1/0||value===1/0},utilities.isEmptyString=function(value,trim){return"string"!=typeof value||(utilities.parseBoolean(trim,!0)?0===value.trim().length:0===value.length)},utilities.isNonEmptyString=function(value,trim){return"string"==typeof value&&(utilities.parseBoolean(trim,!0)?0!==value.trim().length:0!==value.length)},utilities.isObject=function(value,strict){return void 0!==value&&(strict?null!==value&&value.constructor===Object:value instanceof Object&&!(value instanceof Function))},utilities.isObjectStrict=function(value){return null!=value&&value.constructor===Object},utilities.isEmptyObject=function(value){return null!=value&&value.constructor===Object&&0===Object.keys(value).length},utilities.isNonEmptyObject=function(value){return null!=value&&value.constructor===Object&&0!==Object.keys(value).length},utilities.isEmptyArray=function(value){return!Array.isArray(value)||0===value.length},utilities.isNonEmptyArray=function(value){return Array.isArray(value)&&0!==value.length},utilities.isDate=function(value){return value instanceof Date},utilities.isError=function(value){return value instanceof Error},utilities.isRegularExpression=function(value){return value instanceof RegExp},utilities.isFunction=function(value){return value instanceof Function},utilities.isComment=function(value,comment){if(utilities.isEmptyString(value))return!1;utilities.isEmptyString(comment)&&(comment="//");for(var commentStartIndex=-1,i=0;i<value.length;i++)if(" "!==value[i]&&"\t"!=value[i]){if(value[i]!=comment[0])return!1;commentStartIndex=i;break}if(commentStartIndex<0||value.length-commentStartIndex<comment.length)return!1;for(i=commentStartIndex;i<value.length&&!(i-commentStartIndex>=comment.length);i++)if(value[i]!=comment[i-commentStartIndex])return!1;return!0},utilities.isVisible=function(element){return!!utilities.isObject(element)&&(utilities.isBoolean(element.visible)?element.visible:utilities.isFunction(element.visible)?element.visible():utilities.isBoolean(element.hidden)?!element.hidden:!utilities.isFunction(element.hidden)||!element.hidden())},utilities.isHidden=function(element){return!utilities.isObject(element)||(utilities.isBoolean(element.visible)?!element.visible:utilities.isFunction(element.visible)?!element.visible():utilities.isBoolean(element.hidden)?element.hidden:!!utilities.isFunction(element.hidden)&&element.hidden())},utilities.isEnabled=function(element){return!!utilities.isObject(element)&&(utilities.isBoolean(element.enabled)?element.enabled:utilities.isFunction(element.enabled)?element.enabled():utilities.isBoolean(element.disabled)?!element.disabled:!utilities.isFunction(element.disabled)||!element.disabled())},utilities.isDisabled=function(element){return!utilities.isObject(element)||(utilities.isBoolean(element.enabled)?!element.enabled:utilities.isFunction(element.enabled)?!element.enabled():utilities.isBoolean(element.disabled)?element.disabled:!!utilities.isFunction(element.disabled)&&element.disabled())},utilities.equalsIgnoreCase=function(stringA,stringB){return"string"==typeof stringA&&"string"==typeof stringB&&0===stringA.localeCompare(stringB,void 0,{sensitivity:"accent"})},utilities.parseBoolean=function(value,defaultValue){if(utilities.isBoolean(value))return value;if(utilities.isBoolean(value,!0))return value.valueOf();if(utilities.isBoolean(defaultValue)||(defaultValue=null),utilities.isInvalid(value))return defaultValue;if(0===value)return!1;if(1===value)return!0;if("string"!=typeof value)return defaultValue;var formattedValue=value.trim().toLowerCase();if(0===formattedValue.length)return defaultValue;if(1!==formattedValue.length)return"true"===formattedValue||"yes"===formattedValue||"on"===formattedValue||"false"!==formattedValue&&"no"!==formattedValue&&"off"!==formattedValue&&defaultValue;var character=formattedValue.charAt(0);return"t"===character||"y"===character||"f"!==character&&"n"!==character&&("0"!==character&&("1"===character||defaultValue))},utilities.parseInteger=function(value,defaultValue){var newValue=NaN;return("number"==typeof value||"string"==typeof value&&validator.isFloat(value))&&(newValue=parseInt(value)),utilities.isInvalidNumber(newValue)?(defaultValue=parseInt(defaultValue),utilities.isValidNumber(defaultValue)?defaultValue:NaN):newValue},utilities.parseFloatingPointNumber=function(value,defaultValue){var newValue=NaN;return"number"==typeof value?newValue=value:"string"==typeof value&&validator.isFloat(value)&&(newValue=parseFloat(value)),utilities.isInvalidNumber(newValue)?utilities.isValidNumber(defaultValue)?defaultValue:NaN:newValue},utilities.parseDate=function(value,defaultValue){if(utilities.isDate(defaultValue)||(defaultValue=null),"number"==typeof value)return utilities.isInvalidNumber(value)||!Number.isInteger(value)?defaultValue:new Date(parseInt(value));if("string"!=typeof value)return value instanceof Date?value:defaultValue;var formattedValue=value.trim();if(0===formattedValue.length)return defaultValue;var timestamp=null;return timestamp=validator.isInt(formattedValue)?parseInt(formattedValue):Date.parse(formattedValue),utilities.isInvalidNumber(timestamp)?defaultValue:new Date(timestamp)},utilities.parseTime=function(value,throwErrors){if(throwErrors=utilities.parseBoolean(throwErrors),utilities.isEmptyString(value)){if(throwErrors)throw new Error("Invalid or empty time value.");return null}var formattedValue=value.trim(),hour=null,minutes=null,regularTime=formattedValue.match(/^[ \t]*(([2-9]|[1][0-2]?)(:([0-5][0-9]))?[ \t]*([ap]m))[ \t]*$/i);if(regularTime){var regularHour=utilities.parseInteger(utilities.trimLeadingZeroes(regularTime[2]));if(utilities.isInvalidNumber(regularHour)){if(throwErrors)throw new Error('Invalid regular hour: "'+regularTime[2]+'".');return null}minutes=utilities.parseInteger(utilities.trimLeadingZeroes(regularTime[4])),utilities.isInvalidNumber(minutes)&&(minutes=0);var morning="AM"===(period=regularTime[5].toUpperCase())||"PM"!==period&&null;if(null===morning){if(throwErrors)throw new Error('Invalid period: "'+regularTime[5]+'".');return null}24===(hour=morning?regularHour+(12===regularHour?12:0):regularHour+(12===regularHour?0:12))&&(hour=0)}else{var militaryTime=formattedValue.match(/^[ \t]*(((([0-1][0-9])|(2[0-3])):?([0-5][0-9]))|((24):?(00)))[ \t]*$/i);if(!militaryTime){if(throwErrors)throw new Error('Invalid time: "'+formattedValue+'".');return null}var militaryHour=militaryTime[3],militaryMinutes=militaryTime[6];if((utilities.isInvalid(militaryHour)||utilities.isInvalid(militaryMinutes))&&(militaryHour=militaryTime[8],utilities.isNonEmptyString(militaryTime[9])&&(militaryMinutes=militaryTime[9])),utilities.isInvalid(militaryHour)||utilities.isInvalid(militaryMinutes)){if(throwErrors)throw new Error('Invalid military time: "'+formattedValue+'".');return null}if(hour=utilities.parseInteger(utilities.trimLeadingZeroes(militaryHour)),utilities.isInvalidNumber(hour)){if(throwErrors)throw new Error('Invalid military time hour: "'+militaryHour+'".');return null}if(minutes=utilities.parseInteger(utilities.trimLeadingZeroes(militaryMinutes)),utilities.isInvalidNumber(minutes)){if(throwErrors)throw new Error('Invalid military time minutes: "'+militaryMinutes+'".');return null}24===hour&&0===minutes&&(hour=0)}if(hour<0||23<hour){if(throwErrors)throw new Error('Time hour is out of range (0 - 23): "'+hour+'".');return null}if(minutes<0||59<minutes){if(throwErrors)throw new Error('Time minutes is out of range (0 - 59): "'+minutes+'".');return null}var period=hour<12?"AM":"PM";return{regular:{raw:(regularHour=0===hour?12:hour<=12?hour:hour-12)+":"+utilities.addLeadingZeroes(minutes,2)+" "+period,hour:regularHour,minutes:minutes,period:period,morning:hour<12},military:{raw:utilities.addLeadingZeroes(hour,2)+utilities.addLeadingZeroes(minutes,2),hour:hour,minutes:minutes}}},utilities.parseEmail=function(value){if(utilities.isEmptyString(value))return null;var emailData=value.trim().toLowerCase().match(/([^+@]+)(\+.*)?(@.+\..+)/);return utilities.isInvalid(emailData)||emailData.length<4?null:emailData[1]+emailData[3]},utilities.parseEmailDomain=function(value){if(utilities.isEmptyString(value))return null;var emailDomainData=value.trim().toLowerCase().match(/([^+@]+)(\+.*)?@(.+\..+)/);return utilities.isInvalid(emailDomainData)||emailDomainData.length<4?null:emailDomainData[3]},utilities.parseStringList=function(value){if("string"!=typeof value)return null;if(0===value.length)return[];for(var data=value.split(/[;,]+/),formattedList=[],formattedValue=null,i=0;i<data.length;i++)0!==(formattedValue=data[i].trim()).length&&formattedList.push(formattedValue);return formattedList},utilities.parseRegularExpression=function(value,throwErrors){if(throwErrors=utilities.parseBoolean(throwErrors,!1),utilities.isRegularExpression(value))return value;if(utilities.isEmptyString(value)){if(throwErrors)throw new Error("Regular expression cannot be empty.");return null}var regExpData=value.match(/\s*\/(.*)\/(.*)\s*/);if(!regExpData){if(throwErrors)throw new Error("Invalid regular expression value.");return null}if(throwErrors)return new RegExp(regExpData[1],regExpData[2]);try{return new RegExp(regExpData[1],regExpData[2])}catch(error){return null}},utilities.parseYouTubeLink=function(value){if(utilities.isEmptyString(value))return null;var formattedValue=value.trim(),linkData=formattedValue.match(/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/i);return linkData&&11<=linkData[1].length?linkData[1]:formattedValue.match(/[A-Z0-9_-]{11,}/i)?formattedValue:null},utilities.formatValue=function(value,format,options){if(utilities.isObjectStrict(options)?(options={throwErrors:utilities.parseBoolean(options.throwErrors,!1)}).verbose=utilities.parseBoolean(options.verbose,!options.throwErrors):options={throwErrors:!1,verbose:!0},!utilities.isObjectStrict(format))return utilities.clone(value);format=utilities.clone(format);var errorMessage=null;if(utilities.isEmptyString(format.type))errorMessage="Invalid required type format value - expected non-empty string.";else{var originalType=format.type;format.type=format.type.trim().toLowerCase();for(var validFormatType=!1,i=0;i<formatTypes.length;i++)if(format.type===formatTypes[i]){validFormatType=!0;break}if(validFormatType){if("bool"===format.type)format.type="boolean";else if("int"===format.type)format.type="integer";else if("number"===format.type)format.type="float";else if("string"===format.type){if(void 0!==format.trim){var originalTrim=format.trim;format.trim=utilities.parseBoolean(format.trim),null===format.trim&&(errorMessage='Invalid optional trim string format value - expected boolean, received "'+utilities.toString(originalTrim)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.case)if(utilities.isEmptyString(format.case))errorMessage="Invalid optional string case format value - expected non-empty string.";else{var originalCase=format.case;format.case=changeCase.camelCase(format.case.trim()),utilities.isFunction(stringCaseFunctions[format.case])||(errorMessage="Invalid optional case format value - expected one of "+Object.keys(stringCaseFunctions).join(", ")+', received "'+utilities.toString(originalCase)+'".')}}else if("object"===format.type){if(void 0!==format.strict){var originalStrict=format.strict;format.strict=utilities.parseBoolean(format.strict),null===format.strict&&(errorMessage='Invalid optional strict object format value - expected boolean, received "'+utilities.toString(originalStrict)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.autopopulate){var originalAutopopulate=format.autopopulate;format.autopopulate=utilities.parseBoolean(format.autopopulate),null===format.autopopulate&&(errorMessage='Invalid optional autopopulate object format value - expected boolean, received "'+utilities.toString(originalAutopopulate)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.order){var originalOrder=format.order;format.order=utilities.parseBoolean(format.order),null===format.order&&(errorMessage='Invalid optional order object format value - expected boolean, received "'+utilities.toString(originalOrder)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.removeExtra){var originalRemoveExtra=format.removeExtra;format.removeExtra=utilities.parseBoolean(format.removeExtra),null===format.removeExtra&&(errorMessage='Invalid optional removeExtra object format value - expected boolean, received "'+utilities.toString(originalRemoveExtra)+'".')}}else"regexp"===format.type||"regularexpression"===format.type?format.type="regex":"func"===format.type&&(format.type="function");if(utilities.isInvalid(errorMessage)&&("object"!==format.type&&"array"!==format.type||void 0===format.format||utilities.isObjectStrict(format.format)||(errorMessage='Invalid optional format format value - expected object, received "'+utilities.toString(format.format)+'".')),utilities.isInvalid(errorMessage)&&("string"===format.type||"object"===format.type||"array"===format.type)&&void 0!==format.nonEmpty){var originalNonEmpty=format.nonEmpty;format.nonEmpty=utilities.parseBoolean(format.nonEmpty),null===format.nonEmpty&&(errorMessage='Invalid optional nonEmpty format value - expected boolean, received "'+utilities.toString(originalNonEmpty)+'".')}}else errorMessage="Invalid required type format value - expected one of "+formatTypes.join(", ")+', received "'+utilities.toString(originalType)+'".'}if(utilities.isInvalid(errorMessage)&&void 0!==format.nullable){var originalNullable=format.nullable;format.nullable=utilities.parseBoolean(format.nullable),null===format.nullable&&(errorMessage='Invalid optional nullable format value - expected boolean, received "'+utilities.toString(originalNullable)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.required){var originalRequired=format.required;format.required=utilities.parseBoolean(format.required),null===format.required&&(errorMessage='Invalid optional required format value - expected boolean, received "'+utilities.toString(originalRequired)+'".')}if(utilities.isInvalid(errorMessage)&&void 0!==format.parser&&(utilities.isFunction(format.parser)||(errorMessage='Invalid optional parser format value - expected function, received "'+utilities.toString(format.parser)+'".')),utilities.isInvalid(errorMessage)&&void 0!==format.validator&&(utilities.isFunction(format.validator)||(errorMessage='Invalid optional validator format value - expected function, received "'+utilities.toString(format.validator)+'".')),utilities.isInvalid(errorMessage)&&void 0!==format.formatter&&(utilities.isFunction(format.formatter)||(errorMessage='Invalid optional formatter format value - expected function, received "'+utilities.toString(format.formatter)+'".')),utilities.isValid(errorMessage)){if(options.throwErrors)throw new Error(errorMessage);return options.verbose&&console.error(errorMessage),null}if(utilities.isFunction(format.parser))if(options.throwErrors)value=format.parser(value,format,options);else try{value=format.parser(value,format,options)}catch(error){return options.verbose&&console.error(error.message),null}var formattedValue=void 0;if(void 0===value)formattedValue=utilities.clone(format.default);else if(null===value)format.nullable?formattedValue=null:void 0!==format.default?formattedValue=utilities.clone(format.default):errorMessage="Value cannot be null!";else if("boolean"===format.type)null===(formattedValue=utilities.parseBoolean(value))&&(errorMessage='Invalid boolean value: "'+utilities.toString(value)+'".');else if("integer"===format.type)formattedValue=utilities.parseInteger(value),utilities.isInvalidNumber(formattedValue)&&(errorMessage='Invalid integer value: "'+utilities.toString(value)+'".');else if("float"===format.type)formattedValue=utilities.parseFloatingPointNumber(value),utilities.isInvalidNumber(formattedValue)&&(errorMessage='Invalid float value: "'+utilities.toString(value)+'".');else if("string"===format.type){if(formattedValue="string"==typeof value?value:utilities.toString(value),format.trim&&(formattedValue=formattedValue.trim()),void 0!==format.case&&(formattedValue=stringCaseFunctions[format.case](formattedValue)),format.nonEmpty&&0===formattedValue.length){var message="String value cannot be empty.";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}}else if("array"===format.type){if("string"==typeof value)try{formattedValue=JSON.parse(value),Array.isArray(formattedValue)||(errorMessage='Invalid stringified array value type - expected array: "'+utilities.toString(value)+'".')}catch(error){errorMessage='Invalid stringified array value: "'+utilities.toString(value)+'".'}else Array.isArray(value)?formattedValue=utilities.clone(value):errorMessage='Invalid value type - expected array or stringified array: "'+utilities.toString(value)+'".';if(utilities.isInvalid(errorMessage)&&Array.isArray(formattedValue)){var formattedArray=[];if(utilities.isObjectStrict(format.format)){var formattedElement=null;for(i=0;i<formattedValue.length;i++)if(void 0!==formattedValue[i]){if(options.throwErrors)formattedElement=utilities.formatValue(formattedValue[i],format.format,options);else{(subOptions=utilities.clone(options)).throwErrors=!0;try{formattedElement=utilities.formatValue(formattedValue[i],format.format,subOptions)}catch(error){return options.verbose&&console.error(error.message),null}}formattedArray.push(formattedElement)}}else for(i=0;i<formattedValue.length;i++)void 0!==formattedValue[i]&&formattedArray.push(utilities.clone(formattedValue[i]));if(formattedValue=formattedArray,format.nonEmpty&&0===formattedValue.length){message="Array value cannot be empty.";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}}}else if("date"===format.type)formattedValue=utilities.parseDate(value),utilities.isDate(formattedValue)||(errorMessage='Invalid date value: "'+utilities.toString(value)+'".');else if("regex"===format.type){if(utilities.isRegularExpression(value))formattedValue=utilities.clone(value);else if(options.throwErrors)formattedValue=utilities.parseRegularExpression(value,!0);else try{formattedValue=utilities.parseRegularExpression(value,!0)}catch(error){errorMessage=error.message}utilities.isInvalid(formattedValue)&&(errorMessage='Invalid regular expression value: "'+utilities.toString(value)+'".')}else"function"===format.type&&(formattedValue=value,utilities.isFunction(formattedValue)||(errorMessage='Invalid function value: "'+utilities.toString(value)+'".'));if(utilities.isInvalid(errorMessage)&&"object"===format.type){if(utilities.isValid(value))if("string"==typeof value)try{formattedValue=JSON.parse(value),utilities.isObject(formattedValue,format.strict)||(errorMessage="Invalid stringified object value type - expected "+(format.strict?"strict ":"")+'object: "'+utilities.toString(value)+'".')}catch(error){errorMessage='Invalid stringified object value: "'+utilities.toString(value)+'".'}else utilities.isObject(value,format.strict)?formattedValue=utilities.clone(value):errorMessage="Invalid value type - expected "+(format.strict?"strict ":"")+'object or stringified object: "'+utilities.toString(value)+'".';if(utilities.isInvalid(errorMessage)){if(utilities.isInvalid(formattedValue)&&format.autopopulate&&!utilities.isObject(formattedValue,format.strict)&&(formattedValue={}),utilities.isObjectStrict(format.format)&&utilities.isObject(formattedValue)){var attribute=null,attributes=Object.keys(format.format);for(i=0;i<attributes.length;i++)if(attribute=attributes[i],options.throwErrors){void 0!==(formattedAttribute=utilities.formatValue(formattedValue[attribute],format.format[attribute],options))&&(formattedValue[attribute]=formattedAttribute)}else{var subOptions;(subOptions=utilities.clone(options)).throwErrors=!0;try{var formattedAttribute;void 0!==(formattedAttribute=utilities.formatValue(formattedValue[attribute],format.format[attribute],subOptions))&&(formattedValue[attribute]=formattedAttribute)}catch(error){return options.verbose&&console.error(error.message),null}}if(format.removeExtra){var newValue={};attributes=Object.keys(formattedValue);for(i=0;i<attributes.length;i++)attribute=attributes[i],utilities.isValid(format.format[attribute])&&(newValue[attribute]=formattedValue[attribute]);formattedValue=newValue}if(format.order){var orderedObject={};attributes=Object.keys(format.format);for(i=0;i<attributes.length;i++)void 0!==formattedValue[attribute=attributes[i]]&&(orderedObject[attribute]=formattedValue[attribute],delete formattedValue[attribute]);var extraAttributes=Object.keys(formattedValue);for(i=0;i<extraAttributes.length;i++)orderedObject[attribute=extraAttributes[i]]=formattedValue[attribute];formattedValue=orderedObject}}if(format.nonEmpty&&utilities.isEmptyObject(formattedValue)){message="Object value must contain at least one attribute.";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}}}if(utilities.isValid(errorMessage)){if(options.throwErrors)throw new Error(errorMessage);return options.verbose&&console.error(errorMessage),null}if(void 0===formattedValue){if(format.required){message="Missing required value!";if(options.throwErrors)throw new Error(message);return options.verbose&&console.error(message),null}void 0!==format.default&&(formattedValue=utilities.clone(format.default))}if(utilities.isFunction(format.validator))if(options.throwErrors){if(!format.validator(formattedValue,format,options))throw new Error("Validation check failed!")}else try{if(!format.validator(formattedValue,format,options)){message="Validation check failed!";return options.verbose&&console.error(message),null}}catch(error){return options.verbose&&console.error(error.message),null}if(utilities.isFunction(format.formatter))if(options.throwErrors)formattedValue=format.formatter(formattedValue,format,options);else try{formattedValue=format.formatter(formattedValue,format,options)}catch(error){return options.verbose&&console.error(error.message),null}return formattedValue},utilities.formatObject=function(object,format,removeExtra,throwErrors){if(!(utilities.isObjectStrict(object)||utilities.isObjectStrict(removeExtra)&&utilities.isFunction(removeExtra.parser)))return{};var options=null;options=utilities.isObjectStrict(removeExtra)?{throwErrors:utilities.parseBoolean(removeExtra.throwErrors,utilities.parseBoolean(throwErrors,!1)),verbose:utilities.parseBoolean(removeExtra.verbose,!1)}:{throwErrors:utilities.parseBoolean(throwErrors,!1),verbose:!1};var subFormat={type:"object",strict:!1,autopopulate:!!utilities.isObjectStrict(removeExtra)&&utilities.parseBoolean(removeExtra.autopopulate,!1),order:!!utilities.isObjectStrict(removeExtra)&&utilities.parseBoolean(removeExtra.order,!1),removeExtra:utilities.isObjectStrict(removeExtra)?utilities.parseBoolean(removeExtra.removeExtra,utilities.parseBoolean(removeExtra,!1)):utilities.parseBoolean(removeExtra,!1),nullable:!0,required:!1,format:format};utilities.isObjectStrict(removeExtra)&&(utilities.isFunction(removeExtra.parser)&&(subFormat.parser=removeExtra.parser),utilities.isFunction(removeExtra.validator)&&(subFormat.validator=removeExtra.validator),utilities.isFunction(removeExtra.formatter)&&(subFormat.formatter=removeExtra.formatter));var formattedObject=null;if(options.throwErrors)formattedObject=utilities.formatValue(object,subFormat,options);else{var subOptions=utilities.clone(options);subOptions.throwErrors=!0;try{formattedObject=utilities.formatValue(object,subFormat,subOptions)}catch(error){return options.verbose&&console.error(error.message),null}}return utilities.isObjectStrict(formattedObject)||utilities.isObjectStrict(removeExtra)&&utilities.isFunction(removeExtra.parser)?formattedObject:{}},utilities.formatStringList=function(value,stringify){var data=null;if(utilities.isNonEmptyString(value))data=utilities.parseStringList(value);else{if(!utilities.isNonEmptyArray(value))return"string"==typeof value||Array.isArray(value)?"":null;data=value}var formattedList="",formattedValue=null;stringify=utilities.parseBoolean(stringify);for(var i=0;i<data.length;i++){if("string"!=typeof data[i]){if(null===stringify)continue;formattedValue=stringify?utilities.toString(data[i]):data[i]}else formattedValue=data[i].trim();0!==formattedValue.length&&(0<formattedList.length&&(formattedList+=", "),formattedList+=formattedValue)}return formattedList},utilities.leftShift=function(number,bits){return Number.isInteger(number)&&Number.isInteger(bits)?number*Math.pow(2,bits):NaN},utilities.rightShift=function(number,bits){return Number.isInteger(number)&&Number.isInteger(bits)?number/Math.pow(2,bits):NaN},utilities.trimString=function(value,defaultValue){return"string"==typeof value?value.trim():void 0===defaultValue?null:defaultValue},utilities.trimNullTerminatedString=function(value,defaultValue){if("string"!=typeof value)return void 0===defaultValue?null:defaultValue;var nullTerminatorIndex=value.indexOf("\0");return 0<=nullTerminatorIndex?value.substr(0,nullTerminatorIndex):value},utilities.trimWhitespace=function(value,trimNewlines){if("string"!=typeof value)return null;var trimmedString=value.replace(/^[ \t]+|[ \t]+$/gm,"");return utilities.parseBoolean(trimNewlines,!1)&&(trimmedString=trimmedString.replace(/\r\n?|\n/g,"")),trimmedString},utilities.trimTrailingNewlines=function(value){return"string"!=typeof value?null:utilities.isEmptyString(value)?value:value.replace(/[ \t\r\n]+$/,"")},utilities.replaceNonBreakingSpaces=function(value){return"string"==typeof value?value.replace(/ /gi," "):null},utilities.indentText=function(value,amount,indentation,clearEmptyLines){if("string"!=typeof value)return null;clearEmptyLines=utilities.parseBoolean(clearEmptyLines,!0),(amount=utilities.parseInteger(amount,1))<0&&(amount=0),indentation="string"==typeof indentation?indentation:"\t";for(var totalIndentation="",i=0;i<amount;i++)totalIndentation+=indentation;var line=null,lines=value.split(/\r\n?|\n/g),indentedParagraph="";for(i=0;i<lines.length;i++)line=lines[i],indentedParagraph+=(utilities.isEmptyString(line)&&clearEmptyLines?"":totalIndentation+line)+(i<lines.length-1?"\n":"");return indentedParagraph},utilities.trimLeadingZeroes=function(value){if("string"!=typeof value)return null;if(0===value.length)return value;var formattedValue=value.trim();return 0===formattedValue.length?formattedValue:formattedValue.match(/^[0]+$/)?"0":formattedValue.replace(/^0+/,"")},utilities.addLeadingZeroes=function(value,expectedLength){if(utilities.isInvalid(value))return null;if(value=value.toString(),expectedLength=utilities.parseInteger(expectedLength),utilities.isInvalidNumber(expectedLength)||expectedLength<0)return value;for(var numberOfZeroes=expectedLength-value.length,i=0;i<numberOfZeroes;i++)value="0"+value;return value},utilities.toString=function(value){if(void 0===value)return"undefined";if(null===value)return"null";if("string"==typeof value)return value;if(value===1/0)return"Infinity";if(value===-1/0)return"-Infinity";if("number"==typeof value&&isNaN(value))return"NaN";if(utilities.isDate(value))return value.toString();if(utilities.isRegularExpression(value)){var flags="";for(var flag in regExpFlags)value[flag]&&(flags+=regExpFlags[flag]);return"/"+value.source+"/"+flags}if(utilities.isFunction(value))return value.toString();if(utilities.isError(value)){var error={message:value.message};for(var attribute in value)error[attribute]=value[attribute];return JSON.stringify(error)}return JSON.stringify(value)},utilities.compareDates=function(a,b){return a=utilities.parseDate(a),b=utilities.parseDate(b),null===a&&null===b?0:null===a?-1:null===b?1:a.getTime()-b.getTime()},utilities.compareCasePercentage=function(value){if(utilities.isEmptyString(value))return 0;for(var c=null,upper=0,lower=0,lowerA="a".charCodeAt(),lowerZ="z".charCodeAt(),upperA="A".charCodeAt(),upperZ="Z".charCodeAt(),i=0;i<value.length;i++)lowerA<=(c=value.charCodeAt(i))&&c<=lowerZ?lower++:upperA<=c&&c<=upperZ&&upper++;return upper-lower},utilities.reverseString=function(value){if("string"!=typeof value)return null;for(var reverse="",i=(value=value.replace(/([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g,function($0,$1,$2){return utilities.reverseString($2)+$1}).replace(/([\uD800-\uDBFF])([\uDC00-\uDFFF])/g,"$2$1")).length-1;0<=i;i--)reverse+=value[i];return reverse},utilities.createError=function(message,status){var error=new Error(message);return error.status=utilities.parseInteger(status,500),error},utilities.clone=function(value){if(!utilities.isObject(value))return value;if(value instanceof Boolean)return new Boolean(value.valueOf());if(value instanceof Date)return(copy=new Date).setTime(value.getTime()),copy;if(value instanceof Array){for(var copy=[],i=0,length=value.length;i<length;i++)copy[i]=utilities.clone(value[i]);return copy}if(value instanceof Set)return new Set(value);if(value instanceof Map)return new Map(value);if(value instanceof RegExp){var flags="";for(var flag in regExpFlags)value[flag]&&(flags+=regExpFlags[flag]);return new RegExp(value.source,flags)}if("undefined"!=typeof Buffer&&value instanceof Buffer)return Buffer.from instanceof Function?Buffer.from(value):new Buffer(value);if(value instanceof Object){copy=null;if(value instanceof Error){(copy=new Error(value.message)).stack=utilities.clone(value.stack);var properties=Object.keys(value);for(i=0;i<properties.length;i++)copy[properties[i]]=utilities.clone(value[properties[i]])}else copy={};for(var attribute in value)Object.prototype.hasOwnProperty.call(value,attribute)&&(copy[attribute]=utilities.clone(value[attribute]));return copy}return value},utilities.merge=function(a,b,copy,deepMerge){if(!utilities.isObject(a)||Array.isArray(a))return null;var newObject=null;if(newObject=(copy=utilities.parseBoolean(copy,!0))?utilities.clone(a):a,!utilities.isObject(a)||Array.isArray(a)||!utilities.isObject(b)||Array.isArray(b))return newObject;var attribute=null,value=null,newValue=null,attributes=Object.keys(b);deepMerge=utilities.parseBoolean(deepMerge,!0);for(var i=0;i<attributes.length;i++)value=newObject[attribute=attributes[i]],newValue=copy?utilities.clone(b[attribute]):b[attribute],deepMerge&&utilities.isObject(value)&&!Array.isArray(value)&&utilities.isObject(newValue)&&!Array.isArray(newValue)?newObject[attribute]=utilities.merge(value,newValue):newObject[attribute]=newValue;return newObject},utilities.getFileName=function(filePath){if("string"!=typeof filePath)return null;for(var i=(filePath=filePath.trim()).length-1;0<=i;i--)if("/"===filePath[i]||"\\"===filePath[i])return filePath.substring(i+1,filePath.length).trim();return filePath},utilities.getFilePath=function(filePath){if("string"!=typeof filePath)return null;for(var i=(filePath=filePath.trim()).length-1;0<=i;i--)if("/"===filePath[i]||"\\"===filePath[i])return filePath.substring(0,i).trim();return""},utilities.getFileNameNoExtension=function(fileName){if("string"!=typeof fileName)return null;for(var i=(fileName=utilities.getFileName(fileName)).length-1;0<=i;i--)if("."===fileName[i])return fileName.substring(0,i).trim();return fileName},utilities.getFileExtension=function(fileName){if("string"!=typeof fileName)return null;for(var i=(fileName=utilities.getFileName(fileName)).length-1;0<=i;i--)if("."===fileName[i])return fileName.substring(i+1,fileName.length).trim();return""},utilities.fileHasExtension=function(fileName,extension){if(utilities.isEmptyString(fileName)||utilities.isEmptyString(extension))return!1;var actualFileExtension=utilities.getFileExtension(fileName);return!utilities.isEmptyString(actualFileExtension)&&actualFileExtension.toLowerCase()===extension.trim().toLowerCase()},utilities.reverseFileExtension=function(fileName){if("string"!=typeof fileName)return null;for(var i=(fileName=fileName.trim()).length-1;0<=i;i--)if("."===fileName[i])return fileName.substring(0,i)+"."+utilities.reverseString(fileName.substring(i+1,fileName.length));return fileName},utilities.truncateFileName=function(fileName,maxLength){if("string"!=typeof fileName)return null;if(fileName=utilities.getFileName(fileName),utilities.isEmptyString(fileName))return"";if(maxLength=utilities.parseInteger(maxLength),utilities.isInvalidNumber(maxLength)||maxLength<0)return fileName;if(0===maxLength)return"";if(fileName.length<=maxLength)return fileName;for(var extension="",originalFileName=fileName,i=fileName.length-1;0<=i;i--)if("."===fileName[i]){extension=fileName.substring(i+1,fileName.length),originalFileName=fileName.substring(0,i);break}return maxLength-(extension.length+(0<extension.length?1:0))<1?originalFileName.substring(0,maxLength):originalFileName.substring(0,maxLength-extension.length-(0<extension.length?1:0))+(0<extension.length?"."+extension:"")},utilities.prependSlash=function(value){if("string"!=typeof value)return null;var formattedValue=value.trim();return 0===formattedValue.length||"/"!==formattedValue[0]&&"\\"!==formattedValue[0]&&(formattedValue="/"+formattedValue),formattedValue},utilities.appendSlash=function(value){if("string"!=typeof value)return null;var formattedValue=value.trim();return 0===formattedValue.length||"/"!==formattedValue[formattedValue.length-1]&&"\\"!==formattedValue[formattedValue.length-1]&&(formattedValue+="/"),formattedValue},utilities.joinPaths=function(base,path){var formattedBase="string"==typeof base?base.trim().replace(/[\/\\]+$/,""):null,formattedPath="string"==typeof path?path.trim().replace(/^[\/\\]+/,""):null,newPath="";return utilities.isNonEmptyString(formattedBase)&&(newPath+=formattedBase,utilities.isNonEmptyString(formattedPath)&&(newPath+="/")),utilities.isNonEmptyString(formattedPath)&&(newPath+=formattedPath),newPath},utilities.createQueryString=function(value,includeQuestionMark){if(!utilities.isObjectStrict(value))return"";var parameters=Object.keys(value).map(function(key){return encodeURIComponent(key)+"="+encodeURIComponent(utilities.toString(value[key]))}).join("&");return 0===parameters.length?"":(utilities.parseBoolean(includeQuestionMark,!1)?"?":"")+parameters},utilities.createRange=function(start,end){var formattedStart=utilities.parseInteger(start),formattedEnd=utilities.parseInteger(end);if(1===arguments.length&&(formattedEnd=formattedStart,formattedStart=0),utilities.isInvalidNumber(formattedStart)||utilities.isInvalidNumber(formattedEnd)||formattedEnd<formattedStart)return[];for(var range=[],i=formattedStart;i<=formattedEnd;i++)range.push(i);return range},utilities.futureMonths=function(date,prependZero){if(null===(date=utilities.parseDate(date)))return null;var currentDate=new Date,month=0;date.getFullYear()===currentDate.getFullYear()&&(month=currentDate.getMonth());var months=[];prependZero=utilities.parseBoolean(prependZero,!1);for(var i=0;i<12;i++)month<=i&&(prependZero?months.push((i<=8?"0":"")+(i+1)):months.push(i+1));return months},utilities.visibleElements=function(elements){if(!Array.isArray(elements))return[];for(var visibleElements=[],i=0;i<elements.length;i++)utilities.isVisible(elements[i])&&visibleElements.push(elements[i]);return visibleElements},utilities.hiddenElements=function(elements){if(!Array.isArray(elements))return[];for(var hiddenElements=[],i=0;i<elements.length;i++)utilities.isHidden(elements[i])&&hiddenElements.push(elements[i]);return hiddenElements},utilities.enabledElements=function(elements){if(!Array.isArray(elements))return[];for(var enabledElements=[],i=0;i<elements.length;i++)utilities.isEnabled(elements[i])&&enabledElements.push(elements[i]);return enabledElements},utilities.disabledElements=function(elements){if(!Array.isArray(elements))return[];for(var disabledElements=[],i=0;i<elements.length;i++)utilities.isDisabled(elements[i])&&disabledElements.push(elements[i]);return disabledElements},utilities.elementsWithAttribute=function(elements,attribute,hasAttribute){if(!Array.isArray(elements)||utilities.isEmptyString(attribute))return[];var element=null,filteredElements=[];attribute=attribute.trim(),hasAttribute=utilities.parseBoolean(hasAttribute,!0);for(var i=0;i<elements.length;i++)element=elements[i],utilities.isObject(element)&&(utilities.isInvalid(elements[i][attribute])?hasAttribute||filteredElements.push(element):hasAttribute&&filteredElements.push(elements[i]));return filteredElements},utilities.elementsWithoutAttribute=function(elements,attribute){return utilities.elementsWithAttribute(elements,attribute,!1)},utilities.matchAttribute=function(element,attribute,value){return!!utilities.isObject(element)&&(!!utilities.isEmptyString(attribute)||element[attribute.trim()]===value)},utilities.generateVersions=function(version,prefix,suffix){if(null===(version=utilities.parseVersion(version)))return null;prefix=utilities.trimString(prefix),suffix=utilities.trimString(suffix);for(var versions=[],value=null,i=0;i<version.length;i++){value="",utilities.isNonEmptyString(prefix)&&(value+=prefix);for(var j=0;j<=i;j++)0<j&&(value+="_"),value+=version[j];utilities.isNonEmptyString(suffix)&&(value+=suffix),versions.push(value)}return versions},utilities.parseVersion=function(value,trimTrailingZeroes){var formattedValue=utilities.isValidNumber(value)?value.toString():value;if("string"!=typeof formattedValue)return null;var version=[],versionData=formattedValue.match(/[^. \t]+/g);if(null===versionData||0===versionData.length)return null;for(var part=null,i=0;i<versionData.length;i++)if(validator.isInt(versionData[i])){if(part=utilities.parseInteger(versionData[i]),utilities.isInvalidNumber(part)||part<0)continue;version.push(part.toString())}else version.push(versionData[i]);if(utilities.parseBoolean(trimTrailingZeroes,!1))for(;!(version.length<=1)&&"0"===version[version.length-1];)version.pop();return 0===version.length?null:version},utilities.compareVersions=function(v1,v2,caseSensitive,throwErrors){if(caseSensitive=utilities.parseBoolean(caseSensitive,!1),throwErrors=utilities.parseBoolean(throwErrors,!1),null===(v1=utilities.parseVersion(v1))){if(throwErrors)throw new Error("Cannot compare invalid or empty first version.");return null}if(null===(v2=utilities.parseVersion(v2))){if(throwErrors)throw new Error("Cannot compare invalid or empty second version.");return null}for(var index=0;;){if(index>=v1.length){if(v1.length===v2.length)return 0;for(var i=index;i<v2.length;i++)if("0"!==v2[i])return-1;return 0}if(index>=v2.length){for(i=index;i<v1.length;i++)if("0"!==v1[i])return 1;return 0}var formattedA=utilities.parseInteger(v1[index]),formattedB=utilities.parseInteger(v2[index]);if(utilities.isInvalidNumber(formattedA)&&(formattedA=caseSensitive?v1[index]:v1[index].toUpperCase()),utilities.isInvalidNumber(formattedB)&&(formattedB=caseSensitive?v2[index]:v2[index].toUpperCase()),Number.isInteger(formattedA)){if(!Number.isInteger(formattedB))return-1}else if(Number.isInteger(formattedB))return 1;if(formattedB<formattedA)return 1;if(formattedA<formattedB)return-1;index++}},utilities}); | ||
//# sourceMappingURL=extra-utilities.min.js.map |
{ | ||
"name": "extra-utilities", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "A collection of useful helper functions.", | ||
@@ -10,5 +10,4 @@ "main": "dist/extra-utilities.js", | ||
"test": "mocha", | ||
"coverage": "gulp coverage", | ||
"coveralls": "npm run coverage -- --report lcovonly && cat ./coverage/lcov.info | coveralls", | ||
"security": "gulp security" | ||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha --require test/*.js", | ||
"coveralls": "npm run coverage -- --report lcovonly && cat ./coverage/lcov.info | coveralls" | ||
}, | ||
@@ -35,4 +34,4 @@ "repository": { | ||
"dependencies": { | ||
"change-case-bundled": "^1.0.1", | ||
"validator": "^9.4.1" | ||
"change-case-bundled": "^1.0.3", | ||
"validator": "^12.2.0" | ||
}, | ||
@@ -39,0 +38,0 @@ "devDependencies": { |
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
264197
6
1994
+ Addedvalidator@12.2.0(transitive)
- Removedvalidator@9.4.1(transitive)
Updatedchange-case-bundled@^1.0.3
Updatedvalidator@^12.2.0