diff --git a/.babelrc b/.babelrc deleted file mode 100644 index bd20dc1..0000000 --- a/.babelrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "presets": [ - "es2015", - "react" - ] -} diff --git a/.circleci/config.yml b/.circleci/config.yml index 34f1ba9..c6ef349 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,8 +6,5 @@ jobs: working_directory: ~/react-nvd3 steps: - checkout - - run: mkdir -p ~/react-nvd3/artifacts - run: npm install - run: ./node_modules/gulp/bin/gulp.js jest - - store_artifacts: - path: ~/react-nvd3/artifacts diff --git a/dist/react-nvd3.js b/dist/react-nvd3.js index dec3f50..a2371d7 100644 --- a/dist/react-nvd3.js +++ b/dist/react-nvd3.js @@ -1307,7 +1307,6 @@ return /******/ (function(modules) { // webpackBootstrap exports.includes = includes; exports.negate = negate; - exports.filterObject = filterObject; exports.pick = pick; exports.without = without; exports.isPlainObject = isPlainObject; @@ -1399,7 +1398,7 @@ return /******/ (function(modules) { // webpackBootstrap } /** - * It replace all the {type:'function', name: 'nameOffunction'} + * It replaces all the {type:'function', name: 'nameOffunction'} * ocurrences in a give object by the functions stored * in the {context} with the name {name} * @param {Object} o The original object to be patched @@ -1454,7 +1453,7 @@ return /******/ (function(modules) { // webpackBootstrap } function isCallable(value) { - return value && typeof value === 'function'; + return Boolean(value && typeof value === 'function'); } /***/ }, diff --git a/dist/react-nvd3.min.js b/dist/react-nvd3.min.js index e5424c6..3fc4f4f 100644 --- a/dist/react-nvd3.min.js +++ b/dist/react-nvd3.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("d3"),require("nvd3")):"function"==typeof define&&define.amd?define(["react","d3","nvd3"],e):"object"==typeof exports?exports.NVD3Chart=e(require("react"),require("d3"),require("nvd3")):t.NVD3Chart=e(t.React,t.d3,t.nv)}(this,function(t,e,n){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var o=n(1),i=r(o),u=n(2),c=r(u),s=n(17),a=r(s),f=n(21),l=r(f),p=n(22),d=r(p),h=n(25),y=r(h),v=n(48),b=r(v),g=n(55),m=r(g),_=n(56),x=r(_),w=n(57),O=r(w),j=n(58),S=["x","y","type","datum","configure"],P=["width","height"],k="margin",E="containerStyle",C="renderStart",M="renderEnd",z="ready",D=function(t){function e(){(0,l["default"])(this,e);var t=(0,y["default"])(this,(e.__proto__||(0,a["default"])(e)).call(this));return t.resize=t.resize.bind(t),t}return(0,b["default"])(e,t),(0,d["default"])(e,[{key:"componentDidMount",value:function(){var t=this;O["default"].addGraph(this.renderChart.bind(this),function(e){(0,j.isCallable)(t.props.ready)&&t.props.ready(e,z)})}},{key:"componentDidUpdate",value:function(){this.renderChart()}},{key:"componentWillUnmount",value:function(){this.resizeHandler&&clearTimeout(this.resizeHandler),window.removeEventListener?window.removeEventListener("resize",this.resize):window.detachEvent("resize",this.resize)}},{key:"renderChart",value:function(){var t=void 0;switch(this.chart=this.chart&&!this.rendering?this.chart:O["default"].models[this.props.type](),(0,j.isCallable)(this.props.renderStart)&&this.props.renderStart(this.chart,C),this.parsedProps=(0,j.bindFunctions)(this.props,this.props.context),this.chart.x&&this.chart.x((0,j.getValueFunction)(this.parsedProps.x,"x")),this.chart.y&&this.chart.y((0,j.getValueFunction)(this.parsedProps.y,"y")),this.props.margin&&this.chart.margin(this.options(k,j.pick).margin||(0,j.propsByPrefix)("margin",this.props)||{}),this.configureComponents(this.chart,this.options(S.concat(E),j.without)),!this.props.configure||this.props.configure(this.chart),this.selection=x["default"].select(this.refs.svg).datum(this.props.datum).call(this.chart),this.resizeHandler||(window.addEventListener?window.addEventListener("resize",this.resize,!1):window.attachEvent("resize",this.resize,!1)),this.props.type){case"multiBarChart":t=this.chart.multibar.dispatch;break;case"pieChart":t=this.chart.pie.dispatch;break;case"lineChart":case"linePlusBarChart":t=this.chart.lines.dispatch;break;default:t=this.chart.dispatch}return t.renderEnd&&t.on("renderEnd",this.renderEnd.bind(this)),t.elementClick&&t.on("elementClick",this.elementClick.bind(this)),this.rendering=!0,this.chart}},{key:"renderEnd",value:function(t){(0,j.isCallable)(this.props.renderEnd)&&this.props.renderEnd(this.chart,M),this.rendering=!1}},{key:"elementClick",value:function(t){(0,j.isCallable)(this.props.elementClick)&&this.props.elementClick(t,"elementClick")}},{key:"configureComponents",value:function(t,e){for(var n in e){var r=e[n];t&&((0,j.isPlainObject)(r)?this.configureComponents(t[n],r):"function"==typeof t[n]&&t[n](r))}}},{key:"options",value:function(t,e){var n=this.parsedProps.options||this.parsedProps||this.props.chartOptions;return(e=e||j.pick)(n,t)}},{key:"resize",value:function(t){var e=this;clearTimeout(this.resizeHandler),this.resizeHandler=setTimeout(function(){clearTimeout(e.resizeHandler),e.chart&&"function"==typeof e.chart.update&&e.chart.update()},250)}},{key:"render",value:function(){var t=(0,j.pick)(this.props,P),e=(0,c["default"])({},t,this.props.containerStyle);return m["default"].createElement("div",{ref:"root",className:"nv-chart",style:e},m["default"].createElement("svg",(0,i["default"])({ref:"svg"},t)))}}]),e}(m["default"].Component);e["default"]=D,t.exports=D},function(t,e,n){"use strict";var r=n(2)["default"];e["default"]=r||function(t){for(var e=1;es;)for(var p,d=i(u[s++]),h=f?a(d).concat(f(d)):a(d),y=h.length,v=0;y>v;)l.call(d,p=h[v++])&&(n[p]=d[p]);return n}:Object.assign},function(t,e){var n=Object;t.exports={create:n.create,getProto:n.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:n.getOwnPropertyDescriptor,setDesc:n.defineProperty,setDescs:n.defineProperties,getKeys:n.keys,getNames:n.getOwnPropertyNames,getSymbols:n.getOwnPropertySymbols,each:[].forEach}},function(t,e,n){var r=n(13);t.exports=function(t){return Object(r(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(15);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e){t.exports=function(t){try{return!!t()}catch(e){return!0}}},function(t,e,n){t.exports={"default":n(18),__esModule:!0}},function(t,e,n){n(19),t.exports=n(7).Object.getPrototypeOf},function(t,e,n){var r=n(12);n(20)("getPrototypeOf",function(t){return function(e){return t(r(e))}})},function(t,e,n){var r=n(5),o=n(7),i=n(16);t.exports=function(t,e){var n=(o.Object||{})[t]||Object[t],u={};u[t]=e(n),r(r.S+r.F*i(function(){n(1)}),"Object",u)}},function(t,e){"use strict";e.__esModule=!0,e["default"]=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=n(23),i=r(o);e["default"]=function(){function t(t,e){for(var n=0;no;)B(t,n=r[o++],e[n]);return t},V=function(t,e){return void 0===e?O(t):H(O(t),e)},W=function(t){var e=M.call(this,t);return!(e||!i(this,t)||!i(D,t)||i(this,C)&&this[C][t])||e},G=function(t,e){var n=x(t=m(t),e);return!n||!i(D,e)||i(t,C)&&t[C][e]||(n.enumerable=!0),n},I=function(t){for(var e,n=j(m(t)),r=[],o=0;n.length>o;)i(D,e=n[o++])||e==C||r.push(e);return r},J=function(t){for(var e,n=j(m(t)),r=[],o=0;n.length>o;)i(D,e=n[o++])&&r.push(D[e]);return r},K=function(t){if(void 0!==t&&!A(t)){for(var e,n,r=[t],o=1,i=arguments;i.length>o;)r.push(i[o++]);return e=r[1],"function"==typeof e&&(n=e),!n&&b(e)||(e=function(t,e){if(n&&(e=n.call(this,t,e)),!A(e))return e}),r[1]=e,k.apply(P,r)}},L=a(function(){var t=S();return"[null]"!=k([t])||"{}"!=k({a:t})||"{}"!=k(Object(t))});F||(S=function(){if(A(this))throw TypeError("Symbol is not a constructor");return q(p(arguments.length>0?arguments[0]:void 0))},s(S.prototype,"toString",function(){return this._k}),A=function(t){return t instanceof S},r.create=V,r.isEnum=W,r.getDesc=G,r.setDesc=B,r.setDescs=H,r.getNames=y.get=I,r.getSymbols=J,u&&!n(46)&&s(N,"propertyIsEnumerable",W,!0));var R={"for":function(t){return i(z,t+="")?z[t]:z[t]=S(t)},keyFor:function(t){return h(z,t)},useSetter:function(){E=!0},useSimple:function(){E=!1}};r.each.call("hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),function(t){var e=d(t);R[t]=F?e:q(e)}),E=!0,c(c.G+c.W,{Symbol:S}),c(c.S,"Symbol",R),c(c.S+c.F*!F,"Object",{create:V,defineProperty:B,defineProperties:H,getOwnPropertyDescriptor:G,getOwnPropertyNames:I,getOwnPropertySymbols:J}),P&&c(c.S+c.F*(!F||L),"JSON",{stringify:K}),l(S,"Symbol"),l(Math,"Math",!0),l(o.JSON,"JSON",!0)},function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},function(t,e,n){t.exports=!n(16)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e,n){t.exports=n(33)},function(t,e,n){var r=n(11),o=n(34);t.exports=n(31)?function(t,e,n){return r.setDesc(t,e,o(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,n){var r=n(6),o="__core-js_shared__",i=r[o]||(r[o]={});t.exports=function(t){return i[t]||(i[t]={})}},function(t,e,n){var r=n(11).setDesc,o=n(30),i=n(37)("toStringTag");t.exports=function(t,e,n){t&&!o(t=n?t:t.prototype,i)&&r(t,i,{configurable:!0,value:e})}},function(t,e,n){var r=n(35)("wks"),o=n(38),i=n(6).Symbol;t.exports=function(t){return r[t]||(r[t]=i&&i[t]||(i||o)("Symbol."+t))}},function(t,e){var n=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++n+r).toString(36))}},function(t,e,n){var r=n(11),o=n(40);t.exports=function(t,e){for(var n,i=o(t),u=r.getKeys(i),c=u.length,s=0;c>s;)if(i[n=u[s++]]===e)return n}},function(t,e,n){var r=n(14),o=n(13);t.exports=function(t){return r(o(t))}},function(t,e,n){var r=n(40),o=n(11).getNames,i={}.toString,u="object"==typeof window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],c=function(t){try{return o(t)}catch(e){return u.slice()}};t.exports.get=function(t){return u&&"[object Window]"==i.call(t)?c(t):o(r(t))}},function(t,e,n){var r=n(11);t.exports=function(t){var e=r.getKeys(t),n=r.getSymbols;if(n)for(var o,i=n(t),u=r.isEnum,c=0;i.length>c;)u.call(t,o=i[c++])&&e.push(o);return e}},function(t,e,n){var r=n(15);t.exports=Array.isArray||function(t){return"Array"==r(t)}},function(t,e,n){var r=n(45);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e){t.exports=!0},function(t,e){},function(t,e,n){"use strict";var r=n(49)["default"],o=n(51)["default"];e["default"]=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=r(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(o?o(t,e):t.__proto__=e)},e.__esModule=!0},function(t,e,n){t.exports={"default":n(50),__esModule:!0}},function(t,e,n){var r=n(11);t.exports=function(t,e){return r.create(t,e)}},function(t,e,n){t.exports={"default":n(52),__esModule:!0}},function(t,e,n){n(53),t.exports=n(7).Object.setPrototypeOf},function(t,e,n){var r=n(5);r(r.S,"Object",{setPrototypeOf:n(54).set})},function(t,e,n){var r=n(11).getDesc,o=n(45),i=n(44),u=function(t,e){if(i(t),!o(e)&&null!==e)throw TypeError(e+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,e,o){try{o=n(8)(Function.call,r(Object.prototype,"__proto__").set,2),o(t,[]),e=!(t instanceof Array)}catch(i){e=!0}return function(t,n){return u(t,n),e?t.__proto__=n:o(t,n),t}}({},!1):void 0),check:u}},function(e,n){e.exports=t},function(t,n){t.exports=e},function(t,e){t.exports=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){return t.indexOf(e)>=0}function i(t){return function(){return!t.apply(this,arguments)}}function u(t,e,n){for(var r={},o=(0,m["default"])(t),i=0,u=o.length;is;)for(var p,d=i(u[s++]),h=f?a(d).concat(f(d)):a(d),y=h.length,v=0;y>v;)l.call(d,p=h[v++])&&(n[p]=d[p]);return n}:Object.assign},function(t,e){var n=Object;t.exports={create:n.create,getProto:n.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:n.getOwnPropertyDescriptor,setDesc:n.defineProperty,setDescs:n.defineProperties,getKeys:n.keys,getNames:n.getOwnPropertyNames,getSymbols:n.getOwnPropertySymbols,each:[].forEach}},function(t,e,n){var r=n(13);t.exports=function(t){return Object(r(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(15);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e){t.exports=function(t){try{return!!t()}catch(e){return!0}}},function(t,e,n){t.exports={"default":n(18),__esModule:!0}},function(t,e,n){n(19),t.exports=n(7).Object.getPrototypeOf},function(t,e,n){var r=n(12);n(20)("getPrototypeOf",function(t){return function(e){return t(r(e))}})},function(t,e,n){var r=n(5),o=n(7),i=n(16);t.exports=function(t,e){var n=(o.Object||{})[t]||Object[t],u={};u[t]=e(n),r(r.S+r.F*i(function(){n(1)}),"Object",u)}},function(t,e){"use strict";e.__esModule=!0,e["default"]=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=n(23),i=r(o);e["default"]=function(){function t(t,e){for(var n=0;no;)A(t,n=r[o++],e[n]);return t},V=function(t,e){return void 0===e?O(t):H(O(t),e)},W=function(t){var e=M.call(this,t);return!(e||!i(this,t)||!i(D,t)||i(this,C)&&this[C][t])||e},G=function(t,e){var n=x(t=m(t),e);return!n||!i(D,e)||i(t,C)&&t[C][e]||(n.enumerable=!0),n},I=function(t){for(var e,n=j(m(t)),r=[],o=0;n.length>o;)i(D,e=n[o++])||e==C||r.push(e);return r},J=function(t){for(var e,n=j(m(t)),r=[],o=0;n.length>o;)i(D,e=n[o++])&&r.push(D[e]);return r},K=function(t){if(void 0!==t&&!B(t)){for(var e,n,r=[t],o=1,i=arguments;i.length>o;)r.push(i[o++]);return e=r[1],"function"==typeof e&&(n=e),!n&&b(e)||(e=function(t,e){if(n&&(e=n.call(this,t,e)),!B(e))return e}),r[1]=e,k.apply(P,r)}},L=a(function(){var t=S();return"[null]"!=k([t])||"{}"!=k({a:t})||"{}"!=k(Object(t))});F||(S=function(){if(B(this))throw TypeError("Symbol is not a constructor");return q(p(arguments.length>0?arguments[0]:void 0))},s(S.prototype,"toString",function(){return this._k}),B=function(t){return t instanceof S},r.create=V,r.isEnum=W,r.getDesc=G,r.setDesc=A,r.setDescs=H,r.getNames=y.get=I,r.getSymbols=J,u&&!n(46)&&s(N,"propertyIsEnumerable",W,!0));var R={"for":function(t){return i(z,t+="")?z[t]:z[t]=S(t)},keyFor:function(t){return h(z,t)},useSetter:function(){E=!0},useSimple:function(){E=!1}};r.each.call("hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),function(t){var e=d(t);R[t]=F?e:q(e)}),E=!0,c(c.G+c.W,{Symbol:S}),c(c.S,"Symbol",R),c(c.S+c.F*!F,"Object",{create:V,defineProperty:A,defineProperties:H,getOwnPropertyDescriptor:G,getOwnPropertyNames:I,getOwnPropertySymbols:J}),P&&c(c.S+c.F*(!F||L),"JSON",{stringify:K}),l(S,"Symbol"),l(Math,"Math",!0),l(o.JSON,"JSON",!0)},function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},function(t,e,n){t.exports=!n(16)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e,n){t.exports=n(33)},function(t,e,n){var r=n(11),o=n(34);t.exports=n(31)?function(t,e,n){return r.setDesc(t,e,o(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,n){var r=n(6),o="__core-js_shared__",i=r[o]||(r[o]={});t.exports=function(t){return i[t]||(i[t]={})}},function(t,e,n){var r=n(11).setDesc,o=n(30),i=n(37)("toStringTag");t.exports=function(t,e,n){t&&!o(t=n?t:t.prototype,i)&&r(t,i,{configurable:!0,value:e})}},function(t,e,n){var r=n(35)("wks"),o=n(38),i=n(6).Symbol;t.exports=function(t){return r[t]||(r[t]=i&&i[t]||(i||o)("Symbol."+t))}},function(t,e){var n=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++n+r).toString(36))}},function(t,e,n){var r=n(11),o=n(40);t.exports=function(t,e){for(var n,i=o(t),u=r.getKeys(i),c=u.length,s=0;c>s;)if(i[n=u[s++]]===e)return n}},function(t,e,n){var r=n(14),o=n(13);t.exports=function(t){return r(o(t))}},function(t,e,n){var r=n(40),o=n(11).getNames,i={}.toString,u="object"==typeof window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],c=function(t){try{return o(t)}catch(e){return u.slice()}};t.exports.get=function(t){return u&&"[object Window]"==i.call(t)?c(t):o(r(t))}},function(t,e,n){var r=n(11);t.exports=function(t){var e=r.getKeys(t),n=r.getSymbols;if(n)for(var o,i=n(t),u=r.isEnum,c=0;i.length>c;)u.call(t,o=i[c++])&&e.push(o);return e}},function(t,e,n){var r=n(15);t.exports=Array.isArray||function(t){return"Array"==r(t)}},function(t,e,n){var r=n(45);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e){t.exports=!0},function(t,e){},function(t,e,n){"use strict";var r=n(49)["default"],o=n(51)["default"];e["default"]=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=r(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(o?o(t,e):t.__proto__=e)},e.__esModule=!0},function(t,e,n){t.exports={"default":n(50),__esModule:!0}},function(t,e,n){var r=n(11);t.exports=function(t,e){return r.create(t,e)}},function(t,e,n){t.exports={"default":n(52),__esModule:!0}},function(t,e,n){n(53),t.exports=n(7).Object.setPrototypeOf},function(t,e,n){var r=n(5);r(r.S,"Object",{setPrototypeOf:n(54).set})},function(t,e,n){var r=n(11).getDesc,o=n(45),i=n(44),u=function(t,e){if(i(t),!o(e)&&null!==e)throw TypeError(e+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,e,o){try{o=n(8)(Function.call,r(Object.prototype,"__proto__").set,2),o(t,[]),e=!(t instanceof Array)}catch(i){e=!0}return function(t,n){return u(t,n),e?t.__proto__=n:o(t,n),t}}({},!1):void 0),check:u}},function(e,n){e.exports=t},function(t,n){t.exports=e},function(t,e){t.exports=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){return t.indexOf(e)>=0}function i(t){return function(){return!t.apply(this,arguments)}}function u(t,e,n){for(var r={},o=(0,m["default"])(t),i=0,u=o.length;i=0.14.0", "react-dom": ">=0.14.0" + }, + "babel": { + "presets": [ + "es2015", + "react" + ] } } diff --git a/src/utils.js b/src/utils.js index bf2d232..9502b65 100644 --- a/src/utils.js +++ b/src/utils.js @@ -27,7 +27,7 @@ export function negate(f) { * @param {Function} predicate * @return {Object} */ -export function filterObject(obj, keys, predicate) { +function filterObject(obj, keys, predicate) { let result = {}; let ks = Object.keys(obj); @@ -79,7 +79,7 @@ export function isPlainObject(obj){ } /** - * It replace all the {type:'function', name: 'nameOffunction'} + * It replaces all the {type:'function', name: 'nameOffunction'} * ocurrences in a give object by the functions stored * in the {context} with the name {name} * @param {Object} o The original object to be patched @@ -132,5 +132,5 @@ export function propsByPrefix(prefix, props) { } export function isCallable(value) { - return value && typeof value === 'function'; -} \ No newline at end of file + return Boolean(value && typeof value === 'function'); +} diff --git a/test/utils.test.js b/test/utils.test.js index 3c5e476..c98c61a 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -1,9 +1,15 @@ import { includes, - negate + negate, + pick, + without, + isPlainObject, + bindFunctions, + getValueFunction, + isCallable, } from '../src/utils.js'; -describe("The utils.includes function", () => { +describe("Function utils.includes(array, item)", () => { beforeEach(() => { self.TestData = [ 0, 1, 2, 3]; }); @@ -13,17 +19,16 @@ describe("The utils.includes function", () => { expect(includes(self.TestData, 0)).toBe.true; }); - it('should locate a value if it does not exists', () => { - let TestData = [ 0, 1, 2, 3]; + it('should not locate a value if it does not exists', () => { expect(includes(self.TestData, 'zero')).toBe.false; }); - it('should Throw if non array is checked', () => { + it('should Throw TypeError', () => { expect(includes).toThrow(TypeError); }); }); -describe("The utils.negate function", () => { +describe("Function utils.negate(f)", () => { it('should make a positive producer be a negative producer', () => { let negator = negate(function(a) {return true;}); expect(negator('a')).toBe.false; @@ -34,3 +39,123 @@ describe("The utils.negate function", () => { expect(negator('a')).toBe.true; }); }); + +describe("Function utils.pick(obj, keys)", () => { + it('should return empty if empty is passed', () => { + expect(pick({}, ["a", "b"])).toEqual({}); + }); + + it('should return empty object if no keys are passed', () => { + expect(pick({a: 1, b: 2}, [])).toEqual({}); + }); + + it('should return only picked keys', () => { + expect(pick({a: 1, b: 2}, ["a"])).toEqual({a: 1}); + }); + + it('should return object if all keys are passed', () => { + expect(pick({a: 1, b: 2}, ["a", "b", "c"])).toEqual({a: 1, b: 2}); + }); +}); + +describe("Function utils.without(obj, keys)", () => { + it('should return empty if empty is passed', () => { + expect(without({}, ["a", "b"])).toEqual({}); + }); + + it('should return empty object if all keys are passed', () => { + expect(without({a: 1, b: 2}, ["a", "b", "c"])).toEqual({}); + }); + + it('should return only unpicked keys', () => { + expect(without({a: 1, b: 2}, ["a"])).toEqual({b: 2}); + }); + + it('should return object if all not keys passed', () => { + expect(without({a: 1, b: 2}, ["c"])).toEqual({a: 1, b: 2}); + }); +}); + +describe("Function utils.isPlainObject(obj)", () => { + it("should verify Objects as plain objects", () => { + let myObject = new Object(); + expect(isPlainObject(myObject)).toBe(true); + }); + + it("should verify {} as a plain objects", () => { + expect(isPlainObject({a: 1, b: {}})).toBe(true); + }); + + it("should not verify String as a plain objects", () => { + let myString = new String("Hello"); + expect(isPlainObject(myString)).toBe(false); + }); +}); + +describe("Function utils.bindFunctions(obj, handlers)", () => { + it("It should handle empty object and empty handlers", () => { + expect(bindFunctions({}, {})).toEqual({}); + }); + + it("It should handle empty object with any handler", () => { + expect(bindFunctions({}, {a: () => {}})).toEqual({}); + }); + + it("It should bind functions to their references", () => { + let data = {a: {name: "a", type: "function"}}; + let handlers = {a: () => {return true}}; + + expect(bindFunctions(data, handlers).a()).toBe(true); + }); + + it("It should bind functions to a list of references", () => { + let data = [{a: {name: "a", type: "function"}}]; + let handlers = {a: () => {return true}}; + + expect(bindFunctions(data, handlers)[0].a()).toBe(true); + }); + + it("It should bind functions to internal references", () => { + let data = [{a: {a: {name: "a", type: "function"}}}]; + let handlers = {a: () => {return true}}; + + expect(bindFunctions(data, handlers)[0].a.a()).toBe(true); + }); +}); + +describe("Function utils.getValueFunction(v, _default)", () => { + it("It should ignore arguments that are functions", () => { + let f = (a) => {return a * a;} + let g = getValueFunction(f) + expect(g(2)).toBe(4); + }); + + it("It should return getter function for non function arguments", () => { + let a = "name" + let f = getValueFunction(a) + let testObject = {name: "react-nvd3"} + expect(f(testObject)).toBe("react-nvd3"); + }); + + it("It should try the _default as a backup getter if first does not work", () => { + let a = "_x" + let b = "name" + let f = getValueFunction(a, b) + let testObject = {name: "react-nvd3"} + expect(f(testObject)).toBe("react-nvd3"); + }); +}); + +describe("Function utils.isCallable(value)", () => { + it("should determine functions are callable", () => { + let f = () => {return 1}; + expect(isCallable(f)).toBe(true); + }); + + it("should determine non functions are not callable", () => { + expect(isCallable(undefined)).toBe(false); + expect(isCallable(1)).toBe(false); + expect(isCallable({})).toBe(false); + expect(isCallable("")).toBe(false); + }); +});