Comparing version 0.0.3 to 0.0.4
@@ -8,3 +8,3 @@ /*! | ||
* @license MIT | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
*/ | ||
@@ -730,3 +730,3 @@ (function (global, factory) { | ||
var VERSION = "0.0.3"; | ||
var VERSION = "0.0.4"; | ||
@@ -733,0 +733,0 @@ // Core |
@@ -8,4 +8,4 @@ /*! | ||
* @license MIT | ||
* @version 0.0.3 | ||
* @version 0.0.4 | ||
*/ | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.CakeHash=factory()}(this,function(){"use strict";function getType(obj){return null==obj?obj+"":"object"===("undefined"==typeof obj?"undefined":babelHelpers["typeof"](obj))||"function"==typeof obj?classTypes[Object.prototype.toString.call(obj)]||"object":"undefined"==typeof obj?"undefined":babelHelpers["typeof"](obj)}function isArray(obj){return Array.isArray(obj)}function isObject(obj){return!isArray(obj)&&"object"===getType(obj)}function isNumber(obj){return"number"===getType(obj)}function isString(obj){return"string"===getType(obj)}function isBoolean(obj){return"boolean"===getType(obj)}function isCollection(obj){return isArray(obj)||isObject(obj)}function isNumeric(obj){var type=getType(obj);return("number"===type||"string"===type)&&obj-parseFloat(obj)+1>=0}function isInteger(obj){var type=getType(obj);return("number"===type||"string"===type)&&/^([1-9]\d*|0)$/.test(obj)}function empty(obj){return isArray(obj)?0===obj.length:isObject(obj)?0===Object.keys(obj).length:isNumeric(obj)?0===parseFloat(obj):!obj}function hasProp(obj,key){return obj&&obj.hasOwnProperty(key)}function clone(obj){var _isArray=isArray(obj),_isObject=isObject(obj);if(_isArray||_isObject){var result=_isArray?[]:{},key=void 0,val=void 0;for(key in obj)hasProp(obj,key)&&(val=obj[key],isCollection(val)&&(val=clone(val)),result[key]=val);return result}}function merge(obj,source){var deep=arguments.length<=2||void 0===arguments[2]?!1:arguments[2];return each(source,function(value,key){deep&&hasProp(obj,key)&&isCollection(value)?merge(obj[key],value,deep):obj[key]=value}),obj}function each(obj,iterate,context){if(null==obj)return obj;if(context=context||obj,isObject(obj)){for(var key in obj)if(hasProp(obj,key)&&iterate.call(context,obj[key],key)===!1)break}else if(isArray(obj)){var i=void 0,length=obj.length;for(i=0;length>i&&iterate.call(context,obj[i],i)!==!1;i++);}return obj}function arrayCombine(keys,values){var data={},keyCount=keys&&keys.length,i=0,key=void 0;if(!(isCollection(keys)&&isCollection(values)&&isNumber(keyCount)&&isNumber(values.length)&&keyCount))return null;if(keyCount!==values.length)return null;for(i=0;keyCount>i;i++)key=keys[i],isInteger(key)&&(key=parseInt(key,10)),data[key]=values[i];return objToArray(data)}function arrayFill(startIndex,num,mixedVal){var key=void 0,arr=[];if(!isNaN(startIndex)&&!isNaN(num))for(key=0;num>key;key++)arr[key+startIndex]=mixedVal;return arr}function objToArray(obj){if(!isObject(obj))return obj;if(!Object.keys(obj).every(function(key){return isInteger(key)}))return obj;var array=[];return each(obj,function(value,i){array[i]=value}),array}function simpleOp(op,data,path){var values=arguments.length<=3||void 0===arguments[3]?null:arguments[3],length=path.length,last=length-1,list=data;return each(path,function(key,i){switch((isNumeric(key)&&parseInt(key,10)>0||"0"===key)&&0!==key.indexOf("0")&&(key=parseInt(key,10)),op){case"insert":if(i===last)return list[key]=values,!1;null!=list[key]&&hasProp(list,key)||(list[key]={}),isCollection(list[key])||(list[key]={}),list=list[key];break;case"remove":if(i===last)return delete list[key],!1;if(null==list[key]||!hasProp(list,key))return!1;list=list[key]}}),data}function get(data,path){var defaultValue=arguments.length<=2||void 0===arguments[2]?null:arguments[2],parts=void 0,val=void 0;if(!isCollection(data))return defaultValue;if(empty(data)||null==path||""===path)return defaultValue;if(isString(path)||isNumeric(path))parts=(path+"").split(".");else{if(!isArray(path))return defaultValue;parts=path}return val=isCollection(data)?clone(data):data,each(parts,function(v){return isCollection(val)&&hasProp(val,v)?void(val=val[v]):(val=defaultValue,!1)}),val}function trim(input){return input.replace(/^\s+|\s+$/g,"")}function tokenize(str){var separator=arguments.length<=1||void 0===arguments[1]?",":arguments[1],left=arguments.length<=2||void 0===arguments[2]?"(":arguments[2],right=arguments.length<=3||void 0===arguments[3]?")":arguments[3];if(empty(str))return[];for(var depth=0,offset=0,buffer="",results=[],length=str.length,open=!1;length>=offset;){for(var tmpOffset=-1,offsets=[str.indexOf(separator,offset),str.indexOf(left,offset),str.indexOf(right,offset)],i=0;3>i;i++)-1!==offsets[i]&&(offsets[i]<tmpOffset||-1===tmpOffset)&&(tmpOffset=offsets[i]);if(-1!==tmpOffset){buffer+=str.substr(offset,tmpOffset-offset);var char=str.substr(tmpOffset,1);depth||char!==separator?buffer+=char:(results.push(buffer),buffer=""),left!==right?(char===left&&depth++,char===right&&depth--):char===left&&(open?depth--:(depth++,open=!0)),offset=++tmpOffset}else results.push(buffer+str.substr(offset)),offset=length+1}return empty(results)&&!empty(buffer)&&results.push(buffer),empty(results)?[]:results.map(function(val){return trim(val)})}function splitConditions(token){var conditions=!1,position=token.indexOf("[");return position>-1&&(conditions=token.substr(position),token=token.substr(0,position)),[token,conditions]}function matchToken(key,token){switch(token){case"{n}":return isNumeric(key);case"{s}":return isString(key);case"{*}":return!0;default:return isNumeric(token)?key==token:key===token}}function matches(data,selector){for(var identifier="(?:\\\\.|[\\w-_.]|[^\\x00-\\xa0])+",attributes=new RegExp("\\s*("+identifier+")(?:\\s*([><!]?[=]|[><])\\s*(\\/.*?\\/|"+identifier+")|)\\s*]","g"),cond=void 0;cond=attributes.exec(selector);){var attr=cond[1],op=cond[2]||null,val=cond[3]||null,hasProperty=hasProp(data,attr);if(empty(op)&&empty(val)&&!hasProperty)return!1;if(!hasProperty&&null==data[attr])return!1;var prop=hasProperty?prop=data[attr]:void 0,_isBoolean=isBoolean(prop)||"true"===prop||"false"===prop;if(_isBoolean&&isNumeric(val)?prop=prop?"1":"0":_isBoolean&&(prop=prop?"true":"false"),"="===op&&val&&"/"===val[0]&&"/"===val[val.length-1]){if(prop=isString(prop)||isNumeric(prop)?prop:"",!new RegExp(val.substr(1,val.length-2)).test(prop))return!1}else if("="===op&&prop!=val||"!="===op&&prop==val||">"===op&&val>=prop||"<"===op&&prop>=val||">="===op&&val>prop||"<="===op&&prop>val)return!1}return!0}function extract(data,path){if(!isCollection(data))return null;if(empty(path))return data;if(!/[{\[]/.test(path))return get(data,path,null);var key="__set_item__",tokens=void 0,context=babelHelpers.defineProperty({},key,[data]);return tokens=path.indexOf("[")<0?path.split("."):tokenize(path,".","[","]"),each(tokens,function(token){var next=[],_Text$splitConditions=splitConditions(token),_Text$splitConditions2=babelHelpers.slicedToArray(_Text$splitConditions,2),_token=_Text$splitConditions2[0],conditions=_Text$splitConditions2[1];each(context[key],function(item){each(item,function(v,k){matchToken(k,_token)&&next.push(v)})}),conditions&&!function(){var filter=[];each(next,function(item){isCollection(item)&&matches(item,conditions)&&filter.push(item)}),next=filter}(),context=babelHelpers.defineProperty({},key,next)}),context[key]}function insert(data,path){var value=arguments.length<=2||void 0===arguments[2]?null:arguments[2],noTokens=path.indexOf("[")<0;if(noTokens&&path.indexOf(".")<0)return data[path]=value,data;var tokens=void 0;if(tokens=noTokens?path.split("."):tokenize(path,".","[","]"),noTokens&&path.indexOf("{")<0)return simpleOp("insert",data,tokens,value);var token=tokens.shift(),nextPath=tokens.join("."),_Text$splitConditions=splitConditions(token),_Text$splitConditions2=babelHelpers.slicedToArray(_Text$splitConditions,2),_token=_Text$splitConditions2[0],conditions=_Text$splitConditions2[1];return each(data,function(v,k){matchToken(k,_token)&&(!conditions||matches(v,conditions))&&(data[k]=nextPath?insert(v,nextPath,value):merge(v,value))}),data}function remove(data,path){var noTokens=path.indexOf("[")<0,noExpansion=path.indexOf("{")<0;if(noExpansion&&noTokens&&path.indexOf(".")<0)return delete data[path],data;var tokens=noTokens?path.split("."):tokenize(path,".","[","]");if(noExpansion&&noTokens)return simpleOp("remove",data,tokens);var token=tokens.shift(),nextPath=tokens.join("."),_Text$splitConditions=splitConditions(token),_Text$splitConditions2=babelHelpers.slicedToArray(_Text$splitConditions,2),_token=_Text$splitConditions2[0],conditions=_Text$splitConditions2[1];return each(data,function(v,k){var match=matchToken(k,_token);match&&isCollection(v)?(conditions?matches(v,conditions)&&(nextPath?data[k]=remove(v,nextPath):delete data[k]):data[k]=remove(v,nextPath),empty(data[k])&&delete data[k]):match&&empty(nextPath)&&delete data[k]}),data}function combine(data,keyPath){var valuePath=arguments.length<=2||void 0===arguments[2]?null:arguments[2],groupPath=arguments.length<=3||void 0===arguments[3]?null:arguments[3];if(empty(data))return[];var keys=extract(data,keyPath),vals=void 0;if(empty(keys))return[];if(empty(valuePath)||(vals=extract(data,valuePath)),empty(vals)&&(vals=arrayFill(0,keys.length,null)),keys.length!==vals.length)return[];if(null!=groupPath){var group=extract(data,groupPath);if(!empty(group)){for(var c=keys.length,out={},i=0;c>i;i++)null!=group[i]&&hasProp(group,i)||(group[i]=0),null!=out[group[i]]&&hasProp(out,group[i])||(out[group[i]]={}),out[group[i]][keys[i]]=vals[i];return objToArray(out)}}return empty(vals)?[]:arrayCombine(keys,vals)}function check(data,path){var results=extract(data,path);return isCollection(results)?!empty(results):null!=results}function flatten(data){var separator=arguments.length<=1||void 0===arguments[1]?".":arguments[1];return _flatten(data,separator)}function _flatten(input,separator){var currentPath=arguments.length<=2||void 0===arguments[2]?null:arguments[2],results={},path=null;return isArray(input)&&0===input.length?(path=null==currentPath?0:currentPath,results[path]=input,results):(each(input,function(val,key){if(path=null==currentPath?key:""+currentPath+separator+key,isCollection(val)){var children=_flatten(val,separator,path);Object.keys(children).length>0&&(results=merge(results,children))}else void 0!==val&&(results[path]=val)}),objToArray(results))}function expand(data){var separator=arguments.length<=1||void 0===arguments[1]?".":arguments[1],results={};return each(data,function(value,flat){var keys=(flat+"").split(separator).reverse(),child={};child[keys.shift()]=value,each(keys,function(k){child=babelHelpers.defineProperty({},k,child)}),results=merge(results,child,!0)}),objToArray(results)}function map(data,path,callback){var values=objToArray(extract(data,path));return isArray(values)?values.map(callback):null}function reduce(data,path,callback){var values=objToArray(extract(data,path));return isArray(values)?values.reduce(callback):null}function CakeHash(){}var babelHelpers={};babelHelpers["typeof"]=function(obj){return obj&&"undefined"!=typeof Symbol&&obj.constructor===Symbol?"symbol":typeof obj},babelHelpers.defineProperty=function(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj},babelHelpers.slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i["return"]&&_i["return"]()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var classTypeList=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error","Symbol"],classTypes={};classTypeList.forEach(function(name){classTypes["[object "+name+"]"]=name.toLowerCase()});var VERSION="0.0.3";return CakeHash.VERSION=VERSION,CakeHash.get=get,CakeHash.extract=extract,CakeHash.insert=insert,CakeHash.remove=remove,CakeHash.combine=combine,CakeHash.check=check,CakeHash.flatten=flatten,CakeHash.expand=expand,CakeHash.map=map,CakeHash.reduce=reduce,CakeHash}); | ||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.CakeHash=factory()}(this,function(){"use strict";function getType(obj){return null==obj?obj+"":"object"===("undefined"==typeof obj?"undefined":babelHelpers["typeof"](obj))||"function"==typeof obj?classTypes[Object.prototype.toString.call(obj)]||"object":"undefined"==typeof obj?"undefined":babelHelpers["typeof"](obj)}function isArray(obj){return Array.isArray(obj)}function isObject(obj){return!isArray(obj)&&"object"===getType(obj)}function isNumber(obj){return"number"===getType(obj)}function isString(obj){return"string"===getType(obj)}function isBoolean(obj){return"boolean"===getType(obj)}function isCollection(obj){return isArray(obj)||isObject(obj)}function isNumeric(obj){var type=getType(obj);return("number"===type||"string"===type)&&obj-parseFloat(obj)+1>=0}function isInteger(obj){var type=getType(obj);return("number"===type||"string"===type)&&/^([1-9]\d*|0)$/.test(obj)}function empty(obj){return isArray(obj)?0===obj.length:isObject(obj)?0===Object.keys(obj).length:isNumeric(obj)?0===parseFloat(obj):!obj}function hasProp(obj,key){return obj&&obj.hasOwnProperty(key)}function clone(obj){var _isArray=isArray(obj),_isObject=isObject(obj);if(_isArray||_isObject){var result=_isArray?[]:{},key=void 0,val=void 0;for(key in obj)hasProp(obj,key)&&(val=obj[key],isCollection(val)&&(val=clone(val)),result[key]=val);return result}}function merge(obj,source){var deep=arguments.length<=2||void 0===arguments[2]?!1:arguments[2];return each(source,function(value,key){deep&&hasProp(obj,key)&&isCollection(value)?merge(obj[key],value,deep):obj[key]=value}),obj}function each(obj,iterate,context){if(null==obj)return obj;if(context=context||obj,isObject(obj)){for(var key in obj)if(hasProp(obj,key)&&iterate.call(context,obj[key],key)===!1)break}else if(isArray(obj)){var i=void 0,length=obj.length;for(i=0;length>i&&iterate.call(context,obj[i],i)!==!1;i++);}return obj}function arrayCombine(keys,values){var data={},keyCount=keys&&keys.length,i=0,key=void 0;if(!(isCollection(keys)&&isCollection(values)&&isNumber(keyCount)&&isNumber(values.length)&&keyCount))return null;if(keyCount!==values.length)return null;for(i=0;keyCount>i;i++)key=keys[i],isInteger(key)&&(key=parseInt(key,10)),data[key]=values[i];return objToArray(data)}function arrayFill(startIndex,num,mixedVal){var key=void 0,arr=[];if(!isNaN(startIndex)&&!isNaN(num))for(key=0;num>key;key++)arr[key+startIndex]=mixedVal;return arr}function objToArray(obj){if(!isObject(obj))return obj;if(!Object.keys(obj).every(function(key){return isInteger(key)}))return obj;var array=[];return each(obj,function(value,i){array[i]=value}),array}function simpleOp(op,data,path){var values=arguments.length<=3||void 0===arguments[3]?null:arguments[3],length=path.length,last=length-1,list=data;return each(path,function(key,i){switch((isNumeric(key)&&parseInt(key,10)>0||"0"===key)&&0!==key.indexOf("0")&&(key=parseInt(key,10)),op){case"insert":if(i===last)return list[key]=values,!1;null!=list[key]&&hasProp(list,key)||(list[key]={}),isCollection(list[key])||(list[key]={}),list=list[key];break;case"remove":if(i===last)return delete list[key],!1;if(null==list[key]||!hasProp(list,key))return!1;list=list[key]}}),data}function get(data,path){var defaultValue=arguments.length<=2||void 0===arguments[2]?null:arguments[2],parts=void 0,val=void 0;if(!isCollection(data))return defaultValue;if(empty(data)||null==path||""===path)return defaultValue;if(isString(path)||isNumeric(path))parts=(path+"").split(".");else{if(!isArray(path))return defaultValue;parts=path}return val=isCollection(data)?clone(data):data,each(parts,function(v){return isCollection(val)&&hasProp(val,v)?void(val=val[v]):(val=defaultValue,!1)}),val}function trim(input){return input.replace(/^\s+|\s+$/g,"")}function tokenize(str){var separator=arguments.length<=1||void 0===arguments[1]?",":arguments[1],left=arguments.length<=2||void 0===arguments[2]?"(":arguments[2],right=arguments.length<=3||void 0===arguments[3]?")":arguments[3];if(empty(str))return[];for(var depth=0,offset=0,buffer="",results=[],length=str.length,open=!1;length>=offset;){for(var tmpOffset=-1,offsets=[str.indexOf(separator,offset),str.indexOf(left,offset),str.indexOf(right,offset)],i=0;3>i;i++)-1!==offsets[i]&&(offsets[i]<tmpOffset||-1===tmpOffset)&&(tmpOffset=offsets[i]);if(-1!==tmpOffset){buffer+=str.substr(offset,tmpOffset-offset);var char=str.substr(tmpOffset,1);depth||char!==separator?buffer+=char:(results.push(buffer),buffer=""),left!==right?(char===left&&depth++,char===right&&depth--):char===left&&(open?depth--:(depth++,open=!0)),offset=++tmpOffset}else results.push(buffer+str.substr(offset)),offset=length+1}return empty(results)&&!empty(buffer)&&results.push(buffer),empty(results)?[]:results.map(function(val){return trim(val)})}function splitConditions(token){var conditions=!1,position=token.indexOf("[");return position>-1&&(conditions=token.substr(position),token=token.substr(0,position)),[token,conditions]}function matchToken(key,token){switch(token){case"{n}":return isNumeric(key);case"{s}":return isString(key);case"{*}":return!0;default:return isNumeric(token)?key==token:key===token}}function matches(data,selector){for(var identifier="(?:\\\\.|[\\w-_.]|[^\\x00-\\xa0])+",attributes=new RegExp("\\s*("+identifier+")(?:\\s*([><!]?[=]|[><])\\s*(\\/.*?\\/|"+identifier+")|)\\s*]","g"),cond=void 0;cond=attributes.exec(selector);){var attr=cond[1],op=cond[2]||null,val=cond[3]||null,hasProperty=hasProp(data,attr);if(empty(op)&&empty(val)&&!hasProperty)return!1;if(!hasProperty&&null==data[attr])return!1;var prop=hasProperty?prop=data[attr]:void 0,_isBoolean=isBoolean(prop)||"true"===prop||"false"===prop;if(_isBoolean&&isNumeric(val)?prop=prop?"1":"0":_isBoolean&&(prop=prop?"true":"false"),"="===op&&val&&"/"===val[0]&&"/"===val[val.length-1]){if(prop=isString(prop)||isNumeric(prop)?prop:"",!new RegExp(val.substr(1,val.length-2)).test(prop))return!1}else if("="===op&&prop!=val||"!="===op&&prop==val||">"===op&&val>=prop||"<"===op&&prop>=val||">="===op&&val>prop||"<="===op&&prop>val)return!1}return!0}function extract(data,path){if(!isCollection(data))return null;if(empty(path))return data;if(!/[{\[]/.test(path))return get(data,path,null);var key="__set_item__",tokens=void 0,context=babelHelpers.defineProperty({},key,[data]);return tokens=path.indexOf("[")<0?path.split("."):tokenize(path,".","[","]"),each(tokens,function(token){var next=[],_Text$splitConditions=splitConditions(token),_Text$splitConditions2=babelHelpers.slicedToArray(_Text$splitConditions,2),_token=_Text$splitConditions2[0],conditions=_Text$splitConditions2[1];each(context[key],function(item){each(item,function(v,k){matchToken(k,_token)&&next.push(v)})}),conditions&&!function(){var filter=[];each(next,function(item){isCollection(item)&&matches(item,conditions)&&filter.push(item)}),next=filter}(),context=babelHelpers.defineProperty({},key,next)}),context[key]}function insert(data,path){var value=arguments.length<=2||void 0===arguments[2]?null:arguments[2],noTokens=path.indexOf("[")<0;if(noTokens&&path.indexOf(".")<0)return data[path]=value,data;var tokens=void 0;if(tokens=noTokens?path.split("."):tokenize(path,".","[","]"),noTokens&&path.indexOf("{")<0)return simpleOp("insert",data,tokens,value);var token=tokens.shift(),nextPath=tokens.join("."),_Text$splitConditions=splitConditions(token),_Text$splitConditions2=babelHelpers.slicedToArray(_Text$splitConditions,2),_token=_Text$splitConditions2[0],conditions=_Text$splitConditions2[1];return each(data,function(v,k){matchToken(k,_token)&&(!conditions||matches(v,conditions))&&(data[k]=nextPath?insert(v,nextPath,value):merge(v,value))}),data}function remove(data,path){var noTokens=path.indexOf("[")<0,noExpansion=path.indexOf("{")<0;if(noExpansion&&noTokens&&path.indexOf(".")<0)return delete data[path],data;var tokens=noTokens?path.split("."):tokenize(path,".","[","]");if(noExpansion&&noTokens)return simpleOp("remove",data,tokens);var token=tokens.shift(),nextPath=tokens.join("."),_Text$splitConditions=splitConditions(token),_Text$splitConditions2=babelHelpers.slicedToArray(_Text$splitConditions,2),_token=_Text$splitConditions2[0],conditions=_Text$splitConditions2[1];return each(data,function(v,k){var match=matchToken(k,_token);match&&isCollection(v)?(conditions?matches(v,conditions)&&(nextPath?data[k]=remove(v,nextPath):delete data[k]):data[k]=remove(v,nextPath),empty(data[k])&&delete data[k]):match&&empty(nextPath)&&delete data[k]}),data}function combine(data,keyPath){var valuePath=arguments.length<=2||void 0===arguments[2]?null:arguments[2],groupPath=arguments.length<=3||void 0===arguments[3]?null:arguments[3];if(empty(data))return[];var keys=extract(data,keyPath),vals=void 0;if(empty(keys))return[];if(empty(valuePath)||(vals=extract(data,valuePath)),empty(vals)&&(vals=arrayFill(0,keys.length,null)),keys.length!==vals.length)return[];if(null!=groupPath){var group=extract(data,groupPath);if(!empty(group)){for(var c=keys.length,out={},i=0;c>i;i++)null!=group[i]&&hasProp(group,i)||(group[i]=0),null!=out[group[i]]&&hasProp(out,group[i])||(out[group[i]]={}),out[group[i]][keys[i]]=vals[i];return objToArray(out)}}return empty(vals)?[]:arrayCombine(keys,vals)}function check(data,path){var results=extract(data,path);return isCollection(results)?!empty(results):null!=results}function flatten(data){var separator=arguments.length<=1||void 0===arguments[1]?".":arguments[1];return _flatten(data,separator)}function _flatten(input,separator){var currentPath=arguments.length<=2||void 0===arguments[2]?null:arguments[2],results={},path=null;return isArray(input)&&0===input.length?(path=null==currentPath?0:currentPath,results[path]=input,results):(each(input,function(val,key){if(path=null==currentPath?key:""+currentPath+separator+key,isCollection(val)){var children=_flatten(val,separator,path);Object.keys(children).length>0&&(results=merge(results,children))}else void 0!==val&&(results[path]=val)}),objToArray(results))}function expand(data){var separator=arguments.length<=1||void 0===arguments[1]?".":arguments[1],results={};return each(data,function(value,flat){var keys=(flat+"").split(separator).reverse(),child={};child[keys.shift()]=value,each(keys,function(k){child=babelHelpers.defineProperty({},k,child)}),results=merge(results,child,!0)}),objToArray(results)}function map(data,path,callback){var values=objToArray(extract(data,path));return isArray(values)?values.map(callback):null}function reduce(data,path,callback){var values=objToArray(extract(data,path));return isArray(values)?values.reduce(callback):null}function CakeHash(){}var babelHelpers={};babelHelpers["typeof"]=function(obj){return obj&&"undefined"!=typeof Symbol&&obj.constructor===Symbol?"symbol":typeof obj},babelHelpers.defineProperty=function(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj},babelHelpers.slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i["return"]&&_i["return"]()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var classTypeList=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error","Symbol"],classTypes={};classTypeList.forEach(function(name){classTypes["[object "+name+"]"]=name.toLowerCase()});var VERSION="0.0.4";return CakeHash.VERSION=VERSION,CakeHash.get=get,CakeHash.extract=extract,CakeHash.insert=insert,CakeHash.remove=remove,CakeHash.combine=combine,CakeHash.check=check,CakeHash.flatten=flatten,CakeHash.expand=expand,CakeHash.map=map,CakeHash.reduce=reduce,CakeHash}); |
{ | ||
"name": "cake-hash", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "CakePHP in Utility.Hash class like a collection manipulation. In JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "cake-hash.js", |
@@ -60,3 +60,3 @@ cake-hash | ||
```javascript | ||
import CakeHash from `cake-hash` | ||
import CakeHash from "cake-hash" | ||
@@ -90,3 +90,3 @@ CakeHash.__METHOD__() | ||
| Expression | Definition | | ||
|------------|-----------------------------------------------------------------------------------| | ||
| :----------| :---------------------------------------------------------------------------------| | ||
| `{n}` | Represents a numeric key. Will match any string or numeric key. | | ||
@@ -100,4 +100,5 @@ | `{s}` | Represents a string. Will match any string value including numeric string values. | | ||
### Attribute Matching Types | ||
| Matcher | Definition | | ||
| :--------------| :-----------------------------------------------------------------------------| | ||
| `[id]` | Match elements with a given array key. | | ||
|----------------|-------------------------------------------------------------------------------| | ||
| `[id=2]` | Match elements with id equal to 2. | | ||
@@ -503,3 +504,3 @@ | `[id!=2]` | Match elements with id not equal to 2. | | ||
### map(data, path, callback) | ||
### reduce(data, path, callback) | ||
**`data` : array | object** | ||
@@ -506,0 +507,0 @@ **`path` : string** |
@@ -12,3 +12,3 @@ import get from "./get" | ||
const VERSION = "0.0.3"; | ||
const VERSION = "0.0.4"; | ||
@@ -15,0 +15,0 @@ |
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
86103
560