Comparing version 0.2.0 to 0.3.1
@@ -1,1 +0,1 @@ | ||
define("reactions/chemical.js",["require","lodash"],function(require){var _=require("lodash");return{separateProperties:function(userProperties,feature){return{userPropertyNames:_.keys(userProperties),featurePropertyNames:_.keys(feature)}}}}),define("enzymes/helicase",["require","../reactions/chemical.js"],function(require){var chemicalReactions=require("../reactions/chemical.js");return{breakProperties:function(userProperties,feature){return chemicalReactions.separateProperties(userProperties,feature)}}}),define("reactions/matchers/regex",[],function(){function sanitizeRegexStr(regexStr){return regexStr.substring(1,regexStr.length-1)}var regexDelimiters=/^\/.+\/$/;return{isRegex:function(value){return regexDelimiters.test(value)},matchesPropertyValue:function(propertyValue,regexStr){var sanitisedRegex=sanitizeRegexStr(regexStr),regex=new RegExp("^"+sanitisedRegex+"$");return regex.test(propertyValue)}}}),define("reactions/matchers/numeric-quantifier",[],function(){function isExpressionValid(expression){return validExpressionRegex.test(expression)}var numberRegex=/-?\d+(\.\d{1,2})?/,operatorRegex=/[><]=?/,numericQuantifierRegex=new RegExp(operatorRegex.source+numberRegex.source),validExpressionRegex=new RegExp(numberRegex.source+operatorRegex.source+numberRegex.source);return{isNumber:function(value){return numberRegex.test(value)},isNumericQuantifier:function(value){return numericQuantifierRegex.test(value)},matchesPropertyValue:function(propertyValue,numericQuantifierStr){var expression=propertyValue+numericQuantifierStr;return isExpressionValid(expression)?eval(expression):!1}}}),define("reactions/match-reading.js",["require","lodash","./matchers/regex","./matchers/numeric-quantifier"],function(require){function pickMatcher(userPropertyValue,propertyKey){return regexMatcher.isRegex(propertyKey)?regexMatcher:numericMatcher.isNumber(userPropertyValue)&&numericMatcher.isNumericQuantifier(propertyKey)?numericMatcher:defaultMatcher}var _=require("lodash"),regexMatcher=require("./matchers/regex"),numericMatcher=require("./matchers/numeric-quantifier"),defaultMatcher={matchesPropertyValue:function(userPropertyValue,propertyKey){return userPropertyValue===propertyKey}};return{getMatchedProperties:function(userPropertyValue,featureProperty){return _.findLast(featureProperty,function(propertyValue,propertyKey){var matcher=pickMatcher(userPropertyValue,propertyKey);return matcher.matchesPropertyValue(userPropertyValue,propertyKey)})}}}),define("enzymes/primase",["require","lodash","../reactions/chemical.js","../reactions/match-reading.js"],function(require){function mergeProperties(primer,feature){var properties=getFeatureProperties(feature);_.merge(primer,properties)}function isFeatureDisabled(primer,root){var toggle=_.get(primer,"toggle");return root&&toggle===!1}function getFeatureProperties(feature){return _.pick(feature,["toggle","throttle","buckets"])}function containsFeatureProperties(obj){return _.has(obj,"toggle")||_.has(obj,"throttle")||_.has(obj,"buckets")}function getPropertiesNode(userProperties,featurePropertyName,feature){var featureProperty=feature[featurePropertyName],userPropertyValue=userProperties[featurePropertyName],properties=matchReading.getMatchedProperties(userPropertyValue,featureProperty);return pickMatchedProperties(properties,featureProperty)}function pickMatchedProperties(childProperties,parentProperties){return _.isUndefined(childProperties)?parentProperties:childProperties}function bindPrimer(primerInstructions,childPrimer){_.merge(primerInstructions,childPrimer)}var _=require("lodash"),chemicalReactions=require("../reactions/chemical.js"),matchReading=require("../reactions/match-reading.js");return{preparePrimer:function(userProperties,feature,propertyStrands,root){var self=this,primerInstructions={},userPropertyNames=propertyStrands.userPropertyNames,featurePropertyNames=propertyStrands.featurePropertyNames;return containsFeatureProperties(feature)&&mergeProperties(primerInstructions,feature),isFeatureDisabled(primerInstructions,root)||featurePropertyNames.forEach(function(featurePropertyName){if(_.contains(userPropertyNames,featurePropertyName)){var propertiesNode=getPropertiesNode(userProperties,featurePropertyName,feature),childStrands=chemicalReactions.separateProperties(userProperties,propertiesNode),childPrimer=self.preparePrimer(userProperties,propertiesNode,childStrands);bindPrimer(primerInstructions,childPrimer)}}),primerInstructions}}}),define("mutators/bucket",["require","lodash"],function(require){function pickOneElement(array){if(!_.isArray(array))throw"Not an array!";var index=Math.floor(Math.random()*array.length);return array[index]}function isBucketGene(gene){return!_.isEmpty(gene)&&"bucket"===gene.type}function containsGene(featureProperties,gene){return _.includes(featureProperties.buckets,gene.toggle)}var _=require("lodash");return{mutate:function(featureProperties,gene){return isBucketGene(gene)&&containsGene(featureProperties,gene)?gene.toggle:pickOneElement(featureProperties.buckets)},containsMultivariant:function(featureProperties){return this.isBucketListValid(featureProperties.buckets)},isBucketListValid:function(bucketList){return _.isArray(bucketList)&&bucketList.length>=0}}}),define("mutators/throttle",["require","lodash"],function(require){function getPercentageDecimal(throttle){var percentage=extractPercentage(throttle),value=percentage.substr(0,percentage.length-2);return value/10}function extractPercentage(throttle){var percentage;return percentage=isThrottleNode(throttle)?throttle.value:throttle}function isThrottleValid(throttle){return isThrottleNode(throttle)||isPercentage(throttle)}function isThrottleNode(throttle){return _.isPlainObject(throttle)&&_.isString(throttle.value)&&isPercentage(throttle.value)}function isPercentage(value){return!_.isUndefined(value)&&_.isString(value)&&value.match(/[0-100]%/)}function isThrottleGene(gene){return!_.isEmpty(gene)&&"throttle"===gene.type}function shouldMutate(throttle){return!_.isUndefined(throttle.mutate)&&"force"===throttle.mutate}var _=require("lodash");return{mutate:function(throttle,gene){if(!shouldMutate(throttle)&&isThrottleGene(gene))return gene.toggle;var percentage=getPercentageDecimal(throttle);return Math.random()<percentage},isThrottleValid:function(throttle){return isThrottleValid(throttle)}}}),define("mutators/gene-pairing",["require","lodash"],function(require){function containTogglesPair(genes,featureName){return hasPartialName(_.keys(genes.toggles),featureName)}function containBucketsPair(genes,featureName){return hasPartialName(genes.buckets,featureName)}function containThrottlesPair(genes,featureName){return hasPartialName(genes.throttles,featureName)}function hasPartialName(featureNames,partialName){return findWithPartialName(featureNames,partialName).length>0}function findWithPartialName(featureNames,partialName){return _.filter(featureNames,function(featureName){return 0===featureName.indexOf(partialName)})}function getMatchingBucket(genes,featureName){var matchedFeatures=findWithPartialName(genes.buckets,featureName),matched=_.find(matchedFeatures,function(matchedBucket){return genes.toggles[matchedBucket]});return _.isString(matched)?getBucketNameFromFeatureName(matched):""}function getBucketNameFromFeatureName(featureName){var dotIndex=featureName.indexOf(".");return dotIndex>=0?featureName.substring(dotIndex+1):""}var _=require("lodash");return{pairGene:function(genes,featureName){var gene={};if(containTogglesPair(genes,featureName)){var type="toggle",name=genes.toggles[featureName];containBucketsPair(genes,featureName)?(type="bucket",name=getMatchingBucket(genes,featureName)):containThrottlesPair(genes,featureName)&&(type="throttle"),gene.toggle=name,gene.type=type}return gene}}}),define("reactions/proof-reading",["require","lodash","../mutators/bucket","../mutators/throttle"],function(require){var _=require("lodash"),bucketMutator=require("../mutators/bucket"),throttleMutator=require("../mutators/throttle");return{areInstructionsValid:function(featureInstructions){var toggle=_.get(featureInstructions,"toggle"),throttle=_.get(featureInstructions,"throttle"),buckets=_.get(featureInstructions,"buckets");return this.isToggleValid(toggle)&&this.isThrottleValid(throttle)&&this.areBucketsValid(buckets)},isToggleValid:function(toggle){return _.isUndefined(toggle)||_.isBoolean(toggle)},isThrottleValid:function(throttle){return _.isUndefined(throttle)||throttleMutator.isThrottleValid(throttle)},areBucketsValid:function(buckets){return _.isUndefined(buckets)||bucketMutator.isBucketListValid(buckets)},checkFeatureInstructions:function(featureInstructions){var valid=_.isUndefined(featureInstructions)||_.isNull(featureInstructions)||!_.isArray(featureInstructions)&&_.isObject(featureInstructions);if(!valid)throw new Error("Invalid feature instructions!")}}}),define("enzymes/polymerase",["require","lodash","../mutators/bucket","../mutators/throttle","../mutators/gene-pairing","../reactions/proof-reading"],function(require){function addToFeatures(features,featureName,toggle){return features.push(_.merge({name:featureName},toggle))}function processFeatureInstructions(featureProperties,gene){var toggle={type:"toggle",toggle:!1};return featureProperties.toggle!==!1&&(throttleMutator.isThrottleValid(featureProperties.throttle)?(toggle.toggle=throttleMutator.mutate(featureProperties.throttle,gene),toggle.type="throttle"):featureProperties.toggle===!0&&(toggle.toggle=!0)),toggle}function containsBuckets(toggle,featureInstructions){return toggle.toggle&&bucketMutator.containsMultivariant(featureInstructions)}function addBucketToFeatures(features,featureName,featureInstructions,toggle,gene){var bucketName=bucketMutator.mutate(featureInstructions,gene),bucketToggle={toggle:toggle.toggle,type:"bucket"};addToFeatures(features,featureName+"."+bucketName,bucketToggle)}var _=require("lodash"),bucketMutator=require("../mutators/bucket"),throttleMutator=require("../mutators/throttle"),genePairing=require("../mutators/gene-pairing"),proofReader=require("../reactions/proof-reading");return{assembleFeatures:function(featureName,primerInstructions,ancestorGenes){var features=[];if(proofReader.areInstructionsValid(primerInstructions)){var gene=genePairing.pairGene(ancestorGenes,featureName),toggle=processFeatureInstructions(primerInstructions,gene);addToFeatures(features,featureName,toggle),containsBuckets(toggle,primerInstructions)&&addBucketToFeatures(features,featureName,primerInstructions,toggle,gene)}else addToFeatures(features,featureName,{toggle:!1,type:"toggle"});return features}}}),function(){var hasExports="undefined"!=typeof module&&module.exports;define("muton",["require","lodash","./enzymes/helicase","./enzymes/primase","./enzymes/polymerase","./reactions/proof-reading"],function(require){function joinToggles(features,resolvedFeatures){features.toggles=_.reduce(resolvedFeatures,function(result,elem){return result[elem.name]=elem.toggle,result},features.toggles)}function joinThrottles(features,resolvedFeatures){var buckets=_.chain(resolvedFeatures).filter({type:"bucket"}).pluck("name").value();features.buckets=features.buckets.concat(buckets)}function joinBuckets(features,resolvedFeatures){var throttles=_.chain(resolvedFeatures).filter({type:"throttle"}).pluck("name").value();features.throttles=features.throttles.concat(throttles)}function joinMutations(features,resolvedFeatures){joinToggles(features,resolvedFeatures),joinThrottles(features,resolvedFeatures),joinBuckets(features,resolvedFeatures)}var _=require("lodash"),helicase=require("./enzymes/helicase"),primase=require("./enzymes/primase"),polymerase=require("./enzymes/polymerase"),proofReading=require("./reactions/proof-reading"),muton={getFeatureMutations:function(userProperties,featureInstructions){return this.getMutations(userProperties,featureInstructions).toggles},getMutations:function(userProperties,featureInstructions){return this.inheritMutations(userProperties,featureInstructions,{})},inheritMutations:function(userProperties,featureInstructions,ancestorGenes){var features={toggles:{},buckets:[],throttles:[]};return proofReading.checkFeatureInstructions(featureInstructions),_.forEach(featureInstructions,function(feature,featureName){var propertyChains=helicase.breakProperties(userProperties,feature),primer=primase.preparePrimer(userProperties,feature,propertyChains,!0),resolvedFeatures=polymerase.assembleFeatures(featureName,primer,ancestorGenes);joinMutations(features,resolvedFeatures)}),features}};return hasExports?module.exports=muton:this.muton=muton,muton})}.call(this); | ||
define("muton",[],function(){return function(t){function r(e){if(n[e])return n[e].exports;var o=n[e]={exports:{},id:e,loaded:!1};return t[e].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var n={};return r.m=t,r.c=n,r.p="",r(0)}([function(t,r,n){function e(t,r){t.toggles=c(r,function(t,r){return t[r.name]=r.toggle,t},t.toggles)}function o(t,r){var n=f(r,{type:"bucket"}),e=a("name",n);t.buckets=t.buckets.concat(e)}function u(t,r){var n=f(r,{type:"throttle"}),e=a("name",n);t.throttles=t.throttles.concat(e)}function i(t,r){e(t,r),o(t,r),u(t,r)}var c=n(1),f=n(50),a=n(53),s=n(57),l=n(60),p=n(62),v=n(99),g=n(105),x={getFeatureMutations:function(t,r){return this.getMutations(t,r).toggles},getMutations:function(t,r){return this.inheritMutations(t,r,{})},inheritMutations:function(t,r,n){var e={toggles:{},buckets:[],throttles:[]};return g.checkFeatureInstructions(r),s(r,function(r,o){var u=l.breakProperties(t,r),c=p.preparePrimer(t,r,u,!0),f=v.assembleFeatures(o,c,n);i(e,f)}),e}};t.exports=x},function(t,r,n){var e=n(2),o=n(3),u=n(24),i=u(e,o);t.exports=i},function(t,r){function n(t,r,n,e){var o=-1,u=t.length;for(e&&u&&(n=t[++o]);++o<u;)n=r(n,t[o],o,t);return n}t.exports=n},function(t,r,n){var e=n(4),o=n(23),u=o(e);t.exports=u},function(t,r,n){function e(t,r){return o(t,r,u)}var o=n(5),u=n(9);t.exports=e},function(t,r,n){var e=n(6),o=e();t.exports=o},function(t,r,n){function e(t){return function(r,n,e){for(var u=o(r),i=e(r),c=i.length,f=t?c:-1;t?f--:++f<c;){var a=i[f];if(n(u[a],a,u)===!1)break}return r}}var o=n(7);t.exports=e},function(t,r,n){function e(t){return o(t)?t:Object(t)}var o=n(8);t.exports=e},function(t,r){function n(t){var r=typeof t;return!!t&&("object"==r||"function"==r)}t.exports=n},function(t,r,n){var e=n(10),o=n(14),u=n(8),i=n(18),c=e(Object,"keys"),f=c?function(t){var r=null==t?void 0:t.constructor;return"function"==typeof r&&r.prototype===t||"function"!=typeof t&&o(t)?i(t):u(t)?c(t):[]}:i;t.exports=f},function(t,r,n){function e(t,r){var n=null==t?void 0:t[r];return o(n)?n:void 0}var o=n(11);t.exports=e},function(t,r,n){function e(t){return null==t?!1:o(t)?s.test(f.call(t)):u(t)&&i.test(t)}var o=n(12),u=n(13),i=/^\[object .+?Constructor\]$/,c=Object.prototype,f=Function.prototype.toString,a=c.hasOwnProperty,s=RegExp("^"+f.call(a).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=e},function(t,r,n){function e(t){return o(t)&&c.call(t)==u}var o=n(8),u="[object Function]",i=Object.prototype,c=i.toString;t.exports=e},function(t,r){function n(t){return!!t&&"object"==typeof t}t.exports=n},function(t,r,n){function e(t){return null!=t&&u(o(t))}var o=n(15),u=n(17);t.exports=e},function(t,r,n){var e=n(16),o=e("length");t.exports=o},function(t,r){function n(t){return function(r){return null==r?void 0:r[t]}}t.exports=n},function(t,r){function n(t){return"number"==typeof t&&t>-1&&t%1==0&&e>=t}var e=9007199254740991;t.exports=n},function(t,r,n){function e(t){for(var r=f(t),n=r.length,e=n&&t.length,a=!!e&&c(e)&&(u(t)||o(t)),l=-1,p=[];++l<n;){var v=r[l];(a&&i(v,e)||s.call(t,v))&&p.push(v)}return p}var o=n(19),u=n(20),i=n(21),c=n(17),f=n(22),a=Object.prototype,s=a.hasOwnProperty;t.exports=e},function(t,r,n){function e(t){return u(t)&&o(t)&&c.call(t,"callee")&&!f.call(t,"callee")}var o=n(14),u=n(13),i=Object.prototype,c=i.hasOwnProperty,f=i.propertyIsEnumerable;t.exports=e},function(t,r,n){var e=n(10),o=n(17),u=n(13),i="[object Array]",c=Object.prototype,f=c.toString,a=e(Array,"isArray"),s=a||function(t){return u(t)&&o(t.length)&&f.call(t)==i};t.exports=s},function(t,r){function n(t,r){return t="number"==typeof t||e.test(t)?+t:-1,r=null==r?o:r,t>-1&&t%1==0&&r>t}var e=/^\d+$/,o=9007199254740991;t.exports=n},function(t,r,n){function e(t){if(null==t)return[];f(t)||(t=Object(t));var r=t.length;r=r&&c(r)&&(u(t)||o(t))&&r||0;for(var n=t.constructor,e=-1,a="function"==typeof n&&n.prototype===t,l=Array(r),p=r>0;++e<r;)l[e]=e+"";for(var v in t)p&&i(v,r)||"constructor"==v&&(a||!s.call(t,v))||l.push(v);return l}var o=n(19),u=n(20),i=n(21),c=n(17),f=n(8),a=Object.prototype,s=a.hasOwnProperty;t.exports=e},function(t,r,n){function e(t,r){return function(n,e){var c=n?o(n):0;if(!u(c))return t(n,e);for(var f=r?c:-1,a=i(n);(r?f--:++f<c)&&e(a[f],f,a)!==!1;);return n}}var o=n(15),u=n(17),i=n(7);t.exports=e},function(t,r,n){function e(t,r){return function(n,e,c,f){var a=arguments.length<3;return"function"==typeof e&&void 0===f&&i(n)?t(n,e,c,a):u(n,o(e,f,4),c,a,r)}}var o=n(25),u=n(49),i=n(20);t.exports=e},function(t,r,n){function e(t,r,n){var e=typeof t;return"function"==e?void 0===r?t:i(t,r,n):null==t?c:"object"==e?o(t):void 0===r?f(t):u(t,r)}var o=n(26),u=n(38),i=n(45),c=n(46),f=n(47);t.exports=e},function(t,r,n){function e(t){var r=u(t);if(1==r.length&&r[0][2]){var n=r[0][0],e=r[0][1];return function(t){return null==t?!1:t[n]===e&&(void 0!==e||n in i(t))}}return function(t){return o(t,r)}}var o=n(27),u=n(35),i=n(7);t.exports=e},function(t,r,n){function e(t,r,n){var e=r.length,i=e,c=!n;if(null==t)return!i;for(t=u(t);e--;){var f=r[e];if(c&&f[2]?f[1]!==t[f[0]]:!(f[0]in t))return!1}for(;++e<i;){f=r[e];var a=f[0],s=t[a],l=f[1];if(c&&f[2]){if(void 0===s&&!(a in t))return!1}else{var p=n?n(s,l,a):void 0;if(!(void 0===p?o(l,s,n,!0):p))return!1}}return!0}var o=n(28),u=n(7);t.exports=e},function(t,r,n){function e(t,r,n,c,f,a){return t===r?!0:null==t||null==r||!u(t)&&!i(r)?t!==t&&r!==r:o(t,r,e,n,c,f,a)}var o=n(29),u=n(8),i=n(13);t.exports=e},function(t,r,n){function e(t,r,n,e,p,x,h){var b=c(t),y=c(r),d=s,m=s;b||(d=g.call(t),d==a?d=l:d!=l&&(b=f(t))),y||(m=g.call(r),m==a?m=l:m!=l&&(y=f(r)));var j=d==l,O=m==l,k=d==m;if(k&&!b&&!j)return u(t,r,d);if(!p){var P=j&&v.call(t,"__wrapped__"),A=O&&v.call(r,"__wrapped__");if(P||A)return n(P?t.value():t,A?r.value():r,e,p,x,h)}if(!k)return!1;x||(x=[]),h||(h=[]);for(var w=x.length;w--;)if(x[w]==t)return h[w]==r;x.push(t),h.push(r);var V=(b?o:i)(t,r,n,e,p,x,h);return x.pop(),h.pop(),V}var o=n(30),u=n(32),i=n(33),c=n(20),f=n(34),a="[object Arguments]",s="[object Array]",l="[object Object]",p=Object.prototype,v=p.hasOwnProperty,g=p.toString;t.exports=e},function(t,r,n){function e(t,r,n,e,u,i,c){var f=-1,a=t.length,s=r.length;if(a!=s&&!(u&&s>a))return!1;for(;++f<a;){var l=t[f],p=r[f],v=e?e(u?p:l,u?l:p,f):void 0;if(void 0!==v){if(v)continue;return!1}if(u){if(!o(r,function(t){return l===t||n(l,t,e,u,i,c)}))return!1}else if(l!==p&&!n(l,p,e,u,i,c))return!1}return!0}var o=n(31);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=t.length;++n<e;)if(r(t[n],n,t))return!0;return!1}t.exports=n},function(t,r){function n(t,r,n){switch(n){case e:case o:return+t==+r;case u:return t.name==r.name&&t.message==r.message;case i:return t!=+t?r!=+r:t==+r;case c:case f:return t==r+""}return!1}var e="[object Boolean]",o="[object Date]",u="[object Error]",i="[object Number]",c="[object RegExp]",f="[object String]";t.exports=n},function(t,r,n){function e(t,r,n,e,u,c,f){var a=o(t),s=a.length,l=o(r),p=l.length;if(s!=p&&!u)return!1;for(var v=s;v--;){var g=a[v];if(!(u?g in r:i.call(r,g)))return!1}for(var x=u;++v<s;){g=a[v];var h=t[g],b=r[g],y=e?e(u?b:h,u?h:b,g):void 0;if(!(void 0===y?n(h,b,e,u,c,f):y))return!1;x||(x="constructor"==g)}if(!x){var d=t.constructor,m=r.constructor;if(d!=m&&"constructor"in t&&"constructor"in r&&!("function"==typeof d&&d instanceof d&&"function"==typeof m&&m instanceof m))return!1}return!0}var o=n(9),u=Object.prototype,i=u.hasOwnProperty;t.exports=e},function(t,r,n){function e(t){return u(t)&&o(t.length)&&!!E[S.call(t)]}var o=n(17),u=n(13),i="[object Arguments]",c="[object Array]",f="[object Boolean]",a="[object Date]",s="[object Error]",l="[object Function]",p="[object Map]",v="[object Number]",g="[object Object]",x="[object RegExp]",h="[object Set]",b="[object String]",y="[object WeakMap]",d="[object ArrayBuffer]",m="[object Float32Array]",j="[object Float64Array]",O="[object Int8Array]",k="[object Int16Array]",P="[object Int32Array]",A="[object Uint8Array]",w="[object Uint8ClampedArray]",V="[object Uint16Array]",R="[object Uint32Array]",E={};E[m]=E[j]=E[O]=E[k]=E[P]=E[A]=E[w]=E[V]=E[R]=!0,E[i]=E[c]=E[d]=E[f]=E[a]=E[s]=E[l]=E[p]=E[v]=E[g]=E[x]=E[h]=E[b]=E[y]=!1;var M=Object.prototype,S=M.toString;t.exports=e},function(t,r,n){function e(t){for(var r=u(t),n=r.length;n--;)r[n][2]=o(r[n][1]);return r}var o=n(36),u=n(37);t.exports=e},function(t,r,n){function e(t){return t===t&&!o(t)}var o=n(8);t.exports=e},function(t,r,n){function e(t){t=u(t);for(var r=-1,n=o(t),e=n.length,i=Array(e);++r<e;){var c=n[r];i[r]=[c,t[c]]}return i}var o=n(9),u=n(7);t.exports=e},function(t,r,n){function e(t,r){var n=c(t),e=f(t)&&a(r),v=t+"";return t=p(t),function(c){if(null==c)return!1;var f=v;if(c=l(c),(n||!e)&&!(f in c)){if(c=1==t.length?c:o(c,i(t,0,-1)),null==c)return!1;f=s(t),c=l(c)}return c[f]===r?void 0!==r||f in c:u(r,c[f],void 0,!0)}}var o=n(39),u=n(28),i=n(40),c=n(20),f=n(41),a=n(36),s=n(42),l=n(7),p=n(43);t.exports=e},function(t,r,n){function e(t,r,n){if(null!=t){void 0!==n&&n in o(t)&&(r=[n]);for(var e=0,u=r.length;null!=t&&u>e;)t=t[r[e++]];return e&&e==u?t:void 0}}var o=n(7);t.exports=e},function(t,r){function n(t,r,n){var e=-1,o=t.length;r=null==r?0:+r||0,0>r&&(r=-r>o?0:o+r),n=void 0===n||n>o?o:+n||0,0>n&&(n+=o),o=r>n?0:n-r>>>0,r>>>=0;for(var u=Array(o);++e<o;)u[e]=t[e+r];return u}t.exports=n},function(t,r,n){function e(t,r){var n=typeof t;if("string"==n&&c.test(t)||"number"==n)return!0;if(o(t))return!1;var e=!i.test(t);return e||null!=r&&t in u(r)}var o=n(20),u=n(7),i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,c=/^\w*$/;t.exports=e},function(t,r){function n(t){var r=t?t.length:0;return r?t[r-1]:void 0}t.exports=n},function(t,r,n){function e(t){if(u(t))return t;var r=[];return o(t).replace(i,function(t,n,e,o){r.push(e?o.replace(c,"$1"):n||t)}),r}var o=n(44),u=n(20),i=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g,c=/\\(\\)?/g;t.exports=e},function(t,r){function n(t){return null==t?"":t+""}t.exports=n},function(t,r,n){function e(t,r,n){if("function"!=typeof t)return o;if(void 0===r)return t;switch(n){case 1:return function(n){return t.call(r,n)};case 3:return function(n,e,o){return t.call(r,n,e,o)};case 4:return function(n,e,o,u){return t.call(r,n,e,o,u)};case 5:return function(n,e,o,u,i){return t.call(r,n,e,o,u,i)}}return function(){return t.apply(r,arguments)}}var o=n(46);t.exports=e},function(t,r){function n(t){return t}t.exports=n},function(t,r,n){function e(t){return i(t)?o(t):u(t)}var o=n(16),u=n(48),i=n(41);t.exports=e},function(t,r,n){function e(t){var r=t+"";return t=u(t),function(n){return o(n,t,r)}}var o=n(39),u=n(43);t.exports=e},function(t,r){function n(t,r,n,e,o){return o(t,function(t,o,u){n=e?(e=!1,t):r(n,t,o,u)}),n}t.exports=n},function(t,r,n){function e(t,r,n){var e=c(t)?o:i;return r=u(r,n,3),e(t,r)}var o=n(51),u=n(25),i=n(52),c=n(20);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=t.length,o=-1,u=[];++n<e;){var i=t[n];r(i,n,t)&&(u[++o]=i)}return u}t.exports=n},function(t,r,n){function e(t,r){var n=[];return o(t,function(t,e,o){r(t,e,o)&&n.push(t)}),n}var o=n(3);t.exports=e},function(t,r,n){function e(t,r){return o(t,u(r))}var o=n(54),u=n(47);t.exports=e},function(t,r,n){function e(t,r,n){var e=c(t)?o:i;return r=u(r,n,3),e(t,r)}var o=n(55),u=n(25),i=n(56),c=n(20);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=t.length,o=Array(e);++n<e;)o[n]=r(t[n],n,t);return o}t.exports=n},function(t,r,n){function e(t,r){var n=-1,e=u(t)?Array(t.length):[];return o(t,function(t,o,u){e[++n]=r(t,o,u)}),e}var o=n(3),u=n(14);t.exports=e},function(t,r,n){var e=n(58),o=n(3),u=n(59),i=u(e,o);t.exports=i},function(t,r){function n(t,r){for(var n=-1,e=t.length;++n<e&&r(t[n],n,t)!==!1;);return t}t.exports=n},function(t,r,n){function e(t,r){return function(n,e,i){return"function"==typeof e&&void 0===i&&u(n)?t(n,e):r(n,o(e,i,3))}}var o=n(45),u=n(20);t.exports=e},function(t,r,n){"use strict";var e=n(61);t.exports={breakProperties:function(t,r){return e.separateProperties(t,r)}}},function(t,r,n){"use strict";var e=n(9);t.exports={separateProperties:function(t,r){return{userPropertyNames:e(t),featurePropertyNames:e(r)}}}},function(t,r,n){"use strict";function e(t){return l(t,["toggle","throttle","buckets"])}function o(t,r){var n=e(r);p(t,n)}function u(t,r){var n=s(t,"toggle");return r&&n===!1}function i(t){return v(t,"toggle")||v(t,"throttle")||v(t,"buckets")}function c(t,r){return g(t)?r:t}function f(t,r,n){var e=n[r],o=t[r],u=b.getMatchedProperties(o,e);return c(u,e)}function a(t,r){p(t,r)}var s=n(63),l=n(64),p=n(71),v=n(80),g=n(81),x=n(82),h=n(61),b=n(89);t.exports={preparePrimer:function(t,r,n,e){var c=this,s={},l=n.userPropertyNames,p=n.featurePropertyNames;return i(r)&&o(s,r),u(s,e)||p.forEach(function(n){if(x(l,n)){var e=f(t,n,r),o=h.separateProperties(t,e),u=c.preparePrimer(t,e,o);a(s,u)}}),s}}},function(t,r,n){function e(t,r,n){var e=null==t?void 0:o(t,u(r),r+"");return void 0===e?n:e}var o=n(39),u=n(43);t.exports=e},function(t,r,n){var e=n(65),o=n(45),u=n(67),i=n(68),c=n(70),f=c(function(t,r){return null==t?{}:"function"==typeof r[0]?i(t,o(r[0],r[1],3)):u(t,e(r))});t.exports=f},function(t,r,n){function e(t,r,n,a){a||(a=[]);for(var s=-1,l=t.length;++s<l;){var p=t[s];f(p)&&c(p)&&(n||i(p)||u(p))?r?e(p,r,n,a):o(a,p):n||(a[a.length]=p)}return a}var o=n(66),u=n(19),i=n(20),c=n(14),f=n(13);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=r.length,o=t.length;++n<e;)t[o+n]=r[n];return t}t.exports=n},function(t,r,n){function e(t,r){t=o(t);for(var n=-1,e=r.length,u={};++n<e;){var i=r[n];i in t&&(u[i]=t[i])}return u}var o=n(7);t.exports=e},function(t,r,n){function e(t,r){var n={};return o(t,function(t,e,o){r(t,e,o)&&(n[e]=t)}),n}var o=n(69);t.exports=e},function(t,r,n){function e(t,r){return o(t,r,u)}var o=n(5),u=n(22);t.exports=e},function(t,r){function n(t,r){if("function"!=typeof t)throw new TypeError(e);return r=o(void 0===r?t.length-1:+r||0,0),function(){for(var n=arguments,e=-1,u=o(n.length-r,0),i=Array(u);++e<u;)i[e]=n[r+e];switch(r){case 0:return t.call(this,i);case 1:return t.call(this,n[0],i);case 2:return t.call(this,n[0],n[1],i)}var c=Array(r+1);for(e=-1;++e<r;)c[e]=n[e];return c[r]=i,t.apply(this,c)}}var e="Expected a function",o=Math.max;t.exports=n},function(t,r,n){var e=n(72),o=n(78),u=o(e);t.exports=u},function(t,r,n){function e(t,r,n,p,v){if(!f(t))return t;var g=c(r)&&(i(r)||s(r)),x=g?void 0:l(r);return o(x||r,function(o,i){if(x&&(i=o,o=r[i]),a(o))p||(p=[]),v||(v=[]),u(t,r,i,e,n,p,v);else{var c=t[i],f=n?n(c,o,i,t,r):void 0,s=void 0===f;s&&(f=o),void 0===f&&(!g||i in t)||!s&&(f===f?f===c:c!==c)||(t[i]=f)}}),t}var o=n(58),u=n(73),i=n(20),c=n(14),f=n(8),a=n(13),s=n(34),l=n(9);t.exports=e},function(t,r,n){function e(t,r,n,e,l,p,v){for(var g=p.length,x=r[n];g--;)if(p[g]==x)return void(t[n]=v[g]);var h=t[n],b=l?l(h,x,n,t,r):void 0,y=void 0===b;y&&(b=x,c(x)&&(i(x)||a(x))?b=i(h)?h:c(h)?o(h):[]:f(x)||u(x)?b=u(h)?s(h):f(h)?h:{}:y=!1),p.push(x),v.push(b),y?t[n]=e(b,x,l,p,v):(b===b?b!==h:h===h)&&(t[n]=b)}var o=n(74),u=n(19),i=n(20),c=n(14),f=n(75),a=n(34),s=n(76);t.exports=e},function(t,r){function n(t,r){var n=-1,e=t.length;for(r||(r=Array(e));++n<e;)r[n]=t[n];return r}t.exports=n},function(t,r,n){function e(t){var r;if(!i(t)||s.call(t)!=c||u(t)||!a.call(t,"constructor")&&(r=t.constructor,"function"==typeof r&&!(r instanceof r)))return!1;var n;return o(t,function(t,r){n=r}),void 0===n||a.call(t,n)}var o=n(69),u=n(19),i=n(13),c="[object Object]",f=Object.prototype,a=f.hasOwnProperty,s=f.toString;t.exports=e},function(t,r,n){function e(t){return o(t,u(t))}var o=n(77),u=n(22);t.exports=e},function(t,r){function n(t,r,n){n||(n={});for(var e=-1,o=r.length;++e<o;){var u=r[e];n[u]=t[u]}return n}t.exports=n},function(t,r,n){function e(t){return i(function(r,n){var e=-1,i=null==r?0:n.length,c=i>2?n[i-2]:void 0,f=i>2?n[2]:void 0,a=i>1?n[i-1]:void 0;for("function"==typeof c?(c=o(c,a,5),i-=2):(c="function"==typeof a?a:void 0,i-=c?1:0),f&&u(n[0],n[1],f)&&(c=3>i?void 0:c,i=1);++e<i;){var s=n[e];s&&t(r,s,c)}return r})}var o=n(45),u=n(79),i=n(70);t.exports=e},function(t,r,n){function e(t,r,n){if(!i(n))return!1;var e=typeof r;if("number"==e?o(n)&&u(r,n.length):"string"==e&&r in n){var c=n[r];return t===t?t===c:c!==c}return!1}var o=n(14),u=n(21),i=n(8);t.exports=e},function(t,r,n){function e(t,r){if(null==t)return!1;var n=g.call(t,r);if(!n&&!a(r)){if(r=p(r),t=1==r.length?t:o(t,u(r,0,-1)),null==t)return!1;r=l(r),n=g.call(t,r)}return n||s(t.length)&&f(r,t.length)&&(c(t)||i(t))}var o=n(39),u=n(40),i=n(19),c=n(20),f=n(21),a=n(41),s=n(17),l=n(42),p=n(43),v=Object.prototype,g=v.hasOwnProperty;t.exports=e},function(t,r){function n(t){return void 0===t}t.exports=n},function(t,r,n){t.exports=n(83)},function(t,r,n){function e(t,r,n,e){var p=t?u(t):0;return f(p)||(t=s(t),p=t.length),n="number"!=typeof n||e&&c(r,n,e)?0:0>n?l(p+n,0):n||0,"string"==typeof t||!i(t)&&a(t)?p>=n&&t.indexOf(r,n)>-1:!!p&&o(t,r,n)>-1}var o=n(84),u=n(15),i=n(20),c=n(79),f=n(17),a=n(86),s=n(87),l=Math.max;t.exports=e},function(t,r,n){function e(t,r,n){if(r!==r)return o(t,n);for(var e=n-1,u=t.length;++e<u;)if(t[e]===r)return e;return-1}var o=n(85);t.exports=e},function(t,r){function n(t,r,n){for(var e=t.length,o=r+(n?0:-1);n?o--:++o<e;){var u=t[o];if(u!==u)return o}return-1}t.exports=n},function(t,r,n){function e(t){return"string"==typeof t||o(t)&&c.call(t)==u}var o=n(13),u="[object String]",i=Object.prototype,c=i.toString;t.exports=e},function(t,r,n){function e(t){return o(t,u(t))}var o=n(88),u=n(9);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=r.length,o=Array(e);++n<e;)o[n]=t[r[n]];return o}t.exports=n},function(t,r,n){"use strict";function e(t,r){return u.isRegex(r)?u:i.isNumber(t)&&i.isNumericQuantifier(r)?i:c}var o=n(90),u=n(97),i=n(98),c={matchesPropertyValue:function(t,r){return t===r}};t.exports={getMatchedProperties:function(t,r){return o(r,function(r,n){var o=e(t,n);return o.matchesPropertyValue(t,n)})}}},function(t,r,n){var e=n(91),o=n(94),u=o(e,!0);t.exports=u},function(t,r,n){var e=n(92),o=n(23),u=o(e,!0);t.exports=u},function(t,r,n){function e(t,r){return o(t,r,u)}var o=n(93),u=n(9);t.exports=e},function(t,r,n){var e=n(6),o=e(!0);t.exports=o},function(t,r,n){function e(t,r){return function(n,e,f){if(e=o(e,f,3),c(n)){var a=i(n,e,r);return a>-1?n[a]:void 0}return u(n,e,t)}}var o=n(25),u=n(95),i=n(96),c=n(20);t.exports=e},function(t,r){function n(t,r,n,e){var o;return n(t,function(t,n,u){return r(t,n,u)?(o=e?n:t,!1):void 0}),o}t.exports=n},function(t,r){function n(t,r,n){for(var e=t.length,o=n?e:-1;n?o--:++o<e;)if(r(t[o],o,t))return o;return-1}t.exports=n},function(t,r){"use strict";function n(t){return t.substring(1,t.length-1)}var e=/^\/.+\/$/;t.exports={isRegex:function(t){return e.test(t)},matchesPropertyValue:function(t,r){var e=n(r),o=new RegExp("^"+e+"$");return o.test(t)}}},function(module,exports){"use strict";function isExpressionValid(t){return validExpressionRegex.test(t)}var numberRegex=/-?\d+(\.\d{1,2})?/,operatorRegex=/[><]=?/,numericQuantifierRegex=new RegExp(operatorRegex.source+numberRegex.source),validExpressionRegex=new RegExp(numberRegex.source+operatorRegex.source+numberRegex.source);module.exports={isNumber:function(t){return numberRegex.test(t)},isNumericQuantifier:function(t){return numericQuantifierRegex.test(t)},matchesPropertyValue:function(propertyValue,numericQuantifierStr){var expression=propertyValue+numericQuantifierStr;return isExpressionValid(expression)?eval(expression):!1}}},function(t,r,n){"use strict";function e(t,r,n){return t.push(c({name:r},n))}function o(t,r){var n={type:"toggle",toggle:!1};return t.toggle!==!1&&(a.isThrottleValid(t.throttle)?(n.toggle=a.mutate(t.throttle,r),n.type="throttle"):t.toggle===!0&&(n.toggle=!0)),n}function u(t,r){return t.toggle&&f.containsMultivariant(r)}function i(t,r,n,o,u){var i=f.mutate(n,u),c={toggle:o.toggle,type:"bucket"};e(t,r+"."+i,c)}var c=n(71),f=n(100),a=n(102),s=n(103),l=n(105);t.exports={assembleFeatures:function(t,r,n){var c=[];if(l.areInstructionsValid(r)){var f=s.pairGene(n,t),a=o(r,f);e(c,t,a),u(a,r)&&i(c,t,r,a,f)}else e(c,t,{toggle:!1,type:"toggle"});return c}}},function(t,r,n){"use strict";function e(t){if(!i(t))throw"Not an array!";var r=Math.floor(Math.random()*t.length);return t[r]}function o(t){return!c(t)&&"bucket"===t.type}function u(t,r){return f(t.buckets,r.toggle)}var i=n(20),c=n(101),f=n(83);t.exports={mutate:function(t,r){return o(r)&&u(t,r)?r.toggle:e(t.buckets)},containsMultivariant:function(t){return this.isBucketListValid(t.buckets)},isBucketListValid:function(t){return i(t)&&t.length>=0}}},function(t,r,n){function e(t){return null==t?!0:i(t)&&(u(t)||a(t)||o(t)||f(t)&&c(t.splice))?!t.length:!s(t).length}var o=n(19),u=n(20),i=n(14),c=n(12),f=n(13),a=n(86),s=n(9);t.exports=e},function(t,r,n){"use strict";function e(t){return!s(t)&&l(t)&&t.match(/[0-100]%/)}function o(t){return p(t)&&l(t.value)&&e(t.value)}function u(t){var r;return r=o(t)?t.value:t}function i(t){var r=u(t),n=r.substr(0,r.length-2);return n/10}function c(t){return o(t)||e(t)}function f(t){return!v(t)&&"throttle"===t.type}function a(t){return!s(t.mutate)&&"force"===t.mutate}var s=n(81),l=n(86),p=n(75),v=n(101);t.exports={mutate:function(t,r){if(!a(t)&&f(r))return r.toggle;var n=i(t);return Math.random()<n},isThrottleValid:function(t){return c(t)}}},function(t,r,n){"use strict";function e(t,r){return s(t,function(t){return 0===t.indexOf(r)})}function o(t,r){return e(t,r).length>0}function u(t,r){return o(p(t.toggles),r)}function i(t,r){return o(t.buckets,r)}function c(t,r){return o(t.throttles,r)}function f(t){var r=t.indexOf(".");return r>=0?t.substring(r+1):""}function a(t,r){var n=e(t.buckets,r),o=l(n,function(r){return t.toggles[r]});return v(o)?f(o):""}var s=n(50),l=n(104),p=n(9),v=n(86);t.exports={pairGene:function(t,r){var n={};if(u(t,r)){var e="toggle",o=t.toggles[r];i(t,r)?(e="bucket",o=a(t,r)):c(t,r)&&(e="throttle"),n.toggle=o,n.type=e}return n}}},function(t,r,n){var e=n(3),o=n(94),u=o(e);t.exports=u},function(t,r,n){"use strict";var e=n(63),o=n(81),u=n(106),i=n(107),c=n(20),f=n(8),a=n(100),s=n(102);t.exports={areInstructionsValid:function(t){var r=e(t,"toggle"),n=e(t,"throttle"),o=e(t,"buckets");return this.isToggleValid(r)&&this.isThrottleValid(n)&&this.areBucketsValid(o)},isToggleValid:function(t){return o(t)||u(t)},isThrottleValid:function(t){return o(t)||s.isThrottleValid(t)},areBucketsValid:function(t){return o(t)||a.isBucketListValid(t)},checkFeatureInstructions:function(t){var r=o(t)||i(t)||!c(t)&&f(t);if(!r)throw new Error("Invalid feature instructions!")}}},function(t,r,n){function e(t){return t===!0||t===!1||o(t)&&c.call(t)==u}var o=n(13),u="[object Boolean]",i=Object.prototype,c=i.toString;t.exports=e},function(t,r){function n(t){return null===t}t.exports=n}])}); |
@@ -1,1 +0,1 @@ | ||
!function(){var reactions_chemicaljs,enzymes_helicase,reactions_matchers_regex,reactions_matchers_numeric_quantifier,reactions_match_readingjs,enzymes_primase,mutators_bucket,mutators_throttle,mutators_gene_pairing,reactions_proof_reading,enzymes_polymerase,muton,define=amdefine(module);reactions_chemicaljs=function(require){var _=lodash;return{separateProperties:function(userProperties,feature){return{userPropertyNames:_.keys(userProperties),featurePropertyNames:_.keys(feature)}}}}({});var define=amdefine(module);enzymes_helicase=function(require){var chemicalReactions=reactions_chemicaljs;return{breakProperties:function(userProperties,feature){return chemicalReactions.separateProperties(userProperties,feature)}}}({});var define=amdefine(module);reactions_matchers_regex=function(){function sanitizeRegexStr(regexStr){return regexStr.substring(1,regexStr.length-1)}var regexDelimiters=/^\/.+\/$/;return{isRegex:function(value){return regexDelimiters.test(value)},matchesPropertyValue:function(propertyValue,regexStr){var sanitisedRegex=sanitizeRegexStr(regexStr),regex=new RegExp("^"+sanitisedRegex+"$");return regex.test(propertyValue)}}}();var define=amdefine(module);reactions_matchers_numeric_quantifier=function(){function isExpressionValid(expression){return validExpressionRegex.test(expression)}var numberRegex=/-?\d+(\.\d{1,2})?/,operatorRegex=/[><]=?/,numericQuantifierRegex=new RegExp(operatorRegex.source+numberRegex.source),validExpressionRegex=new RegExp(numberRegex.source+operatorRegex.source+numberRegex.source);return{isNumber:function(value){return numberRegex.test(value)},isNumericQuantifier:function(value){return numericQuantifierRegex.test(value)},matchesPropertyValue:function(propertyValue,numericQuantifierStr){var expression=propertyValue+numericQuantifierStr;return isExpressionValid(expression)?eval(expression):!1}}}();var define=amdefine(module);reactions_match_readingjs=function(require){function pickMatcher(userPropertyValue,propertyKey){return regexMatcher.isRegex(propertyKey)?regexMatcher:numericMatcher.isNumber(userPropertyValue)&&numericMatcher.isNumericQuantifier(propertyKey)?numericMatcher:defaultMatcher}var _=lodash,regexMatcher=reactions_matchers_regex,numericMatcher=reactions_matchers_numeric_quantifier,defaultMatcher={matchesPropertyValue:function(userPropertyValue,propertyKey){return userPropertyValue===propertyKey}};return{getMatchedProperties:function(userPropertyValue,featureProperty){return _.findLast(featureProperty,function(propertyValue,propertyKey){var matcher=pickMatcher(userPropertyValue,propertyKey);return matcher.matchesPropertyValue(userPropertyValue,propertyKey)})}}}({});var define=amdefine(module);enzymes_primase=function(require){function mergeProperties(primer,feature){var properties=getFeatureProperties(feature);_.merge(primer,properties)}function isFeatureDisabled(primer,root){var toggle=_.get(primer,"toggle");return root&&toggle===!1}function getFeatureProperties(feature){return _.pick(feature,["toggle","throttle","buckets"])}function containsFeatureProperties(obj){return _.has(obj,"toggle")||_.has(obj,"throttle")||_.has(obj,"buckets")}function getPropertiesNode(userProperties,featurePropertyName,feature){var featureProperty=feature[featurePropertyName],userPropertyValue=userProperties[featurePropertyName],properties=matchReading.getMatchedProperties(userPropertyValue,featureProperty);return pickMatchedProperties(properties,featureProperty)}function pickMatchedProperties(childProperties,parentProperties){return _.isUndefined(childProperties)?parentProperties:childProperties}function bindPrimer(primerInstructions,childPrimer){_.merge(primerInstructions,childPrimer)}var _=lodash,chemicalReactions=reactions_chemicaljs,matchReading=reactions_match_readingjs;return{preparePrimer:function(userProperties,feature,propertyStrands,root){var self=this,primerInstructions={},userPropertyNames=propertyStrands.userPropertyNames,featurePropertyNames=propertyStrands.featurePropertyNames;return containsFeatureProperties(feature)&&mergeProperties(primerInstructions,feature),isFeatureDisabled(primerInstructions,root)||featurePropertyNames.forEach(function(featurePropertyName){if(_.contains(userPropertyNames,featurePropertyName)){var propertiesNode=getPropertiesNode(userProperties,featurePropertyName,feature),childStrands=chemicalReactions.separateProperties(userProperties,propertiesNode),childPrimer=self.preparePrimer(userProperties,propertiesNode,childStrands);bindPrimer(primerInstructions,childPrimer)}}),primerInstructions}}}({});var define=amdefine(module);mutators_bucket=function(require){function pickOneElement(array){if(!_.isArray(array))throw"Not an array!";var index=Math.floor(Math.random()*array.length);return array[index]}function isBucketGene(gene){return!_.isEmpty(gene)&&"bucket"===gene.type}function containsGene(featureProperties,gene){return _.includes(featureProperties.buckets,gene.toggle)}var _=lodash;return{mutate:function(featureProperties,gene){return isBucketGene(gene)&&containsGene(featureProperties,gene)?gene.toggle:pickOneElement(featureProperties.buckets)},containsMultivariant:function(featureProperties){return this.isBucketListValid(featureProperties.buckets)},isBucketListValid:function(bucketList){return _.isArray(bucketList)&&bucketList.length>=0}}}({});var define=amdefine(module);mutators_throttle=function(require){function getPercentageDecimal(throttle){var percentage=extractPercentage(throttle),value=percentage.substr(0,percentage.length-2);return value/10}function extractPercentage(throttle){var percentage;return percentage=isThrottleNode(throttle)?throttle.value:throttle}function isThrottleValid(throttle){return isThrottleNode(throttle)||isPercentage(throttle)}function isThrottleNode(throttle){return _.isPlainObject(throttle)&&_.isString(throttle.value)&&isPercentage(throttle.value)}function isPercentage(value){return!_.isUndefined(value)&&_.isString(value)&&value.match(/[0-100]%/)}function isThrottleGene(gene){return!_.isEmpty(gene)&&"throttle"===gene.type}function shouldMutate(throttle){return!_.isUndefined(throttle.mutate)&&"force"===throttle.mutate}var _=lodash;return{mutate:function(throttle,gene){if(!shouldMutate(throttle)&&isThrottleGene(gene))return gene.toggle;var percentage=getPercentageDecimal(throttle);return Math.random()<percentage},isThrottleValid:function(throttle){return isThrottleValid(throttle)}}}({});var define=amdefine(module);mutators_gene_pairing=function(require){function containTogglesPair(genes,featureName){return hasPartialName(_.keys(genes.toggles),featureName)}function containBucketsPair(genes,featureName){return hasPartialName(genes.buckets,featureName)}function containThrottlesPair(genes,featureName){return hasPartialName(genes.throttles,featureName)}function hasPartialName(featureNames,partialName){return findWithPartialName(featureNames,partialName).length>0}function findWithPartialName(featureNames,partialName){return _.filter(featureNames,function(featureName){return 0===featureName.indexOf(partialName)})}function getMatchingBucket(genes,featureName){var matchedFeatures=findWithPartialName(genes.buckets,featureName),matched=_.find(matchedFeatures,function(matchedBucket){return genes.toggles[matchedBucket]});return _.isString(matched)?getBucketNameFromFeatureName(matched):""}function getBucketNameFromFeatureName(featureName){var dotIndex=featureName.indexOf(".");return dotIndex>=0?featureName.substring(dotIndex+1):""}var _=lodash;return{pairGene:function(genes,featureName){var gene={};if(containTogglesPair(genes,featureName)){var type="toggle",name=genes.toggles[featureName];containBucketsPair(genes,featureName)?(type="bucket",name=getMatchingBucket(genes,featureName)):containThrottlesPair(genes,featureName)&&(type="throttle"),gene.toggle=name,gene.type=type}return gene}}}({});var define=amdefine(module);reactions_proof_reading=function(require){var _=lodash,bucketMutator=mutators_bucket,throttleMutator=mutators_throttle;return{areInstructionsValid:function(featureInstructions){var toggle=_.get(featureInstructions,"toggle"),throttle=_.get(featureInstructions,"throttle"),buckets=_.get(featureInstructions,"buckets");return this.isToggleValid(toggle)&&this.isThrottleValid(throttle)&&this.areBucketsValid(buckets)},isToggleValid:function(toggle){return _.isUndefined(toggle)||_.isBoolean(toggle)},isThrottleValid:function(throttle){return _.isUndefined(throttle)||throttleMutator.isThrottleValid(throttle)},areBucketsValid:function(buckets){return _.isUndefined(buckets)||bucketMutator.isBucketListValid(buckets)},checkFeatureInstructions:function(featureInstructions){var valid=_.isUndefined(featureInstructions)||_.isNull(featureInstructions)||!_.isArray(featureInstructions)&&_.isObject(featureInstructions);if(!valid)throw new Error("Invalid feature instructions!")}}}({});var define=amdefine(module);enzymes_polymerase=function(require){function addToFeatures(features,featureName,toggle){return features.push(_.merge({name:featureName},toggle))}function processFeatureInstructions(featureProperties,gene){var toggle={type:"toggle",toggle:!1};return featureProperties.toggle!==!1&&(throttleMutator.isThrottleValid(featureProperties.throttle)?(toggle.toggle=throttleMutator.mutate(featureProperties.throttle,gene),toggle.type="throttle"):featureProperties.toggle===!0&&(toggle.toggle=!0)),toggle}function containsBuckets(toggle,featureInstructions){return toggle.toggle&&bucketMutator.containsMultivariant(featureInstructions)}function addBucketToFeatures(features,featureName,featureInstructions,toggle,gene){var bucketName=bucketMutator.mutate(featureInstructions,gene),bucketToggle={toggle:toggle.toggle,type:"bucket"};addToFeatures(features,featureName+"."+bucketName,bucketToggle)}var _=lodash,bucketMutator=mutators_bucket,throttleMutator=mutators_throttle,genePairing=mutators_gene_pairing,proofReader=reactions_proof_reading;return{assembleFeatures:function(featureName,primerInstructions,ancestorGenes){var features=[];if(proofReader.areInstructionsValid(primerInstructions)){var gene=genePairing.pairGene(ancestorGenes,featureName),toggle=processFeatureInstructions(primerInstructions,gene);addToFeatures(features,featureName,toggle),containsBuckets(toggle,primerInstructions)&&addBucketToFeatures(features,featureName,primerInstructions,toggle,gene)}else addToFeatures(features,featureName,{toggle:!1,type:"toggle"});return features}}}({}),function(){var hasExports=(amdefine(module),"undefined"!=typeof module&&module.exports);muton=function(require){function joinToggles(features,resolvedFeatures){features.toggles=_.reduce(resolvedFeatures,function(result,elem){return result[elem.name]=elem.toggle,result},features.toggles)}function joinThrottles(features,resolvedFeatures){var buckets=_.chain(resolvedFeatures).filter({type:"bucket"}).pluck("name").value();features.buckets=features.buckets.concat(buckets)}function joinBuckets(features,resolvedFeatures){var throttles=_.chain(resolvedFeatures).filter({type:"throttle"}).pluck("name").value();features.throttles=features.throttles.concat(throttles)}function joinMutations(features,resolvedFeatures){joinToggles(features,resolvedFeatures),joinThrottles(features,resolvedFeatures),joinBuckets(features,resolvedFeatures)}var _=lodash,helicase=enzymes_helicase,primase=enzymes_primase,polymerase=enzymes_polymerase,proofReading=reactions_proof_reading,muton={getFeatureMutations:function(userProperties,featureInstructions){return this.getMutations(userProperties,featureInstructions).toggles},getMutations:function(userProperties,featureInstructions){return this.inheritMutations(userProperties,featureInstructions,{})},inheritMutations:function(userProperties,featureInstructions,ancestorGenes){var features={toggles:{},buckets:[],throttles:[]};return proofReading.checkFeatureInstructions(featureInstructions),_.forEach(featureInstructions,function(feature,featureName){var propertyChains=helicase.breakProperties(userProperties,feature),primer=primase.preparePrimer(userProperties,feature,propertyChains,!0),resolvedFeatures=polymerase.assembleFeatures(featureName,primer,ancestorGenes);joinMutations(features,resolvedFeatures)}),features}};return hasExports?exports=muton:this.muton=muton,muton}({})}.call(this)}(); | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.muton=r():t.muton=r()}(this,function(){return function(t){function r(e){if(n[e])return n[e].exports;var o=n[e]={exports:{},id:e,loaded:!1};return t[e].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var n={};return r.m=t,r.c=n,r.p="",r(0)}([function(t,r,n){function e(t,r){t.toggles=c(r,function(t,r){return t[r.name]=r.toggle,t},t.toggles)}function o(t,r){var n=f(r,{type:"bucket"}),e=a("name",n);t.buckets=t.buckets.concat(e)}function u(t,r){var n=f(r,{type:"throttle"}),e=a("name",n);t.throttles=t.throttles.concat(e)}function i(t,r){e(t,r),o(t,r),u(t,r)}var c=n(1),f=n(50),a=n(53),s=n(57),l=n(60),p=n(62),v=n(99),g=n(105),x={getFeatureMutations:function(t,r){return this.getMutations(t,r).toggles},getMutations:function(t,r){return this.inheritMutations(t,r,{})},inheritMutations:function(t,r,n){var e={toggles:{},buckets:[],throttles:[]};return g.checkFeatureInstructions(r),s(r,function(r,o){var u=l.breakProperties(t,r),c=p.preparePrimer(t,r,u,!0),f=v.assembleFeatures(o,c,n);i(e,f)}),e}};t.exports=x},function(t,r,n){var e=n(2),o=n(3),u=n(24),i=u(e,o);t.exports=i},function(t,r){function n(t,r,n,e){var o=-1,u=t.length;for(e&&u&&(n=t[++o]);++o<u;)n=r(n,t[o],o,t);return n}t.exports=n},function(t,r,n){var e=n(4),o=n(23),u=o(e);t.exports=u},function(t,r,n){function e(t,r){return o(t,r,u)}var o=n(5),u=n(9);t.exports=e},function(t,r,n){var e=n(6),o=e();t.exports=o},function(t,r,n){function e(t){return function(r,n,e){for(var u=o(r),i=e(r),c=i.length,f=t?c:-1;t?f--:++f<c;){var a=i[f];if(n(u[a],a,u)===!1)break}return r}}var o=n(7);t.exports=e},function(t,r,n){function e(t){return o(t)?t:Object(t)}var o=n(8);t.exports=e},function(t,r){function n(t){var r=typeof t;return!!t&&("object"==r||"function"==r)}t.exports=n},function(t,r,n){var e=n(10),o=n(14),u=n(8),i=n(18),c=e(Object,"keys"),f=c?function(t){var r=null==t?void 0:t.constructor;return"function"==typeof r&&r.prototype===t||"function"!=typeof t&&o(t)?i(t):u(t)?c(t):[]}:i;t.exports=f},function(t,r,n){function e(t,r){var n=null==t?void 0:t[r];return o(n)?n:void 0}var o=n(11);t.exports=e},function(t,r,n){function e(t){return null==t?!1:o(t)?s.test(f.call(t)):u(t)&&i.test(t)}var o=n(12),u=n(13),i=/^\[object .+?Constructor\]$/,c=Object.prototype,f=Function.prototype.toString,a=c.hasOwnProperty,s=RegExp("^"+f.call(a).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=e},function(t,r,n){function e(t){return o(t)&&c.call(t)==u}var o=n(8),u="[object Function]",i=Object.prototype,c=i.toString;t.exports=e},function(t,r){function n(t){return!!t&&"object"==typeof t}t.exports=n},function(t,r,n){function e(t){return null!=t&&u(o(t))}var o=n(15),u=n(17);t.exports=e},function(t,r,n){var e=n(16),o=e("length");t.exports=o},function(t,r){function n(t){return function(r){return null==r?void 0:r[t]}}t.exports=n},function(t,r){function n(t){return"number"==typeof t&&t>-1&&t%1==0&&e>=t}var e=9007199254740991;t.exports=n},function(t,r,n){function e(t){for(var r=f(t),n=r.length,e=n&&t.length,a=!!e&&c(e)&&(u(t)||o(t)),l=-1,p=[];++l<n;){var v=r[l];(a&&i(v,e)||s.call(t,v))&&p.push(v)}return p}var o=n(19),u=n(20),i=n(21),c=n(17),f=n(22),a=Object.prototype,s=a.hasOwnProperty;t.exports=e},function(t,r,n){function e(t){return u(t)&&o(t)&&c.call(t,"callee")&&!f.call(t,"callee")}var o=n(14),u=n(13),i=Object.prototype,c=i.hasOwnProperty,f=i.propertyIsEnumerable;t.exports=e},function(t,r,n){var e=n(10),o=n(17),u=n(13),i="[object Array]",c=Object.prototype,f=c.toString,a=e(Array,"isArray"),s=a||function(t){return u(t)&&o(t.length)&&f.call(t)==i};t.exports=s},function(t,r){function n(t,r){return t="number"==typeof t||e.test(t)?+t:-1,r=null==r?o:r,t>-1&&t%1==0&&r>t}var e=/^\d+$/,o=9007199254740991;t.exports=n},function(t,r,n){function e(t){if(null==t)return[];f(t)||(t=Object(t));var r=t.length;r=r&&c(r)&&(u(t)||o(t))&&r||0;for(var n=t.constructor,e=-1,a="function"==typeof n&&n.prototype===t,l=Array(r),p=r>0;++e<r;)l[e]=e+"";for(var v in t)p&&i(v,r)||"constructor"==v&&(a||!s.call(t,v))||l.push(v);return l}var o=n(19),u=n(20),i=n(21),c=n(17),f=n(8),a=Object.prototype,s=a.hasOwnProperty;t.exports=e},function(t,r,n){function e(t,r){return function(n,e){var c=n?o(n):0;if(!u(c))return t(n,e);for(var f=r?c:-1,a=i(n);(r?f--:++f<c)&&e(a[f],f,a)!==!1;);return n}}var o=n(15),u=n(17),i=n(7);t.exports=e},function(t,r,n){function e(t,r){return function(n,e,c,f){var a=arguments.length<3;return"function"==typeof e&&void 0===f&&i(n)?t(n,e,c,a):u(n,o(e,f,4),c,a,r)}}var o=n(25),u=n(49),i=n(20);t.exports=e},function(t,r,n){function e(t,r,n){var e=typeof t;return"function"==e?void 0===r?t:i(t,r,n):null==t?c:"object"==e?o(t):void 0===r?f(t):u(t,r)}var o=n(26),u=n(38),i=n(45),c=n(46),f=n(47);t.exports=e},function(t,r,n){function e(t){var r=u(t);if(1==r.length&&r[0][2]){var n=r[0][0],e=r[0][1];return function(t){return null==t?!1:t[n]===e&&(void 0!==e||n in i(t))}}return function(t){return o(t,r)}}var o=n(27),u=n(35),i=n(7);t.exports=e},function(t,r,n){function e(t,r,n){var e=r.length,i=e,c=!n;if(null==t)return!i;for(t=u(t);e--;){var f=r[e];if(c&&f[2]?f[1]!==t[f[0]]:!(f[0]in t))return!1}for(;++e<i;){f=r[e];var a=f[0],s=t[a],l=f[1];if(c&&f[2]){if(void 0===s&&!(a in t))return!1}else{var p=n?n(s,l,a):void 0;if(!(void 0===p?o(l,s,n,!0):p))return!1}}return!0}var o=n(28),u=n(7);t.exports=e},function(t,r,n){function e(t,r,n,c,f,a){return t===r?!0:null==t||null==r||!u(t)&&!i(r)?t!==t&&r!==r:o(t,r,e,n,c,f,a)}var o=n(29),u=n(8),i=n(13);t.exports=e},function(t,r,n){function e(t,r,n,e,p,x,h){var b=c(t),y=c(r),d=s,m=s;b||(d=g.call(t),d==a?d=l:d!=l&&(b=f(t))),y||(m=g.call(r),m==a?m=l:m!=l&&(y=f(r)));var j=d==l,O=m==l,k=d==m;if(k&&!b&&!j)return u(t,r,d);if(!p){var P=j&&v.call(t,"__wrapped__"),A=O&&v.call(r,"__wrapped__");if(P||A)return n(P?t.value():t,A?r.value():r,e,p,x,h)}if(!k)return!1;x||(x=[]),h||(h=[]);for(var w=x.length;w--;)if(x[w]==t)return h[w]==r;x.push(t),h.push(r);var V=(b?o:i)(t,r,n,e,p,x,h);return x.pop(),h.pop(),V}var o=n(30),u=n(32),i=n(33),c=n(20),f=n(34),a="[object Arguments]",s="[object Array]",l="[object Object]",p=Object.prototype,v=p.hasOwnProperty,g=p.toString;t.exports=e},function(t,r,n){function e(t,r,n,e,u,i,c){var f=-1,a=t.length,s=r.length;if(a!=s&&!(u&&s>a))return!1;for(;++f<a;){var l=t[f],p=r[f],v=e?e(u?p:l,u?l:p,f):void 0;if(void 0!==v){if(v)continue;return!1}if(u){if(!o(r,function(t){return l===t||n(l,t,e,u,i,c)}))return!1}else if(l!==p&&!n(l,p,e,u,i,c))return!1}return!0}var o=n(31);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=t.length;++n<e;)if(r(t[n],n,t))return!0;return!1}t.exports=n},function(t,r){function n(t,r,n){switch(n){case e:case o:return+t==+r;case u:return t.name==r.name&&t.message==r.message;case i:return t!=+t?r!=+r:t==+r;case c:case f:return t==r+""}return!1}var e="[object Boolean]",o="[object Date]",u="[object Error]",i="[object Number]",c="[object RegExp]",f="[object String]";t.exports=n},function(t,r,n){function e(t,r,n,e,u,c,f){var a=o(t),s=a.length,l=o(r),p=l.length;if(s!=p&&!u)return!1;for(var v=s;v--;){var g=a[v];if(!(u?g in r:i.call(r,g)))return!1}for(var x=u;++v<s;){g=a[v];var h=t[g],b=r[g],y=e?e(u?b:h,u?h:b,g):void 0;if(!(void 0===y?n(h,b,e,u,c,f):y))return!1;x||(x="constructor"==g)}if(!x){var d=t.constructor,m=r.constructor;if(d!=m&&"constructor"in t&&"constructor"in r&&!("function"==typeof d&&d instanceof d&&"function"==typeof m&&m instanceof m))return!1}return!0}var o=n(9),u=Object.prototype,i=u.hasOwnProperty;t.exports=e},function(t,r,n){function e(t){return u(t)&&o(t.length)&&!!E[S.call(t)]}var o=n(17),u=n(13),i="[object Arguments]",c="[object Array]",f="[object Boolean]",a="[object Date]",s="[object Error]",l="[object Function]",p="[object Map]",v="[object Number]",g="[object Object]",x="[object RegExp]",h="[object Set]",b="[object String]",y="[object WeakMap]",d="[object ArrayBuffer]",m="[object Float32Array]",j="[object Float64Array]",O="[object Int8Array]",k="[object Int16Array]",P="[object Int32Array]",A="[object Uint8Array]",w="[object Uint8ClampedArray]",V="[object Uint16Array]",R="[object Uint32Array]",E={};E[m]=E[j]=E[O]=E[k]=E[P]=E[A]=E[w]=E[V]=E[R]=!0,E[i]=E[c]=E[d]=E[f]=E[a]=E[s]=E[l]=E[p]=E[v]=E[g]=E[x]=E[h]=E[b]=E[y]=!1;var M=Object.prototype,S=M.toString;t.exports=e},function(t,r,n){function e(t){for(var r=u(t),n=r.length;n--;)r[n][2]=o(r[n][1]);return r}var o=n(36),u=n(37);t.exports=e},function(t,r,n){function e(t){return t===t&&!o(t)}var o=n(8);t.exports=e},function(t,r,n){function e(t){t=u(t);for(var r=-1,n=o(t),e=n.length,i=Array(e);++r<e;){var c=n[r];i[r]=[c,t[c]]}return i}var o=n(9),u=n(7);t.exports=e},function(t,r,n){function e(t,r){var n=c(t),e=f(t)&&a(r),v=t+"";return t=p(t),function(c){if(null==c)return!1;var f=v;if(c=l(c),(n||!e)&&!(f in c)){if(c=1==t.length?c:o(c,i(t,0,-1)),null==c)return!1;f=s(t),c=l(c)}return c[f]===r?void 0!==r||f in c:u(r,c[f],void 0,!0)}}var o=n(39),u=n(28),i=n(40),c=n(20),f=n(41),a=n(36),s=n(42),l=n(7),p=n(43);t.exports=e},function(t,r,n){function e(t,r,n){if(null!=t){void 0!==n&&n in o(t)&&(r=[n]);for(var e=0,u=r.length;null!=t&&u>e;)t=t[r[e++]];return e&&e==u?t:void 0}}var o=n(7);t.exports=e},function(t,r){function n(t,r,n){var e=-1,o=t.length;r=null==r?0:+r||0,0>r&&(r=-r>o?0:o+r),n=void 0===n||n>o?o:+n||0,0>n&&(n+=o),o=r>n?0:n-r>>>0,r>>>=0;for(var u=Array(o);++e<o;)u[e]=t[e+r];return u}t.exports=n},function(t,r,n){function e(t,r){var n=typeof t;if("string"==n&&c.test(t)||"number"==n)return!0;if(o(t))return!1;var e=!i.test(t);return e||null!=r&&t in u(r)}var o=n(20),u=n(7),i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,c=/^\w*$/;t.exports=e},function(t,r){function n(t){var r=t?t.length:0;return r?t[r-1]:void 0}t.exports=n},function(t,r,n){function e(t){if(u(t))return t;var r=[];return o(t).replace(i,function(t,n,e,o){r.push(e?o.replace(c,"$1"):n||t)}),r}var o=n(44),u=n(20),i=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g,c=/\\(\\)?/g;t.exports=e},function(t,r){function n(t){return null==t?"":t+""}t.exports=n},function(t,r,n){function e(t,r,n){if("function"!=typeof t)return o;if(void 0===r)return t;switch(n){case 1:return function(n){return t.call(r,n)};case 3:return function(n,e,o){return t.call(r,n,e,o)};case 4:return function(n,e,o,u){return t.call(r,n,e,o,u)};case 5:return function(n,e,o,u,i){return t.call(r,n,e,o,u,i)}}return function(){return t.apply(r,arguments)}}var o=n(46);t.exports=e},function(t,r){function n(t){return t}t.exports=n},function(t,r,n){function e(t){return i(t)?o(t):u(t)}var o=n(16),u=n(48),i=n(41);t.exports=e},function(t,r,n){function e(t){var r=t+"";return t=u(t),function(n){return o(n,t,r)}}var o=n(39),u=n(43);t.exports=e},function(t,r){function n(t,r,n,e,o){return o(t,function(t,o,u){n=e?(e=!1,t):r(n,t,o,u)}),n}t.exports=n},function(t,r,n){function e(t,r,n){var e=c(t)?o:i;return r=u(r,n,3),e(t,r)}var o=n(51),u=n(25),i=n(52),c=n(20);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=t.length,o=-1,u=[];++n<e;){var i=t[n];r(i,n,t)&&(u[++o]=i)}return u}t.exports=n},function(t,r,n){function e(t,r){var n=[];return o(t,function(t,e,o){r(t,e,o)&&n.push(t)}),n}var o=n(3);t.exports=e},function(t,r,n){function e(t,r){return o(t,u(r))}var o=n(54),u=n(47);t.exports=e},function(t,r,n){function e(t,r,n){var e=c(t)?o:i;return r=u(r,n,3),e(t,r)}var o=n(55),u=n(25),i=n(56),c=n(20);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=t.length,o=Array(e);++n<e;)o[n]=r(t[n],n,t);return o}t.exports=n},function(t,r,n){function e(t,r){var n=-1,e=u(t)?Array(t.length):[];return o(t,function(t,o,u){e[++n]=r(t,o,u)}),e}var o=n(3),u=n(14);t.exports=e},function(t,r,n){var e=n(58),o=n(3),u=n(59),i=u(e,o);t.exports=i},function(t,r){function n(t,r){for(var n=-1,e=t.length;++n<e&&r(t[n],n,t)!==!1;);return t}t.exports=n},function(t,r,n){function e(t,r){return function(n,e,i){return"function"==typeof e&&void 0===i&&u(n)?t(n,e):r(n,o(e,i,3))}}var o=n(45),u=n(20);t.exports=e},function(t,r,n){"use strict";var e=n(61);t.exports={breakProperties:function(t,r){return e.separateProperties(t,r)}}},function(t,r,n){"use strict";var e=n(9);t.exports={separateProperties:function(t,r){return{userPropertyNames:e(t),featurePropertyNames:e(r)}}}},function(t,r,n){"use strict";function e(t){return l(t,["toggle","throttle","buckets"])}function o(t,r){var n=e(r);p(t,n)}function u(t,r){var n=s(t,"toggle");return r&&n===!1}function i(t){return v(t,"toggle")||v(t,"throttle")||v(t,"buckets")}function c(t,r){return g(t)?r:t}function f(t,r,n){var e=n[r],o=t[r],u=b.getMatchedProperties(o,e);return c(u,e)}function a(t,r){p(t,r)}var s=n(63),l=n(64),p=n(71),v=n(80),g=n(81),x=n(82),h=n(61),b=n(89);t.exports={preparePrimer:function(t,r,n,e){var c=this,s={},l=n.userPropertyNames,p=n.featurePropertyNames;return i(r)&&o(s,r),u(s,e)||p.forEach(function(n){if(x(l,n)){var e=f(t,n,r),o=h.separateProperties(t,e),u=c.preparePrimer(t,e,o);a(s,u)}}),s}}},function(t,r,n){function e(t,r,n){var e=null==t?void 0:o(t,u(r),r+"");return void 0===e?n:e}var o=n(39),u=n(43);t.exports=e},function(t,r,n){var e=n(65),o=n(45),u=n(67),i=n(68),c=n(70),f=c(function(t,r){return null==t?{}:"function"==typeof r[0]?i(t,o(r[0],r[1],3)):u(t,e(r))});t.exports=f},function(t,r,n){function e(t,r,n,a){a||(a=[]);for(var s=-1,l=t.length;++s<l;){var p=t[s];f(p)&&c(p)&&(n||i(p)||u(p))?r?e(p,r,n,a):o(a,p):n||(a[a.length]=p)}return a}var o=n(66),u=n(19),i=n(20),c=n(14),f=n(13);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=r.length,o=t.length;++n<e;)t[o+n]=r[n];return t}t.exports=n},function(t,r,n){function e(t,r){t=o(t);for(var n=-1,e=r.length,u={};++n<e;){var i=r[n];i in t&&(u[i]=t[i])}return u}var o=n(7);t.exports=e},function(t,r,n){function e(t,r){var n={};return o(t,function(t,e,o){r(t,e,o)&&(n[e]=t)}),n}var o=n(69);t.exports=e},function(t,r,n){function e(t,r){return o(t,r,u)}var o=n(5),u=n(22);t.exports=e},function(t,r){function n(t,r){if("function"!=typeof t)throw new TypeError(e);return r=o(void 0===r?t.length-1:+r||0,0),function(){for(var n=arguments,e=-1,u=o(n.length-r,0),i=Array(u);++e<u;)i[e]=n[r+e];switch(r){case 0:return t.call(this,i);case 1:return t.call(this,n[0],i);case 2:return t.call(this,n[0],n[1],i)}var c=Array(r+1);for(e=-1;++e<r;)c[e]=n[e];return c[r]=i,t.apply(this,c)}}var e="Expected a function",o=Math.max;t.exports=n},function(t,r,n){var e=n(72),o=n(78),u=o(e);t.exports=u},function(t,r,n){function e(t,r,n,p,v){if(!f(t))return t;var g=c(r)&&(i(r)||s(r)),x=g?void 0:l(r);return o(x||r,function(o,i){if(x&&(i=o,o=r[i]),a(o))p||(p=[]),v||(v=[]),u(t,r,i,e,n,p,v);else{var c=t[i],f=n?n(c,o,i,t,r):void 0,s=void 0===f;s&&(f=o),void 0===f&&(!g||i in t)||!s&&(f===f?f===c:c!==c)||(t[i]=f)}}),t}var o=n(58),u=n(73),i=n(20),c=n(14),f=n(8),a=n(13),s=n(34),l=n(9);t.exports=e},function(t,r,n){function e(t,r,n,e,l,p,v){for(var g=p.length,x=r[n];g--;)if(p[g]==x)return void(t[n]=v[g]);var h=t[n],b=l?l(h,x,n,t,r):void 0,y=void 0===b;y&&(b=x,c(x)&&(i(x)||a(x))?b=i(h)?h:c(h)?o(h):[]:f(x)||u(x)?b=u(h)?s(h):f(h)?h:{}:y=!1),p.push(x),v.push(b),y?t[n]=e(b,x,l,p,v):(b===b?b!==h:h===h)&&(t[n]=b)}var o=n(74),u=n(19),i=n(20),c=n(14),f=n(75),a=n(34),s=n(76);t.exports=e},function(t,r){function n(t,r){var n=-1,e=t.length;for(r||(r=Array(e));++n<e;)r[n]=t[n];return r}t.exports=n},function(t,r,n){function e(t){var r;if(!i(t)||s.call(t)!=c||u(t)||!a.call(t,"constructor")&&(r=t.constructor,"function"==typeof r&&!(r instanceof r)))return!1;var n;return o(t,function(t,r){n=r}),void 0===n||a.call(t,n)}var o=n(69),u=n(19),i=n(13),c="[object Object]",f=Object.prototype,a=f.hasOwnProperty,s=f.toString;t.exports=e},function(t,r,n){function e(t){return o(t,u(t))}var o=n(77),u=n(22);t.exports=e},function(t,r){function n(t,r,n){n||(n={});for(var e=-1,o=r.length;++e<o;){var u=r[e];n[u]=t[u]}return n}t.exports=n},function(t,r,n){function e(t){return i(function(r,n){var e=-1,i=null==r?0:n.length,c=i>2?n[i-2]:void 0,f=i>2?n[2]:void 0,a=i>1?n[i-1]:void 0;for("function"==typeof c?(c=o(c,a,5),i-=2):(c="function"==typeof a?a:void 0,i-=c?1:0),f&&u(n[0],n[1],f)&&(c=3>i?void 0:c,i=1);++e<i;){var s=n[e];s&&t(r,s,c)}return r})}var o=n(45),u=n(79),i=n(70);t.exports=e},function(t,r,n){function e(t,r,n){if(!i(n))return!1;var e=typeof r;if("number"==e?o(n)&&u(r,n.length):"string"==e&&r in n){var c=n[r];return t===t?t===c:c!==c}return!1}var o=n(14),u=n(21),i=n(8);t.exports=e},function(t,r,n){function e(t,r){if(null==t)return!1;var n=g.call(t,r);if(!n&&!a(r)){if(r=p(r),t=1==r.length?t:o(t,u(r,0,-1)),null==t)return!1;r=l(r),n=g.call(t,r)}return n||s(t.length)&&f(r,t.length)&&(c(t)||i(t))}var o=n(39),u=n(40),i=n(19),c=n(20),f=n(21),a=n(41),s=n(17),l=n(42),p=n(43),v=Object.prototype,g=v.hasOwnProperty;t.exports=e},function(t,r){function n(t){return void 0===t}t.exports=n},function(t,r,n){t.exports=n(83)},function(t,r,n){function e(t,r,n,e){var p=t?u(t):0;return f(p)||(t=s(t),p=t.length),n="number"!=typeof n||e&&c(r,n,e)?0:0>n?l(p+n,0):n||0,"string"==typeof t||!i(t)&&a(t)?p>=n&&t.indexOf(r,n)>-1:!!p&&o(t,r,n)>-1}var o=n(84),u=n(15),i=n(20),c=n(79),f=n(17),a=n(86),s=n(87),l=Math.max;t.exports=e},function(t,r,n){function e(t,r,n){if(r!==r)return o(t,n);for(var e=n-1,u=t.length;++e<u;)if(t[e]===r)return e;return-1}var o=n(85);t.exports=e},function(t,r){function n(t,r,n){for(var e=t.length,o=r+(n?0:-1);n?o--:++o<e;){var u=t[o];if(u!==u)return o}return-1}t.exports=n},function(t,r,n){function e(t){return"string"==typeof t||o(t)&&c.call(t)==u}var o=n(13),u="[object String]",i=Object.prototype,c=i.toString;t.exports=e},function(t,r,n){function e(t){return o(t,u(t))}var o=n(88),u=n(9);t.exports=e},function(t,r){function n(t,r){for(var n=-1,e=r.length,o=Array(e);++n<e;)o[n]=t[r[n]];return o}t.exports=n},function(t,r,n){"use strict";function e(t,r){return u.isRegex(r)?u:i.isNumber(t)&&i.isNumericQuantifier(r)?i:c}var o=n(90),u=n(97),i=n(98),c={matchesPropertyValue:function(t,r){return t===r}};t.exports={getMatchedProperties:function(t,r){return o(r,function(r,n){var o=e(t,n);return o.matchesPropertyValue(t,n)})}}},function(t,r,n){var e=n(91),o=n(94),u=o(e,!0);t.exports=u},function(t,r,n){var e=n(92),o=n(23),u=o(e,!0);t.exports=u},function(t,r,n){function e(t,r){return o(t,r,u)}var o=n(93),u=n(9);t.exports=e},function(t,r,n){var e=n(6),o=e(!0);t.exports=o},function(t,r,n){function e(t,r){return function(n,e,f){if(e=o(e,f,3),c(n)){var a=i(n,e,r);return a>-1?n[a]:void 0}return u(n,e,t)}}var o=n(25),u=n(95),i=n(96),c=n(20);t.exports=e},function(t,r){function n(t,r,n,e){var o;return n(t,function(t,n,u){return r(t,n,u)?(o=e?n:t,!1):void 0}),o}t.exports=n},function(t,r){function n(t,r,n){for(var e=t.length,o=n?e:-1;n?o--:++o<e;)if(r(t[o],o,t))return o;return-1}t.exports=n},function(t,r){"use strict";function n(t){return t.substring(1,t.length-1)}var e=/^\/.+\/$/;t.exports={isRegex:function(t){return e.test(t)},matchesPropertyValue:function(t,r){var e=n(r),o=new RegExp("^"+e+"$");return o.test(t)}}},function(module,exports){"use strict";function isExpressionValid(t){return validExpressionRegex.test(t)}var numberRegex=/-?\d+(\.\d{1,2})?/,operatorRegex=/[><]=?/,numericQuantifierRegex=new RegExp(operatorRegex.source+numberRegex.source),validExpressionRegex=new RegExp(numberRegex.source+operatorRegex.source+numberRegex.source);module.exports={isNumber:function(t){return numberRegex.test(t)},isNumericQuantifier:function(t){return numericQuantifierRegex.test(t)},matchesPropertyValue:function(propertyValue,numericQuantifierStr){var expression=propertyValue+numericQuantifierStr;return isExpressionValid(expression)?eval(expression):!1}}},function(t,r,n){"use strict";function e(t,r,n){return t.push(c({name:r},n))}function o(t,r){var n={type:"toggle",toggle:!1};return t.toggle!==!1&&(a.isThrottleValid(t.throttle)?(n.toggle=a.mutate(t.throttle,r),n.type="throttle"):t.toggle===!0&&(n.toggle=!0)),n}function u(t,r){return t.toggle&&f.containsMultivariant(r)}function i(t,r,n,o,u){var i=f.mutate(n,u),c={toggle:o.toggle,type:"bucket"};e(t,r+"."+i,c)}var c=n(71),f=n(100),a=n(102),s=n(103),l=n(105);t.exports={assembleFeatures:function(t,r,n){var c=[];if(l.areInstructionsValid(r)){var f=s.pairGene(n,t),a=o(r,f);e(c,t,a),u(a,r)&&i(c,t,r,a,f)}else e(c,t,{toggle:!1,type:"toggle"});return c}}},function(t,r,n){"use strict";function e(t){if(!i(t))throw"Not an array!";var r=Math.floor(Math.random()*t.length);return t[r]}function o(t){return!c(t)&&"bucket"===t.type}function u(t,r){return f(t.buckets,r.toggle)}var i=n(20),c=n(101),f=n(83);t.exports={mutate:function(t,r){return o(r)&&u(t,r)?r.toggle:e(t.buckets)},containsMultivariant:function(t){return this.isBucketListValid(t.buckets)},isBucketListValid:function(t){return i(t)&&t.length>=0}}},function(t,r,n){function e(t){return null==t?!0:i(t)&&(u(t)||a(t)||o(t)||f(t)&&c(t.splice))?!t.length:!s(t).length}var o=n(19),u=n(20),i=n(14),c=n(12),f=n(13),a=n(86),s=n(9);t.exports=e},function(t,r,n){"use strict";function e(t){return!s(t)&&l(t)&&t.match(/[0-100]%/)}function o(t){return p(t)&&l(t.value)&&e(t.value)}function u(t){var r;return r=o(t)?t.value:t}function i(t){var r=u(t),n=r.substr(0,r.length-2);return n/10}function c(t){return o(t)||e(t)}function f(t){return!v(t)&&"throttle"===t.type}function a(t){return!s(t.mutate)&&"force"===t.mutate}var s=n(81),l=n(86),p=n(75),v=n(101);t.exports={mutate:function(t,r){if(!a(t)&&f(r))return r.toggle;var n=i(t);return Math.random()<n},isThrottleValid:function(t){return c(t)}}},function(t,r,n){"use strict";function e(t,r){return s(t,function(t){return 0===t.indexOf(r)})}function o(t,r){return e(t,r).length>0}function u(t,r){return o(p(t.toggles),r)}function i(t,r){return o(t.buckets,r)}function c(t,r){return o(t.throttles,r)}function f(t){var r=t.indexOf(".");return r>=0?t.substring(r+1):""}function a(t,r){var n=e(t.buckets,r),o=l(n,function(r){return t.toggles[r]});return v(o)?f(o):""}var s=n(50),l=n(104),p=n(9),v=n(86);t.exports={pairGene:function(t,r){var n={};if(u(t,r)){var e="toggle",o=t.toggles[r];i(t,r)?(e="bucket",o=a(t,r)):c(t,r)&&(e="throttle"),n.toggle=o,n.type=e}return n}}},function(t,r,n){var e=n(3),o=n(94),u=o(e);t.exports=u},function(t,r,n){"use strict";var e=n(63),o=n(81),u=n(106),i=n(107),c=n(20),f=n(8),a=n(100),s=n(102);t.exports={areInstructionsValid:function(t){var r=e(t,"toggle"),n=e(t,"throttle"),o=e(t,"buckets");return this.isToggleValid(r)&&this.isThrottleValid(n)&&this.areBucketsValid(o)},isToggleValid:function(t){return o(t)||u(t)},isThrottleValid:function(t){return o(t)||s.isThrottleValid(t)},areBucketsValid:function(t){return o(t)||a.isBucketListValid(t)},checkFeatureInstructions:function(t){var r=o(t)||i(t)||!c(t)&&f(t);if(!r)throw new Error("Invalid feature instructions!")}}},function(t,r,n){function e(t){return t===!0||t===!1||o(t)&&c.call(t)==u}var o=n(13),u="[object Boolean]",i=Object.prototype,c=i.toString;t.exports=e},function(t,r){function n(t){return null===t}t.exports=n}])}); |
{ | ||
"name": "muton", | ||
"version": "0.2.0", | ||
"version": "0.3.1", | ||
"description": "A feature toggling/throttling and multivariate testing tool", | ||
@@ -27,3 +27,2 @@ "main": "src/muton.js", | ||
"devDependencies": { | ||
"amdclean": "^2.7.0", | ||
"blanket": "^1.1.6", | ||
@@ -43,3 +42,3 @@ "chai": "^2.1.1", | ||
"grunt-mocha-istanbul": "^2.4.0", | ||
"grunt-requirejs": "^0.4.2", | ||
"grunt-webpack": "^1.0.11", | ||
"istanbul": "^0.3.13", | ||
@@ -50,8 +49,9 @@ "jshint-stylish": "^1.0.1", | ||
"sinon": "^1.14.1", | ||
"time-grunt": "^1.1.0" | ||
"time-grunt": "^1.1.0", | ||
"webpack": "^1.12.12", | ||
"webpack-dev-server": "^1.14.1" | ||
}, | ||
"dependencies": { | ||
"amdefine": "^0.1.0", | ||
"lodash": "^3.7.0" | ||
} | ||
} |
@@ -28,6 +28,2 @@ Muton | ||
### Dependencies | ||
muton depends on [lodash](https://https://lodash.com/). Please ensure that it's available in your enviroment. | ||
### NPM | ||
@@ -316,4 +312,7 @@ | ||
- Return muton on define call to ensure that it's correctly exported | ||
* 0.3.0 | ||
- Replace requirejs with Webpack | ||
- Include used lodash functions in the final bundle, to avoid dependency conflicts between projects. | ||
[npm-url]: https://npmjs.org/package/muton | ||
[npm-image]: https://badge.fury.io/js/muton.svg |
@@ -8,24 +8,17 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
define(function (require) { | ||
var chemicalReactions = require('../reactions/chemical.js'); | ||
var chemicalReactions = require('../reactions/chemical.js'); | ||
return { | ||
/** | ||
* Returns an object containing two strands: one containing the user properties names and the other containing | ||
* the features names. | ||
* | ||
* @param userProperties a dictionary with user properties | ||
* @param feature a dictionary with features instructions | ||
* @returns An object that contains user property names and features names | ||
*/ | ||
breakProperties: function (userProperties, feature) { | ||
return chemicalReactions.separateProperties(userProperties, feature); | ||
} | ||
}; | ||
}); | ||
module.exports = { | ||
/** | ||
* Returns an object containing two strands: one containing the user properties names and the other containing | ||
* the features names. | ||
* | ||
* @param userProperties a dictionary with user properties | ||
* @param feature a dictionary with features instructions | ||
* @returns An object that contains user property names and features names | ||
*/ | ||
breakProperties: function (userProperties, feature) { | ||
return chemicalReactions.separateProperties(userProperties, feature); | ||
} | ||
}; |
@@ -13,81 +13,75 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
var merge = require('lodash/object/merge'); | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
var bucketMutator = require('../mutators/bucket'); | ||
var throttleMutator = require('../mutators/throttle'); | ||
var genePairing = require('../mutators/gene-pairing'); | ||
var proofReader = require('../reactions/proof-reading'); | ||
var bucketMutator = require('../mutators/bucket'); | ||
var throttleMutator = require('../mutators/throttle'); | ||
var genePairing = require('../mutators/gene-pairing'); | ||
var proofReader = require('../reactions/proof-reading'); | ||
function addToFeatures(features, featureName, toggle) { | ||
return features.push(_.merge({ name: featureName }, toggle)); | ||
} | ||
function addToFeatures(features, featureName, toggle) { | ||
return features.push(merge({ name: featureName }, toggle)); | ||
} | ||
function processFeatureInstructions(featureProperties, gene) { | ||
var toggle = { | ||
type: 'toggle', | ||
toggle: false | ||
}; | ||
function processFeatureInstructions(featureProperties, gene) { | ||
var toggle = { | ||
type: 'toggle', | ||
toggle: false | ||
}; | ||
if (featureProperties.toggle !== false) { | ||
if (throttleMutator.isThrottleValid(featureProperties.throttle)) { | ||
toggle.toggle = throttleMutator.mutate(featureProperties.throttle, gene); | ||
toggle.type = 'throttle'; | ||
} else if (featureProperties.toggle === true) { | ||
toggle.toggle = true; | ||
} | ||
if (featureProperties.toggle !== false) { | ||
if (throttleMutator.isThrottleValid(featureProperties.throttle)) { | ||
toggle.toggle = throttleMutator.mutate(featureProperties.throttle, gene); | ||
toggle.type = 'throttle'; | ||
} else if (featureProperties.toggle === true) { | ||
toggle.toggle = true; | ||
} | ||
return toggle; | ||
} | ||
function containsBuckets(toggle, featureInstructions) { | ||
return toggle.toggle && bucketMutator.containsMultivariant(featureInstructions); | ||
} | ||
return toggle; | ||
} | ||
function addBucketToFeatures(features, featureName, featureInstructions, toggle, gene) { | ||
var bucketName = bucketMutator.mutate(featureInstructions, gene); | ||
function containsBuckets(toggle, featureInstructions) { | ||
return toggle.toggle && bucketMutator.containsMultivariant(featureInstructions); | ||
} | ||
var bucketToggle = { | ||
toggle : toggle.toggle, | ||
type : 'bucket' | ||
}; | ||
function addBucketToFeatures(features, featureName, featureInstructions, toggle, gene) { | ||
var bucketName = bucketMutator.mutate(featureInstructions, gene); | ||
addToFeatures(features, featureName + "." + bucketName, bucketToggle); | ||
} | ||
var bucketToggle = { | ||
toggle : toggle.toggle, | ||
type : 'bucket' | ||
}; | ||
return { | ||
/** | ||
* Returns a resolved feature toggle, with the information indicating whether it's active or not. If the | ||
* feature mutates to a bucket, it also can contain the corresponding feature toggle. | ||
* | ||
* @param featureName The feature name being processed | ||
* @param primerInstructions The primer instructions to process | ||
* @returns A resolved feature toggle, which may mutate to a bucket feature toggle | ||
* @param ancestorGenes An object containing 'genes' to inherit, this only applies to throttles and buckets | ||
*/ | ||
assembleFeatures: function(featureName, primerInstructions, ancestorGenes) { | ||
var features = []; | ||
addToFeatures(features, featureName + "." + bucketName, bucketToggle); | ||
} | ||
if (proofReader.areInstructionsValid(primerInstructions)) { | ||
module.exports = { | ||
/** | ||
* Returns a resolved feature toggle, with the information indicating whether it's active or not. If the | ||
* feature mutates to a bucket, it also can contain the corresponding feature toggle. | ||
* | ||
* @param featureName The feature name being processed | ||
* @param primerInstructions The primer instructions to process | ||
* @returns A resolved feature toggle, which may mutate to a bucket feature toggle | ||
* @param ancestorGenes An object containing 'genes' to inherit, this only applies to throttles and buckets | ||
*/ | ||
assembleFeatures: function(featureName, primerInstructions, ancestorGenes) { | ||
var features = []; | ||
// Get the ancestor gene based on name to be able to copy it to the descendant | ||
var gene = genePairing.pairGene(ancestorGenes, featureName); | ||
if (proofReader.areInstructionsValid(primerInstructions)) { | ||
var toggle = processFeatureInstructions(primerInstructions, gene); | ||
addToFeatures(features, featureName, toggle); | ||
// Get the ancestor gene based on name to be able to copy it to the descendant | ||
var gene = genePairing.pairGene(ancestorGenes, featureName); | ||
if (containsBuckets(toggle, primerInstructions)) { | ||
addBucketToFeatures(features, featureName, primerInstructions, toggle, gene); | ||
} | ||
} else { | ||
addToFeatures(features, featureName, { toggle: false, type: 'toggle' }); | ||
var toggle = processFeatureInstructions(primerInstructions, gene); | ||
addToFeatures(features, featureName, toggle); | ||
if (containsBuckets(toggle, primerInstructions)) { | ||
addBucketToFeatures(features, featureName, primerInstructions, toggle, gene); | ||
} | ||
return features; | ||
} else { | ||
addToFeatures(features, featureName, { toggle: false, type: 'toggle' }); | ||
} | ||
}; | ||
}); | ||
return features; | ||
} | ||
}; |
@@ -8,87 +8,86 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
var get = require('lodash/object/get'); | ||
var pick = require('lodash/object/pick'); | ||
var merge = require('lodash/object/merge'); | ||
var has = require('lodash/object/has'); | ||
var isUndefined = require('lodash/lang/isUndefined'); | ||
var contains = require('lodash/collection/contains'); | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
var chemicalReactions = require('../reactions/chemical.js'); | ||
var matchReading = require('../reactions/match-reading.js'); | ||
var chemicalReactions = require('../reactions/chemical.js'); | ||
var matchReading = require('../reactions/match-reading.js'); | ||
function mergeProperties(primer, feature) { | ||
var properties = getFeatureProperties(feature); | ||
_.merge(primer, properties); | ||
} | ||
function getFeatureProperties(feature) { | ||
return pick(feature, ['toggle', 'throttle', 'buckets']); | ||
} | ||
function isFeatureDisabled(primer, root) { | ||
var toggle = _.get(primer, 'toggle'); | ||
return root && toggle === false; | ||
} | ||
function mergeProperties(primer, feature) { | ||
var properties = getFeatureProperties(feature); | ||
merge(primer, properties); | ||
} | ||
function getFeatureProperties(feature) { | ||
return _.pick(feature, ['toggle', 'throttle', 'buckets']); | ||
} | ||
function isFeatureDisabled(primer, root) { | ||
var toggle = get(primer, 'toggle'); | ||
return root && toggle === false; | ||
} | ||
function containsFeatureProperties(obj) { | ||
return _.has(obj, 'toggle') || _.has(obj, 'throttle') || _.has(obj, 'buckets'); | ||
} | ||
function containsFeatureProperties(obj) { | ||
return has(obj, 'toggle') || has(obj, 'throttle') || has(obj, 'buckets'); | ||
} | ||
function getPropertiesNode(userProperties, featurePropertyName, feature) { | ||
// Explode the current node to check if there are properties | ||
var featureProperty = feature[featurePropertyName]; | ||
function pickMatchedProperties(childProperties, parentProperties) { | ||
return !isUndefined(childProperties) ? childProperties : parentProperties; | ||
} | ||
var userPropertyValue = userProperties[featurePropertyName]; | ||
var properties = matchReading.getMatchedProperties(userPropertyValue, featureProperty); | ||
function getPropertiesNode(userProperties, featurePropertyName, feature) { | ||
// Explode the current node to check if there are properties | ||
var featureProperty = feature[featurePropertyName]; | ||
return pickMatchedProperties(properties, featureProperty); | ||
} | ||
var userPropertyValue = userProperties[featurePropertyName]; | ||
var properties = matchReading.getMatchedProperties(userPropertyValue, featureProperty); | ||
function pickMatchedProperties(childProperties, parentProperties) { | ||
return !_.isUndefined(childProperties) ? childProperties : parentProperties; | ||
} | ||
return pickMatchedProperties(properties, featureProperty); | ||
} | ||
function bindPrimer(primerInstructions, childPrimer) { | ||
_.merge(primerInstructions, childPrimer); | ||
} | ||
function bindPrimer(primerInstructions, childPrimer) { | ||
merge(primerInstructions, childPrimer); | ||
} | ||
return { | ||
/** | ||
* Returns a primer collection containing instructions to toggle on or off a feature, | ||
* matched against the user properties. | ||
* | ||
* @param userProperties The user properties to match the features | ||
* @param feature The feature being processed | ||
* @param propertyStrands An object with the strands containing user and features properties names | ||
* @param root A flag to indicate if the features tree is being processed in the root | ||
* @returns A collection of primer instructions matched against the user properties | ||
*/ | ||
preparePrimer: function(userProperties, feature, propertyStrands, root) { | ||
var self = this; | ||
var primerInstructions = {}; | ||
module.exports = { | ||
/** | ||
* Returns a primer collection containing instructions to toggle on or off a feature, | ||
* matched against the user properties. | ||
* | ||
* @param userProperties The user properties to match the features | ||
* @param feature The feature being processed | ||
* @param propertyStrands An object with the strands containing user and features properties names | ||
* @param root A flag to indicate if the features tree is being processed in the root | ||
* @returns A collection of primer instructions matched against the user properties | ||
*/ | ||
preparePrimer: function(userProperties, feature, propertyStrands, root) { | ||
var self = this; | ||
var primerInstructions = {}; | ||
var userPropertyNames = propertyStrands.userPropertyNames; | ||
var featurePropertyNames = propertyStrands.featurePropertyNames; | ||
var userPropertyNames = propertyStrands.userPropertyNames; | ||
var featurePropertyNames = propertyStrands.featurePropertyNames; | ||
// If are feature properties on the current node, it merges with the final result | ||
if (containsFeatureProperties(feature)) { | ||
mergeProperties(primerInstructions, feature); | ||
} | ||
// If are feature properties on the current node, it merges with the final result | ||
if (containsFeatureProperties(feature)) { | ||
mergeProperties(primerInstructions, feature); | ||
} | ||
if (!isFeatureDisabled(primerInstructions, root)) { | ||
featurePropertyNames.forEach(function (featurePropertyName) { | ||
if (_.contains(userPropertyNames, featurePropertyName)) { | ||
var propertiesNode = getPropertiesNode(userProperties, featurePropertyName, feature); | ||
// Process the child node | ||
var childStrands = chemicalReactions.separateProperties(userProperties, propertiesNode); | ||
var childPrimer = self.preparePrimer(userProperties, propertiesNode, childStrands); | ||
if (!isFeatureDisabled(primerInstructions, root)) { | ||
featurePropertyNames.forEach(function (featurePropertyName) { | ||
if (contains(userPropertyNames, featurePropertyName)) { | ||
var propertiesNode = getPropertiesNode(userProperties, featurePropertyName, feature); | ||
// Process the child node | ||
var childStrands = chemicalReactions.separateProperties(userProperties, propertiesNode); | ||
var childPrimer = self.preparePrimer(userProperties, propertiesNode, childStrands); | ||
bindPrimer(primerInstructions, childPrimer); | ||
} | ||
}); | ||
} | ||
bindPrimer(primerInstructions, childPrimer); | ||
} | ||
}); | ||
} | ||
return primerInstructions; | ||
} | ||
}; | ||
}); | ||
return primerInstructions; | ||
} | ||
}; |
@@ -7,46 +7,39 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
var isArray = require('lodash/lang/isArray'); | ||
var isEmpty = require('lodash/lang/isEmpty'); | ||
var includes = require('lodash/collection/includes'); | ||
function pickOneElement(array) { | ||
if (!isArray(array)) { | ||
throw 'Not an array!'; | ||
} | ||
var index = Math.floor(Math.random() * (array.length)); | ||
return array[index]; | ||
} | ||
define(function (require) { | ||
function isBucketGene(gene) { | ||
return !isEmpty(gene) && gene.type === 'bucket'; | ||
} | ||
var _ = require('lodash'); | ||
function containsGene(featureProperties, gene) { | ||
return includes(featureProperties.buckets, gene.toggle); | ||
} | ||
function pickOneElement(array) { | ||
if (!_.isArray(array)) { | ||
throw 'Not an array!'; | ||
module.exports = { | ||
mutate: function(featureProperties, gene) { | ||
if (isBucketGene(gene) && containsGene(featureProperties, gene)) { | ||
return gene.toggle; | ||
} else { | ||
return pickOneElement(featureProperties.buckets); | ||
} | ||
}, | ||
var index = Math.floor(Math.random() * (array.length)); | ||
return array[index]; | ||
} | ||
containsMultivariant: function(featureProperties) { | ||
return this.isBucketListValid(featureProperties.buckets); | ||
}, | ||
function isBucketGene(gene) { | ||
return !_.isEmpty(gene) && gene.type === 'bucket'; | ||
isBucketListValid: function(bucketList) { | ||
return isArray(bucketList) && bucketList.length >= 0; | ||
} | ||
function containsGene(featureProperties, gene) { | ||
return _.includes(featureProperties.buckets, gene.toggle); | ||
} | ||
return { | ||
mutate: function(featureProperties, gene) { | ||
if (isBucketGene(gene) && containsGene(featureProperties, gene)) { | ||
return gene.toggle; | ||
} else { | ||
return pickOneElement(featureProperties.buckets); | ||
} | ||
}, | ||
containsMultivariant: function(featureProperties) { | ||
return this.isBucketListValid(featureProperties.buckets); | ||
}, | ||
isBucketListValid: function(bucketList) { | ||
return _.isArray(bucketList) && bucketList.length >= 0; | ||
} | ||
}; | ||
}); | ||
}; |
'use strict'; | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
var filter = require('lodash/collection/filter'); | ||
var find = require('lodash/collection/find'); | ||
var keys = require('lodash/object/keys'); | ||
var isString = require('lodash/lang/isString'); | ||
function findWithPartialName(featureNames, partialName) { | ||
return filter(featureNames, function (featureName) { | ||
return featureName.indexOf(partialName) === 0; | ||
}); | ||
} | ||
define(function (require) { | ||
function hasPartialName(featureNames, partialName) { | ||
return findWithPartialName(featureNames, partialName).length > 0; | ||
} | ||
var _ = require('lodash'); | ||
function containTogglesPair(genes, featureName) { | ||
return hasPartialName(keys(genes.toggles), featureName); | ||
} | ||
function containTogglesPair(genes, featureName) { | ||
return hasPartialName(_.keys(genes.toggles), featureName); | ||
} | ||
function containBucketsPair(genes, featureName) { | ||
return hasPartialName(genes.buckets, featureName); | ||
} | ||
function containBucketsPair(genes, featureName) { | ||
return hasPartialName(genes.buckets, featureName); | ||
} | ||
function containThrottlesPair(genes, featureName) { | ||
return hasPartialName(genes.throttles, featureName); | ||
} | ||
function containThrottlesPair(genes, featureName) { | ||
return hasPartialName(genes.throttles, featureName); | ||
} | ||
function getBucketNameFromFeatureName(featureName) { | ||
var dotIndex = featureName.indexOf('.'); | ||
return dotIndex >= 0 ? featureName.substring(dotIndex + 1) : ''; | ||
} | ||
function hasPartialName(featureNames, partialName) { | ||
return findWithPartialName(featureNames, partialName).length > 0; | ||
} | ||
function findWithPartialName(featureNames, partialName) { | ||
return _.filter(featureNames, function (featureName) { | ||
return featureName.indexOf(partialName) === 0; | ||
function getMatchingBucket(genes, featureName) { | ||
var matchedFeatures = findWithPartialName(genes.buckets, featureName); | ||
var matched = find(matchedFeatures, function (matchedBucket) { | ||
return genes.toggles[matchedBucket]; | ||
}); | ||
} | ||
return isString(matched) ? getBucketNameFromFeatureName(matched) : ''; | ||
} | ||
function getMatchingBucket(genes, featureName) { | ||
var matchedFeatures = findWithPartialName(genes.buckets, featureName); | ||
var matched = _.find(matchedFeatures, function (matchedBucket) { | ||
return genes.toggles[matchedBucket]; | ||
}); | ||
return _.isString(matched) ? getBucketNameFromFeatureName(matched) : ''; | ||
} | ||
module.exports = { | ||
pairGene: function (genes, featureName) { | ||
var gene = {}; | ||
if (containTogglesPair(genes, featureName)) { | ||
var type = 'toggle'; | ||
var name = genes.toggles[featureName]; | ||
if (containBucketsPair(genes, featureName)) { | ||
type = 'bucket'; | ||
name = getMatchingBucket(genes, featureName); | ||
} else if (containThrottlesPair(genes, featureName)) { | ||
type = 'throttle'; | ||
} | ||
function getBucketNameFromFeatureName(featureName) { | ||
var dotIndex = featureName.indexOf('.'); | ||
return dotIndex >= 0 ? featureName.substring(dotIndex + 1) : ''; | ||
gene['toggle'] = name; | ||
gene['type'] = type; | ||
} | ||
return gene; | ||
} | ||
return { | ||
pairGene: function (genes, featureName) { | ||
var gene = {}; | ||
if (containTogglesPair(genes, featureName)) { | ||
var type = 'toggle'; | ||
var name = genes.toggles[featureName]; | ||
if (containBucketsPair(genes, featureName)) { | ||
type = 'bucket'; | ||
name = getMatchingBucket(genes, featureName); | ||
} else if (containThrottlesPair(genes, featureName)) { | ||
type = 'throttle'; | ||
} | ||
gene['toggle'] = name; | ||
gene['type'] = type; | ||
} | ||
return gene; | ||
} | ||
}; | ||
}); | ||
}; |
@@ -7,60 +7,56 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
var isUndefined = require('lodash/lang/isUndefined'); | ||
var isString = require('lodash/lang/isString'); | ||
var isPlainObject = require('lodash/lang/isPlainObject'); | ||
var isEmpty = require('lodash/lang/isEmpty'); | ||
function isPercentage(value) { | ||
return !isUndefined(value) && isString(value) && value.match(/[0-100]%/); | ||
} | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
function isThrottleNode(throttle) { | ||
return isPlainObject(throttle) && isString(throttle['value']) && isPercentage(throttle['value']); | ||
} | ||
function getPercentageDecimal(throttle) { | ||
var percentage = extractPercentage(throttle); | ||
var value = percentage.substr(0, percentage.length - 2); | ||
return value / 10; | ||
function extractPercentage(throttle) { | ||
var percentage; | ||
if (isThrottleNode(throttle)) { | ||
percentage = throttle['value']; | ||
} else { | ||
percentage = throttle; | ||
} | ||
return percentage; | ||
} | ||
function extractPercentage(throttle) { | ||
var percentage; | ||
if (isThrottleNode(throttle)) { | ||
percentage = throttle['value']; | ||
} else { | ||
percentage = throttle; | ||
} | ||
return percentage; | ||
} | ||
function getPercentageDecimal(throttle) { | ||
var percentage = extractPercentage(throttle); | ||
var value = percentage.substr(0, percentage.length - 2); | ||
return value / 10; | ||
} | ||
function isThrottleValid(throttle) { | ||
return isThrottleNode(throttle) || isPercentage(throttle); | ||
} | ||
function isThrottleValid(throttle) { | ||
return isThrottleNode(throttle) || isPercentage(throttle); | ||
} | ||
function isThrottleNode(throttle) { | ||
return _.isPlainObject(throttle) && _.isString(throttle['value']) && isPercentage(throttle['value']); | ||
} | ||
function isThrottleGene(gene) { | ||
return !isEmpty(gene) && gene.type === 'throttle'; | ||
} | ||
function isPercentage(value) { | ||
return !_.isUndefined(value) && _.isString(value) && value.match(/[0-100]%/); | ||
} | ||
function shouldMutate(throttle) { | ||
return !isUndefined(throttle['mutate']) && throttle['mutate'] === 'force'; | ||
} | ||
function isThrottleGene(gene) { | ||
return !_.isEmpty(gene) && gene.type === 'throttle'; | ||
} | ||
module.exports = { | ||
mutate: function (throttle, gene) { | ||
if (!shouldMutate(throttle) && isThrottleGene(gene)) { | ||
return gene.toggle; | ||
} else { | ||
var percentage = getPercentageDecimal(throttle); | ||
return Math.random() < percentage; | ||
} | ||
}, | ||
function shouldMutate(throttle) { | ||
return !_.isUndefined(throttle['mutate']) && throttle['mutate'] === 'force'; | ||
isThrottleValid: function (throttle) { | ||
return isThrottleValid(throttle); | ||
} | ||
return { | ||
mutate: function (throttle, gene) { | ||
if (!shouldMutate(throttle) && isThrottleGene(gene)) { | ||
return gene.toggle; | ||
} else { | ||
var percentage = getPercentageDecimal(throttle); | ||
return Math.random() < percentage; | ||
} | ||
}, | ||
isThrottleValid: function (throttle) { | ||
return isThrottleValid(throttle); | ||
} | ||
}; | ||
}); | ||
}; |
185
src/muton.js
@@ -26,122 +26,101 @@ /** | ||
(function () { | ||
var reduce = require('lodash/collection/reduce'); | ||
var filter = require('lodash/collection/filter'); | ||
var pluck = require('lodash/collection/pluck'); | ||
var forEach = require('lodash/collection/forEach'); | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
var helicase = require('./enzymes/helicase'); | ||
var primase = require('./enzymes/primase'); | ||
var polymerase = require('./enzymes/polymerase'); | ||
var proofReading = require('./reactions/proof-reading'); | ||
var hasExports = typeof module !== 'undefined' && module.exports; | ||
function joinToggles(features, resolvedFeatures) { | ||
features.toggles = reduce(resolvedFeatures, function (result, elem) { | ||
result[elem.name] = elem.toggle; | ||
return result; | ||
}, features.toggles); | ||
} | ||
/*jshint -W038*/ | ||
define(function (require) { | ||
function joinThrottles(features, resolvedFeatures) { | ||
var buckets = filter(resolvedFeatures, {type : 'bucket'}); | ||
var names = pluck('name', buckets); | ||
var _ = require('lodash'); | ||
var helicase = require('./enzymes/helicase'); | ||
var primase = require('./enzymes/primase'); | ||
var polymerase = require('./enzymes/polymerase'); | ||
var proofReading = require('./reactions/proof-reading'); | ||
features.buckets = features.buckets.concat(names); | ||
} | ||
function joinToggles(features, resolvedFeatures) { | ||
features.toggles = _.reduce(resolvedFeatures, function (result, elem) { | ||
result[elem.name] = elem.toggle; | ||
return result; | ||
}, features.toggles); | ||
} | ||
function joinBuckets(features, resolvedFeatures) { | ||
var throttles = filter(resolvedFeatures, {type : 'throttle'}); | ||
var names = pluck('name', throttles); | ||
function joinThrottles(features, resolvedFeatures) { | ||
var buckets = _.chain(resolvedFeatures) | ||
.filter({type : 'bucket'}) | ||
.pluck('name') | ||
.value(); | ||
features.buckets = features.buckets.concat(buckets); | ||
} | ||
features.throttles = features.throttles.concat(names); | ||
} | ||
function joinBuckets(features, resolvedFeatures) { | ||
var throttles = _.chain(resolvedFeatures) | ||
.filter({type : 'throttle'}) | ||
.pluck('name') | ||
.value(); | ||
features.throttles = features.throttles.concat(throttles); | ||
} | ||
function joinMutations(features, resolvedFeatures) { | ||
joinToggles(features, resolvedFeatures); | ||
joinThrottles(features, resolvedFeatures); | ||
joinBuckets(features, resolvedFeatures); | ||
} | ||
function joinMutations(features, resolvedFeatures) { | ||
joinToggles(features, resolvedFeatures); | ||
joinThrottles(features, resolvedFeatures); | ||
joinBuckets(features, resolvedFeatures); | ||
} | ||
var muton = { | ||
var muton = { | ||
/** | ||
* Given a list of user properties and feature instructions, it returns a collection of features toggles. | ||
* | ||
* @deprecated use getMutations or inheritMutations instead | ||
* | ||
* @param userProperties (optional) A collection of user properties | ||
* @param featureInstructions A collection of feature instructions which can be organized as a hierarchy of properties. | ||
* @returns An collection of feature toggles | ||
*/ | ||
getFeatureMutations: function (userProperties, featureInstructions) { | ||
return this.getMutations(userProperties, featureInstructions).toggles; | ||
}, | ||
/** | ||
* Given a list of user properties and feature instructions, it returns a collection of features toggles. | ||
* | ||
* @deprecated use getMutations or inheritMutations instead | ||
* | ||
* @param userProperties (optional) A collection of user properties | ||
* @param featureInstructions A collection of feature instructions which can be organized as a hierarchy of properties. | ||
* @returns An collection of feature toggles | ||
*/ | ||
getFeatureMutations: function (userProperties, featureInstructions) { | ||
return this.getMutations(userProperties, featureInstructions).toggles; | ||
}, | ||
/** | ||
* Given a list of user properties and feature instructions, it returns a collection of features toggles. | ||
* | ||
* @param userProperties (optional) A collection of user properties | ||
* @param featureInstructions A collection of feature instructions which can be organized as a hierarchy of properties. | ||
* @returns {{toggles: {}, buckets: Array, throttles: Array}} An collection of feature toggles | ||
*/ | ||
getMutations: function (userProperties, featureInstructions) { | ||
return this.inheritMutations(userProperties, featureInstructions, {}); | ||
}, | ||
/** | ||
* Given a list of user properties and feature instructions, it returns a collection of features toggles. | ||
* | ||
* @param userProperties (optional) A collection of user properties | ||
* @param featureInstructions A collection of feature instructions which can be organized as a hierarchy of properties. | ||
* @returns {{toggles: {}, buckets: Array, throttles: Array}} An collection of feature toggles | ||
*/ | ||
getMutations: function (userProperties, featureInstructions) { | ||
return this.inheritMutations(userProperties, featureInstructions, {}); | ||
}, | ||
/** | ||
* Given a list of user properties and feature instructions, it returns a collection of features toggles. If specified, | ||
* it can inherit ancestor genes for buckets and throttle mutations | ||
* | ||
* @param userProperties (optional) A collection of user properties | ||
* @param featureInstructions A collection of feature instructions which can be organized as a hierarchy of properties. | ||
* @param ancestorGenes (optional) The ancestor genes, which is the output of previous mutations from Muton | ||
* @returns {{toggles: {}, buckets: Array, throttles: Array}} An collection of feature toggles | ||
*/ | ||
inheritMutations: function (userProperties, featureInstructions, ancestorGenes) { | ||
var features = { | ||
toggles: {}, | ||
buckets: [], | ||
throttles: [] | ||
}; | ||
/** | ||
* Given a list of user properties and feature instructions, it returns a collection of features toggles. If specified, | ||
* it can inherit ancestor genes for buckets and throttle mutations | ||
* | ||
* @param userProperties (optional) A collection of user properties | ||
* @param featureInstructions A collection of feature instructions which can be organized as a hierarchy of properties. | ||
* @param ancestorGenes (optional) The ancestor genes, which is the output of previous mutations from Muton | ||
* @returns {{toggles: {}, buckets: Array, throttles: Array}} An collection of feature toggles | ||
*/ | ||
inheritMutations: function (userProperties, featureInstructions, ancestorGenes) { | ||
var features = { | ||
toggles: {}, | ||
buckets: [], | ||
throttles: [] | ||
}; | ||
proofReading.checkFeatureInstructions(featureInstructions); | ||
proofReading.checkFeatureInstructions(featureInstructions); | ||
forEach(featureInstructions, function (feature, featureName) { | ||
// Helicase will break the user properties and features apart into two different chains | ||
var propertyChains = helicase.breakProperties(userProperties, feature); | ||
_.forEach(featureInstructions, function (feature, featureName) { | ||
// Helicase will break the user properties and features apart into two different chains | ||
var propertyChains = helicase.breakProperties(userProperties, feature); | ||
// Read the chains and return a primer object that will contain a set of instructions | ||
var primer = primase.preparePrimer(userProperties, feature, propertyChains, true); | ||
// Read the chains and return a primer object that will contain a set of instructions | ||
var primer = primase.preparePrimer(userProperties, feature, propertyChains, true); | ||
// Pick the primer, proof-read the instructions and then assemble the collection of feature toggles | ||
var resolvedFeatures = polymerase.assembleFeatures(featureName, primer, ancestorGenes); | ||
// Pick the primer, proof-read the instructions and then assemble the collection of feature toggles | ||
var resolvedFeatures = polymerase.assembleFeatures(featureName, primer, ancestorGenes); | ||
// Join all the mutations | ||
joinMutations(features, resolvedFeatures); | ||
}); | ||
// Join all the mutations | ||
joinMutations(features, resolvedFeatures); | ||
}); | ||
return features; | ||
} | ||
}; | ||
return features; | ||
} | ||
}; | ||
// Exports section | ||
if (hasExports) { | ||
// Export to NodeJS | ||
module.exports = muton; | ||
} else { | ||
// Export to Global | ||
this.muton = muton; | ||
} | ||
return muton; | ||
}); | ||
}).call(this); | ||
module.exports = muton; |
@@ -6,19 +6,11 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
var keys = require('lodash/object/keys'); | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
return { | ||
separateProperties: function (userProperties, feature) { | ||
return { | ||
userPropertyNames: _.keys(userProperties), | ||
featurePropertyNames: _.keys(feature) | ||
}; | ||
} | ||
}; | ||
}); | ||
module.exports = { | ||
separateProperties: function (userProperties, feature) { | ||
return { | ||
userPropertyNames: keys(userProperties), | ||
featurePropertyNames: keys(feature) | ||
}; | ||
} | ||
}; |
@@ -6,38 +6,31 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
define(function (require) { | ||
var findLast = require('lodash/collection/findLast'); | ||
var regexMatcher = require('./matchers/regex'); | ||
var numericMatcher = require('./matchers/numeric-quantifier'); | ||
var _ = require('lodash'); | ||
var regexMatcher = require('./matchers/regex'); | ||
var numericMatcher = require('./matchers/numeric-quantifier'); | ||
var defaultMatcher = { | ||
matchesPropertyValue: function(userPropertyValue, propertyKey) { | ||
return userPropertyValue === propertyKey; | ||
} | ||
}; | ||
var defaultMatcher = { | ||
matchesPropertyValue: function(userPropertyValue, propertyKey) { | ||
return userPropertyValue === propertyKey; | ||
} | ||
}; | ||
function pickMatcher(userPropertyValue, propertyKey) { | ||
if (regexMatcher.isRegex(propertyKey)) { | ||
return regexMatcher; | ||
} else if (numericMatcher.isNumber(userPropertyValue) && | ||
numericMatcher.isNumericQuantifier(propertyKey)) { | ||
return numericMatcher; | ||
} else { | ||
return defaultMatcher; | ||
} | ||
} | ||
function pickMatcher(userPropertyValue, propertyKey) { | ||
if (regexMatcher.isRegex(propertyKey)) { | ||
return regexMatcher; | ||
} else if (numericMatcher.isNumber(userPropertyValue) && | ||
numericMatcher.isNumericQuantifier(propertyKey)) { | ||
return numericMatcher; | ||
} else { | ||
return defaultMatcher; | ||
} | ||
module.exports = { | ||
getMatchedProperties: function(userPropertyValue, featureProperty) { | ||
return findLast(featureProperty, function (propertyValue, propertyKey) { | ||
var matcher = pickMatcher(userPropertyValue, propertyKey); | ||
return matcher.matchesPropertyValue(userPropertyValue, propertyKey); | ||
}); | ||
} | ||
return { | ||
getMatchedProperties: function(userPropertyValue, featureProperty) { | ||
return _.findLast(featureProperty, function (propertyValue, propertyKey) { | ||
var matcher = pickMatcher(userPropertyValue, propertyKey); | ||
return matcher.matchesPropertyValue(userPropertyValue, propertyKey); | ||
}); | ||
} | ||
}; | ||
}); | ||
}; |
'use strict'; | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
var numberRegex = /-?\d+(\.\d{1,2})?/; | ||
var operatorRegex = /[><]=?/; | ||
define(function () { | ||
var numericQuantifierRegex = new RegExp(operatorRegex.source + numberRegex.source); | ||
var validExpressionRegex = new RegExp(numberRegex.source + operatorRegex.source + numberRegex.source); | ||
var numberRegex = /-?\d+(\.\d{1,2})?/; | ||
var operatorRegex = /[><]=?/; | ||
function isExpressionValid(expression) { | ||
return validExpressionRegex.test(expression); | ||
} | ||
var numericQuantifierRegex = new RegExp(operatorRegex.source + numberRegex.source); | ||
var validExpressionRegex = new RegExp(numberRegex.source + operatorRegex.source + numberRegex.source); | ||
module.exports = { | ||
function isExpressionValid(expression) { | ||
return validExpressionRegex.test(expression); | ||
} | ||
isNumber: function (value) { | ||
return numberRegex.test(value); | ||
}, | ||
return { | ||
isNumericQuantifier: function (value) { | ||
return numericQuantifierRegex.test(value); | ||
}, | ||
isNumber: function (value) { | ||
return numberRegex.test(value); | ||
}, | ||
matchesPropertyValue: function(propertyValue, numericQuantifierStr) { | ||
var expression = propertyValue + numericQuantifierStr; | ||
isNumericQuantifier: function (value) { | ||
return numericQuantifierRegex.test(value); | ||
}, | ||
if (!isExpressionValid(expression)) { | ||
// Just to catch eventual issues with eval | ||
return false; | ||
} | ||
matchesPropertyValue: function(propertyValue, numericQuantifierStr) { | ||
var expression = propertyValue + numericQuantifierStr; | ||
if (!isExpressionValid(expression)) { | ||
// Just to catch eventual issues with eval | ||
return false; | ||
} | ||
/*jshint -W061*/ | ||
return eval(expression); | ||
} | ||
}; | ||
}); | ||
/*jshint -W061*/ | ||
return eval(expression); | ||
} | ||
}; |
'use strict'; | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
var regexDelimiters = /^\/.+\/$/; | ||
function sanitizeRegexStr(regexStr) { | ||
return regexStr.substring(1, regexStr.length - 1); | ||
} | ||
define(function () { | ||
module.exports = { | ||
isRegex: function (value) { | ||
return regexDelimiters.test(value); | ||
}, | ||
var regexDelimiters = /^\/.+\/$/; | ||
function sanitizeRegexStr(regexStr) { | ||
return regexStr.substring(1, regexStr.length - 1); | ||
matchesPropertyValue: function(propertyValue, regexStr) { | ||
var sanitisedRegex = sanitizeRegexStr(regexStr); | ||
var regex = new RegExp('^' + sanitisedRegex + '$'); | ||
return regex.test(propertyValue); | ||
} | ||
return { | ||
isRegex: function (value) { | ||
return regexDelimiters.test(value); | ||
}, | ||
matchesPropertyValue: function(propertyValue, regexStr) { | ||
var sanitisedRegex = sanitizeRegexStr(regexStr); | ||
var regex = new RegExp('^' + sanitisedRegex + '$'); | ||
return regex.test(propertyValue); | ||
} | ||
}; | ||
}); | ||
}; |
@@ -6,42 +6,40 @@ 'use strict'; | ||
*/ | ||
if (typeof define !== 'function') { | ||
/*jshint -W003*/ | ||
var define = require('amdefine')(module); | ||
} | ||
var get = require('lodash/object/get'); | ||
var isUndefined = require('lodash/lang/isUndefined'); | ||
var isBoolean = require('lodash/lang/isBoolean'); | ||
var isNull = require('lodash/lang/isNull'); | ||
var isArray = require('lodash/lang/isArray'); | ||
var isObject = require('lodash/lang/isObject'); | ||
define(function (require) { | ||
var bucketMutator = require('../mutators/bucket'); | ||
var throttleMutator = require('../mutators/throttle'); | ||
var _ = require('lodash'); | ||
var bucketMutator = require('../mutators/bucket'); | ||
var throttleMutator = require('../mutators/throttle'); | ||
module.exports = { | ||
areInstructionsValid: function (featureInstructions) { | ||
var toggle = get(featureInstructions, 'toggle'); | ||
var throttle = get(featureInstructions, 'throttle'); | ||
var buckets = get(featureInstructions, 'buckets'); | ||
return { | ||
areInstructionsValid: function (featureInstructions) { | ||
var toggle = _.get(featureInstructions, 'toggle'); | ||
var throttle = _.get(featureInstructions, 'throttle'); | ||
var buckets = _.get(featureInstructions, 'buckets'); | ||
return this.isToggleValid(toggle) && this.isThrottleValid(throttle) && this.areBucketsValid(buckets); | ||
}, | ||
return this.isToggleValid(toggle) && this.isThrottleValid(throttle) && this.areBucketsValid(buckets); | ||
}, | ||
isToggleValid: function (toggle) { | ||
return isUndefined(toggle) || isBoolean(toggle); | ||
}, | ||
isToggleValid: function (toggle) { | ||
return _.isUndefined(toggle) || _.isBoolean(toggle); | ||
}, | ||
isThrottleValid: function(throttle) { | ||
return isUndefined(throttle) || throttleMutator.isThrottleValid(throttle); | ||
}, | ||
isThrottleValid: function(throttle) { | ||
return _.isUndefined(throttle) || throttleMutator.isThrottleValid(throttle); | ||
}, | ||
areBucketsValid: function(buckets) { | ||
return isUndefined(buckets) || bucketMutator.isBucketListValid(buckets); | ||
}, | ||
areBucketsValid: function(buckets) { | ||
return _.isUndefined(buckets) || bucketMutator.isBucketListValid(buckets); | ||
}, | ||
checkFeatureInstructions: function (featureInstructions) { | ||
var valid = isUndefined(featureInstructions) || isNull(featureInstructions) || !isArray(featureInstructions) && isObject(featureInstructions); | ||
checkFeatureInstructions: function (featureInstructions) { | ||
var valid = _.isUndefined(featureInstructions) || _.isNull(featureInstructions) || !_.isArray(featureInstructions) && _.isObject(featureInstructions); | ||
if (!valid) { | ||
throw new Error('Invalid feature instructions!'); | ||
} | ||
if (!valid) { | ||
throw new Error('Invalid feature instructions!'); | ||
} | ||
}; | ||
}); | ||
} | ||
}; |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
336176
1
20
8028
2
1
23
317
- Removedamdefine@^0.1.0
- Removedamdefine@0.1.1(transitive)