UNPKG

flavor-js

Version:

FlavorJS the definitive JS natives chainable extensions methods (based on lodash & ES6)

258 lines (221 loc) 16.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>flavor.js - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FlavorJS.html">FlavorJS</a><ul class='methods'><li data-type='method'><a href="FlavorJS.html#delay">delay</a></li><li data-type='method'><a href="FlavorJS.html#extendArray">extendArray</a></li><li data-type='method'><a href="FlavorJS.html#extendBoolean">extendBoolean</a></li><li data-type='method'><a href="FlavorJS.html#extendDate">extendDate</a></li><li data-type='method'><a href="FlavorJS.html#extendFunction">extendFunction</a></li><li data-type='method'><a href="FlavorJS.html#extendLodash">extendLodash</a></li><li data-type='method'><a href="FlavorJS.html#extendNumber">extendNumber</a></li><li data-type='method'><a href="FlavorJS.html#extendObject">extendObject</a></li><li data-type='method'><a href="FlavorJS.html#extendPrototype">extendPrototype</a></li><li data-type='method'><a href="FlavorJS.html#extendPrototypeProperty">extendPrototypeProperty</a></li><li data-type='method'><a href="FlavorJS.html#extendString">extendString</a></li><li data-type='method'><a href="FlavorJS.html#init">init</a></li></ul></li></ul><h3>Namespaces</h3><ul><li><a href="array.html">array</a><ul class='methods'><li data-type='method'><a href="array.html#clone">clone</a></li><li data-type='method'><a href="array.html#concat">concat</a></li><li data-type='method'><a href="array.html#contains">contains</a></li><li data-type='method'><a href="array.html#containsBy">containsBy</a></li><li data-type='method'><a href="array.html#countBy">countBy</a></li><li data-type='method'><a href="array.html#cut">cut</a></li><li data-type='method'><a href="array.html#deepFindBy">deepFindBy</a></li><li data-type='method'><a href="array.html#deepMap">deepMap</a></li><li data-type='method'><a href="array.html#deepSortBy">deepSortBy</a></li><li data-type='method'><a href="array.html#diff">diff</a></li><li data-type='method'><a href="array.html#diffBy">diffBy</a></li><li data-type='method'><a href="array.html#distinct">distinct</a></li><li data-type='method'><a href="array.html#each">each</a></li><li data-type='method'><a href="array.html#filterBy">filterBy</a></li><li data-type='method'><a href="array.html#findBy">findBy</a></li><li data-type='method'><a href="array.html#first">first</a></li><li data-type='method'><a href="array.html#flatten">flatten</a></li><li data-type='method'><a href="array.html#indexBy">indexBy</a></li><li data-type='method'><a href="array.html#intersection">intersection</a></li><li data-type='method'><a href="array.html#isArray">isArray</a></li><li data-type='method'><a href="array.html#last">last</a></li><li data-type='method'><a href="array.html#lorem">lorem</a></li><li data-type='method'><a href="array.html#maxBy">maxBy</a></li><li data-type='method'><a href="array.html#pull">pull</a></li><li data-type='method'><a href="array.html#pullBy">pullBy</a></li><li data-type='method'><a href="array.html#random">random</a></li><li data-type='method'><a href="array.html#removeBy">removeBy</a></li><li data-type='method'><a href="array.html#shuffle">shuffle</a></li><li data-type='method'><a href="array.html#sortBy">sortBy</a></li><li data-type='method'><a href="array.html#split">split</a></li><li data-type='method'><a href="array.html#sum">sum</a></li><li data-type='method'><a href="array.html#tail">tail</a></li><li data-type='method'><a href="array.html#tail">tail</a></li><li data-type='method'><a href="array.html#union">union</a></li></ul></li><li><a href="boolean.html">boolean</a><ul class='methods'><li data-type='method'><a href="boolean.html#isBoolean">isBoolean</a></li><li data-type='method'><a href="boolean.html#random">random</a></li></ul></li><li><a href="date.html">date</a><ul class='methods'><li data-type='method'><a href="date.html#isDate">isDate</a></li><li data-type='method'><a href="date.html#random">random</a></li><li data-type='method'><a href="date.html#toTimestamp">toTimestamp</a></li></ul></li><li><a href="function.html">function</a><ul class='methods'><li data-type='method'><a href="function.html#isFunction">isFunction</a></li><li data-type='method'><a href="function.html#proxy">proxy</a></li></ul></li><li><a href="lodash.html">lodash</a><ul class='methods'><li data-type='method'><a href="lodash.html#deepFindBy">deepFindBy</a></li><li data-type='method'><a href="lodash.html#deepMap">deepMap</a></li><li data-type='method'><a href="lodash.html#deepOrderBy">deepOrderBy</a></li><li data-type='method'><a href="lodash.html#filterByValues">filterByValues</a></li><li data-type='method'><a href="lodash.html#isPercentage">isPercentage</a></li><li data-type='method'><a href="lodash.html#parsePercentage">parsePercentage</a></li><li data-type='method'><a href="lodash.html#pullAllByComparator">pullAllByComparator</a></li><li data-type='method'><a href="lodash.html#timesRange">timesRange</a></li><li data-type='method'><a href="lodash.html#timesReverse">timesReverse</a></li></ul></li><li><a href="number.html">number</a><ul class='methods'><li data-type='method'><a href="number.html#between">between</a></li><li data-type='method'><a href="number.html#degreeDiff">degreeDiff</a></li><li data-type='method'><a href="number.html#degreeDir">degreeDir</a></li><li data-type='method'><a href="number.html#degreeWrap">degreeWrap</a></li><li data-type='method'><a href="number.html#floor">floor</a></li><li data-type='method'><a href="number.html#fromRoman">fromRoman</a></li><li data-type='method'><a href="number.html#isNumber">isNumber</a></li><li data-type='method'><a href="number.html#parse">parse</a></li><li data-type='method'><a href="number.html#random">random</a></li><li data-type='method'><a href="number.html#range">range</a></li><li data-type='method'><a href="number.html#round">round</a></li><li data-type='method'><a href="number.html#round">round</a></li><li data-type='method'><a href="number.html#times">times</a></li><li data-type='method'><a href="number.html#toAbsolute">toAbsolute</a></li><li data-type='method'><a href="number.html#toCurrency">toCurrency</a></li><li data-type='method'><a href="number.html#toFileSize">toFileSize</a></li><li data-type='method'><a href="number.html#toRoman">toRoman</a></li><li data-type='method'><a href="number.html#toSymbolString">toSymbolString</a></li></ul></li><li><a href="object.html">object</a><ul class='methods'><li data-type='method'><a href="object.html#clone">clone</a></li><li data-type='method'><a href="object.html#each">each</a></li><li data-type='method'><a href="object.html#inherit">inherit</a></li><li data-type='method'><a href="object.html#isObject">isObject</a></li><li data-type='method'><a href="object.html#omit">omit</a></li><li data-type='method'><a href="object.html#path">path</a></li><li data-type='method'><a href="object.html#pick">pick</a></li></ul></li><li><a href="string.html">string</a><ul class='methods'><li data-type='method'><a href="string.html#camelCase">camelCase</a></li><li data-type='method'><a href="string.html#capitalize">capitalize</a></li><li data-type='method'><a href="string.html#contains">contains</a></li><li data-type='method'><a href="string.html#decodeURI">decodeURI</a></li><li data-type='method'><a href="string.html#encodeURI">encodeURI</a></li><li data-type='method'><a href="string.html#endsWith">endsWith</a></li><li data-type='method'><a href="string.html#escapeHTML">escapeHTML</a></li><li data-type='method'><a href="string.html#escapeHTML">escapeHTML</a></li><li data-type='method'><a href="string.html#extractDomain">extractDomain</a></li><li data-type='method'><a href="string.html#extractFileExtension">extractFileExtension</a></li><li data-type='method'><a href="string.html#extractQueryString">extractQueryString</a></li><li data-type='method'><a href="string.html#guid">guid</a></li><li data-type='method'><a href="string.html#isRoman">isRoman</a></li><li data-type='method'><a href="string.html#isString">isString</a></li><li data-type='method'><a href="string.html#isUrl">isUrl</a></li><li data-type='method'><a href="string.html#pad">pad</a></li><li data-type='method'><a href="string.html#padLeft">padLeft</a></li><li data-type='method'><a href="string.html#padRight">padRight</a></li><li data-type='method'><a href="string.html#parsePercentage">parsePercentage</a></li><li data-type='method'><a href="string.html#parsePercentage">parsePercentage</a></li><li data-type='method'><a href="string.html#replaceAll">replaceAll</a></li><li data-type='method'><a href="string.html#slugify">slugify</a></li><li data-type='method'><a href="string.html#startsWith">startsWith</a></li><li data-type='method'><a href="string.html#stripTags">stripTags</a></li><li data-type='method'><a href="string.html#toArray">toArray</a></li><li data-type='method'><a href="string.html#toInt">toInt</a></li></ul></li></ul><h3><a href="global.html">Global</a></h3> </nav> <div id="main"> <h1 class="page-title">flavor.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import _ from 'lodash'; import CoreExt from './extensions/core'; import LodashExt from './extensions/lodash'; import ObjectExt from './extensions/object'; import FunctionExt from './extensions/function'; import BooleanExt from './extensions/boolean'; import NumberExt from './extensions/number'; import DateExt from './extensions/date'; import StringExt from './extensions/string'; import ArrayExt from './extensions/array'; import release from './release.json'; /** * constructs FlavorJS class &amp; extends the js natives * @class FlavorJS * @classdesc FlavorJS the definitive JS natives chainable extensions methods * @public */ export default class FlavorJS { constructor() { this.init(); } /** * safe js native prototype extension using Object.defineProperty * @memberOf FlavorJS * @method extendPrototypeProperty * @instance * @param {prototype|object} proto - the prototype/object to extend * @param {string} prop - the name of the property to be defined or modified * @param {*} val - val to be used as value in the descriptor for the property, can be any kind of native (number, function, etc...) or what you want * @param {object} [options={}] - options to be used as parameters in the descriptor for the property&lt;br> * possible options are (source documentation from &lt;a href="https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/object/defineProperty" target="_blank">Javascript|MDN docs&lt;/a>)&lt;br> * @param {boolean} [options.configurable=true] configurable - true if and only if the type of this property descriptor may be changed and if the property may be deleted from the corresponding Object. * @param {boolean} [options.enumerable=false] enumerable - true if and only if this property shows up during enumeration of the properties on the corresponding Object. * @param {boolean} [options.writable=true] writable - true if and only if the value associated with the property may be changed with an assignment operator. * @param {function} [options.get=undefined] get - A function which serves as a getter for the property, or undefined if there is no getter. The function return will be used as the value of property.&lt;br> * for example...&lt;br> * &lt;pre> * function ClassName() { * var privateProp = null; * * Object.defineProperty(this, 'publicProp', { * get: function() { * return privateProp; * } * }); * } * &lt;/pre> * @param {function} [options.set=undefined] set - A function which serves as a setter for the property, or undefined if there is no setter. The function will receive as only argument the new value being assigned to the property.&lt;br> * for example...&lt;br> * &lt;pre> * function ClassName() { * var privateProp = null; * * Object.defineProperty(this, 'publicProp', { * set: function(value) { * privateProp = value; * } * }); * } * &lt;/pre> */ extendPrototypeProperty(proto, prop, val, options = {}) { Object.defineProperty(proto, prop, { value: val, writable: true, configurable: true, enumerable: false, }); } /** * merges all keys in extend plain object to the prototype ( * @memberOf FlavorJS * @method extendPrototype * @instance * @param {prototype|object} proto - the prototype/object to extend * @param {object} extend - the extend object to be merged in prototype */ extendPrototype(proto, extend) { _.forOwn(extend, (value, key) => { this.extendPrototypeProperty(proto, key, value); }); } /** * extendLodash * @memberOf FlavorJS * @method extendLodash * @instance */ extendLodash() { _.mixin(LodashExt); } /** * extendObject * @memberOf FlavorJS * @method extendObject * @instance */ extendObject() { this.extendPrototype(Object.prototype, ObjectExt.prototype); this.extendPrototype(Object, ObjectExt.native); } /** * extendFunction * @memberOf FlavorJS * @method extendFunction * @instance */ extendFunction() { this.extendPrototype(Function.prototype, FunctionExt.prototype); this.extendPrototype(Function, FunctionExt.native); } /** * extendBoolean * @memberOf FlavorJS * @method extendBoolean * @instance */ extendBoolean() { this.extendPrototype(Boolean.prototype, BooleanExt.prototype); this.extendPrototype(Boolean, BooleanExt.native); } /** * extendNumber * @memberOf FlavorJS * @method extendNumber * @instance */ extendNumber() { this.extendPrototype(Number.prototype, NumberExt.prototype); this.extendPrototype(Number, NumberExt.native); } /** * extendDate * @memberOf FlavorJS * @method extendDate * @instance */ extendDate() { this.extendPrototype(Date.prototype, DateExt.prototype); this.extendPrototype(Date, DateExt.native); } /** * extendString * @memberOf FlavorJS * @method extendString * @instance */ extendString() { this.extendPrototype(String.prototype, StringExt.prototype); this.extendPrototype(String, StringExt.native); } /** * extendArray * @memberOf FlavorJS * @method extendArray * @instance */ extendArray() { this.extendPrototype(Array.prototype, ArrayExt.prototype); this.extendPrototype(Array, ArrayExt.native); } /** * initialize all * @memberOf FlavorJS * @method init * @instance */ init() { this.extendLodash(); this.extendObject(); this.extendFunction(); this.extendBoolean(); this.extendNumber(); this.extendDate(); this.extendString(); this.extendArray(); const flavorJSStatus = release.version.inherit({ initialized: true, }); Object.inherit(this, CoreExt, flavorJSStatus); console.log('FlavorJS initialized', flavorJSStatus); } } </code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> on Fri Jun 14 2019 15:20:48 GMT+0200 (CEST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>