UNPKG

ubique

Version:

A mathematical and quantitative library for Javascript and Node.js

1,848 lines (1,723 loc) 715 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define(factory); else if(typeof exports === 'object') exports["ubique"] = factory(); else root["ubique"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { module.exports = __webpack_require__(1); /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { /** * name: ubique * version: 0.5.1 * update date: 2015-09-23 * * author: Max Todaro <m.todaro.ge@gmail.com> * homepage: http://maxto.github.io/index.html * * description: A mathematical and quantitative library for Javascript and Node.js * * * The MIT License (MIT) * * Copyright© 2014-2015 Max Todaro * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ var ubique = {}; __webpack_require__(2)(ubique); __webpack_require__(3)(ubique); __webpack_require__(4)(ubique); __webpack_require__(5)(ubique); __webpack_require__(6)(ubique); __webpack_require__(7)(ubique); __webpack_require__(8)(ubique); __webpack_require__(9)(ubique); __webpack_require__(10)(ubique); __webpack_require__(11)(ubique); __webpack_require__(12)(ubique); __webpack_require__(13)(ubique); __webpack_require__(14)(ubique); __webpack_require__(15)(ubique); __webpack_require__(16)(ubique); __webpack_require__(17)(ubique); __webpack_require__(18)(ubique); __webpack_require__(19)(ubique); __webpack_require__(20)(ubique); __webpack_require__(21)(ubique); __webpack_require__(22)(ubique); __webpack_require__(23)(ubique); __webpack_require__(24)(ubique); __webpack_require__(25)(ubique); __webpack_require__(26)(ubique); __webpack_require__(27)(ubique); __webpack_require__(28)(ubique); __webpack_require__(29)(ubique); __webpack_require__(30)(ubique); __webpack_require__(31)(ubique); __webpack_require__(32)(ubique); __webpack_require__(33)(ubique); __webpack_require__(34)(ubique); __webpack_require__(35)(ubique); __webpack_require__(36)(ubique); __webpack_require__(37)(ubique); __webpack_require__(38)(ubique); __webpack_require__(39)(ubique); __webpack_require__(40)(ubique); __webpack_require__(41)(ubique); __webpack_require__(42)(ubique); __webpack_require__(43)(ubique); __webpack_require__(44)(ubique); __webpack_require__(45)(ubique); __webpack_require__(46)(ubique); __webpack_require__(47)(ubique); __webpack_require__(48)(ubique); __webpack_require__(49)(ubique); __webpack_require__(50)(ubique); __webpack_require__(51)(ubique); __webpack_require__(52)(ubique); __webpack_require__(53)(ubique); __webpack_require__(54)(ubique); __webpack_require__(55)(ubique); __webpack_require__(56)(ubique); __webpack_require__(57)(ubique); __webpack_require__(58)(ubique); __webpack_require__(59)(ubique); __webpack_require__(60)(ubique); __webpack_require__(61)(ubique); __webpack_require__(62)(ubique); __webpack_require__(63)(ubique); __webpack_require__(64)(ubique); __webpack_require__(65)(ubique); __webpack_require__(66)(ubique); __webpack_require__(67)(ubique); __webpack_require__(68)(ubique); __webpack_require__(69)(ubique); __webpack_require__(70)(ubique); __webpack_require__(71)(ubique); __webpack_require__(72)(ubique); __webpack_require__(73)(ubique); __webpack_require__(74)(ubique); __webpack_require__(75)(ubique); __webpack_require__(76)(ubique); __webpack_require__(77)(ubique); __webpack_require__(78)(ubique); __webpack_require__(79)(ubique); __webpack_require__(80)(ubique); __webpack_require__(81)(ubique); __webpack_require__(82)(ubique); __webpack_require__(83)(ubique); __webpack_require__(84)(ubique); __webpack_require__(85)(ubique); __webpack_require__(86)(ubique); __webpack_require__(87)(ubique); __webpack_require__(88)(ubique); __webpack_require__(89)(ubique); __webpack_require__(90)(ubique); __webpack_require__(91)(ubique); __webpack_require__(92)(ubique); __webpack_require__(93)(ubique); __webpack_require__(94)(ubique); __webpack_require__(95)(ubique); __webpack_require__(96)(ubique); __webpack_require__(97)(ubique); __webpack_require__(98)(ubique); __webpack_require__(99)(ubique); __webpack_require__(100)(ubique); __webpack_require__(101)(ubique); __webpack_require__(102)(ubique); __webpack_require__(103)(ubique); __webpack_require__(104)(ubique); __webpack_require__(105)(ubique); __webpack_require__(106)(ubique); __webpack_require__(107)(ubique); __webpack_require__(108)(ubique); __webpack_require__(109)(ubique); __webpack_require__(110)(ubique); __webpack_require__(111)(ubique); __webpack_require__(112)(ubique); __webpack_require__(113)(ubique); __webpack_require__(114)(ubique); __webpack_require__(115)(ubique); __webpack_require__(116)(ubique); __webpack_require__(117)(ubique); __webpack_require__(118)(ubique); __webpack_require__(119)(ubique); __webpack_require__(120)(ubique); __webpack_require__(121)(ubique); __webpack_require__(122)(ubique); __webpack_require__(123)(ubique); __webpack_require__(124)(ubique); __webpack_require__(125)(ubique); __webpack_require__(126)(ubique); __webpack_require__(127)(ubique); __webpack_require__(128)(ubique); __webpack_require__(129)(ubique); __webpack_require__(130)(ubique); __webpack_require__(131)(ubique); __webpack_require__(132)(ubique); __webpack_require__(133)(ubique); __webpack_require__(134)(ubique); __webpack_require__(135)(ubique); __webpack_require__(136)(ubique); __webpack_require__(137)(ubique); __webpack_require__(138)(ubique); __webpack_require__(139)(ubique); __webpack_require__(140)(ubique); __webpack_require__(141)(ubique); __webpack_require__(142)(ubique); __webpack_require__(143)(ubique); __webpack_require__(144)(ubique); __webpack_require__(145)(ubique); __webpack_require__(146)(ubique); __webpack_require__(147)(ubique); __webpack_require__(148)(ubique); __webpack_require__(149)(ubique); __webpack_require__(150)(ubique); __webpack_require__(151)(ubique); __webpack_require__(152)(ubique); __webpack_require__(153)(ubique); __webpack_require__(154)(ubique); __webpack_require__(155)(ubique); __webpack_require__(156)(ubique); __webpack_require__(157)(ubique); __webpack_require__(158)(ubique); __webpack_require__(159)(ubique); __webpack_require__(160)(ubique); __webpack_require__(161)(ubique); __webpack_require__(162)(ubique); __webpack_require__(163)(ubique); __webpack_require__(164)(ubique); __webpack_require__(165)(ubique); __webpack_require__(166)(ubique); __webpack_require__(167)(ubique); __webpack_require__(168)(ubique); __webpack_require__(169)(ubique); __webpack_require__(170)(ubique); __webpack_require__(171)(ubique); __webpack_require__(172)(ubique); __webpack_require__(173)(ubique); __webpack_require__(174)(ubique); __webpack_require__(175)(ubique); __webpack_require__(176)(ubique); __webpack_require__(177)(ubique); __webpack_require__(178)(ubique); __webpack_require__(179)(ubique); __webpack_require__(180)(ubique); __webpack_require__(181)(ubique); __webpack_require__(182)(ubique); __webpack_require__(183)(ubique); __webpack_require__(184)(ubique); __webpack_require__(185)(ubique); __webpack_require__(186)(ubique); __webpack_require__(187)(ubique); __webpack_require__(188)(ubique); __webpack_require__(189)(ubique); __webpack_require__(190)(ubique); __webpack_require__(191)(ubique); __webpack_require__(192)(ubique); __webpack_require__(193)(ubique); __webpack_require__(194)(ubique); __webpack_require__(195)(ubique); __webpack_require__(196)(ubique); module.exports = ubique; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { /** * Constants properties */ module.exports = function($u) { /** * Constants values * @type {number} */ $u.Inf = Number.POSITIVE_INFINITY; $u.maxval = Number.MAX_VALUE; $u.minval = Number.MIN_VALUE; $u.PI = Math.PI; $u.E = Math.E; $u.LN2 = Math.LN2; $u.LN10 = Math.LN10; $u.LOG2E = Math.LOG2E; $u.LOG10E = Math.LOG10E; $u.SQRT1_2 = Math.SQRT1_2; $u.SQRT2 = Math.SQRT2; $u.eps = 2.2204460492503130808472633361816E-16; $u.phi = 1.618033988749894848204586834; } /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { /** * External Library */ module.exports = function($u) { // moment.js - Parse, validate, manipulate, and display dates in JavaScript (http://momentjs.com/) $u.__moment = __webpack_require__(198); // request.js - Simplified HTTP request client (https://github.com/request/request) $u.__request = __webpack_require__(197); // sync-request.js - Make synchronous web requests with cross platform support (https://github.com/ForbesLindesay/sync-request) $u.__syncrequest = __webpack_require__(199); } /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { /** * Structures */ module.exports = function($u) { /** * @method arrayfun * @summary Apply function to each element of an array or matrix * @description Apply function to each element of an array or matrix. First arg is input element, the second one the function to apply, * then the parameters of the function. * * @param {number|string|boolean|...} args variable input arguments * @return {number|string|boolean|...} * * @example * ubique.arrayfun([1.4,2.3,3],Math.log); * // [ 0.336472, 0.832909, 1.098612 ] * * ubique.arrayfun([1.4,0,-10],ubique.sign); * // [ 1, 0, -1 ] * * ubique.arrayfun([[5,6],[1,3]],Math.pow,3); * // [ [ 125, 216 ], [ 1, 27 ] ] * * ubique.arrayfun([['cat','concat'],['cattle','catch the catfish']],ubique.strfind,'cat'); * // [ [ [ 0 ], [ 3 ] ], [ [ 0 ], [ 0, 10 ] ] ] * * ubique.arrayfun([null,true,'hello',5,NaN],ubique.isnull); * // [ true, false, false, false, false ] * * ubique.arrayfun([null,true,'hello',5,NaN],ubique.islogical); * // [ false, true, false, false, false ] * * ubique.arrayfun([null,true,'hello',5,NaN],ubique.isstring); * // [ false, false, true, false, false ] * * ubique.arrayfun([null,true,'hello',5,NaN],ubique.isnumber); * // [ false, false, false, true, true ] * * ubique.arrayfun([null,true,'hello',5,{},undefined,'NaN',NaN],ubique.isnan); * // [ false, false, false, false, false, false, false, true ] */ $u.arrayfun = function() { if (arguments.length < 2) { throw new Error('not enough input arguments'); } var args = $u.argsarray.apply(null,arguments); var x = args[0]; var fun = args[1]; if (!$u.isfunction(fun)) { throw new Error('second input argument must be a function'); } if ($u.isarray(x)) { return x.map(function(a) { return fun.apply(null,[].concat(a,args.slice(2,args.length))); }); } if ($u.ismatrix(x)) { return x.map(function(a) { return a.map(function(b) { return fun.apply(null,[].concat(b,args.slice(2,args.length))); }); }); } return fun.apply(null,[].concat(x,args.slice(2,args.length))); } } /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method clock * @summary Current date and time as date vector * @description Current date and time as date vector. Returns an array: * [year month day hour minute seconds] * * @param {empty} empty no arguments * @return {array} * * @example * ubique.clock(); * // [ 2015, 5, 28, 11, 51, 0, 801 ] */ $u.clock = function() { var now = $u.__moment().toArray(); now[1] = now[1] + 1; return now; } } /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method datevec * @summary Convert date and time to vector of components * @description Convert date and time to vector of components. Based on [moment.js](http://momentjs.com) * * |Identifier| Example | Description | * | ----------- | ---------------- | ----------- | * | `YYYY` | `2014` | 4 digit year | * | `YY` | `14` | 2 digit year | * | `Q` | `1..4` | Quarter of year. Sets month to first month in quarter. | * | `M MM` | `1..12` | Month number | * | `MMM MMMM` | `January..Dec` | Month name in locale set by `moment.locale()` | * | `D DD` | `1..31` | Day of month | * | `Do` | `1st..31st` | Day of month with ordinal | * | `DDD DDDD` | `1..365` | Day of year | * | `X` | `1410715640.579` | Unix timestamp | * | `x` | `1410715640579` | Unix ms timestamp | * | * | `gggg` | `2014` | Locale 4 digit week year | * | `gg` | `14` | Locale 2 digit week year | * | `w ww` | `1..53` | Locale week of year | * | `e` | `1..7` | Locale day of week | * | `GGGG` | `2014` | ISO 4 digit week year | * | `GG` | `14` | ISO 2 digit week year | * | `W WW` | `1..53` | ISO week of year | * | `E` | `1..7` | ISO day of week | * | * | `H HH` | `0..23` | 24 hour time | * | `h hh` | `1..12` | 12 hour time used with `a A`. | * | `a A` | `am pm` | Post or ante meridiem | * | `m mm` | `0..59` | Minutes | * | `s ss` | `0..59` | Seconds | * | `S` | `0..9` | Tenths of a second | * | `SS` | `0..99` | Hundreds of a second | * | `SSS` | `0..999` | Thousandths of a second | * | `Z ZZ` | `+12:00` | Offset from UTC as `+-HH:mm`, `+-HHmm`, or `Z` | * * @param {string|number|array|matrix} d string or number (unix) * @param {string} fmt format string * @return {array|matrix} * * @example * ubique.datevec('2015-01-01 03:34:05','YYYY-MM-DD HH:mm:ss'); * // [ 2015, 1, 1, 3, 34, 5, 0 ] * * ubique.datevec(['31-12-2014','31-01-2015'],'DD-MM-YYYY'); * // [ [ 2014, 12, 31, 0, 0, 0, 0 ], [ 2015, 1, 31, 0, 0, 0, 0 ] ] * * ubique.datevec([['31-12-2014','31-01-2015'],['15-02-2015','01-03-2015']],'DD-MM-YYYY'); * // [ [ [ 2014, 12, 31, 0, 0, 0, 0 ], [ 2015, 1, 31, 0, 0, 0, 0 ] ], * // [ [ 2015, 2, 15, 0, 0, 0, 0 ], [ 2015, 3, 1, 0, 0, 0, 0 ] ] ] * * // from '2015-04-05 12:20:30' to Unix 1428236430 * ubique.datevec(1428236430); * // [ 2015, 4, 5, 12, 20, 30, 0 ] */ $u.datevec= function(d,fmt) { if (arguments.length < 1) { throw new Error('not enough input arguments'); } if ($u.isstring(d)) { if (!fmt) { throw new Error('insert format for date string'); } } // Note: because this mirrors the native Date parameters, // months, hours, minutes, seconds, and milliseconds are all zero indexed. // Years and days of the month are 1 indexed. var _datevec = function(a,fmt) { if ($u.isstring(a)) { var dv = $u.__moment(a,fmt).toArray(); } else if ($u.isnumber(a)) { var dv = $u.__moment.utc(a,'X').toArray(); } else { throw new Error('input must be a string or unix timestamp'); } dv[1] = dv[1] + 1; return dv; } return $u.arrayfun(d,_datevec,fmt); } } /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method datenum * @summary Convert date and time to serial date number (Unix) * @description Convert date and time to serial date number (Unix). Based on [moment.js](http://momentjs.com) * * |Identifier| Example | Description | * | ----------- | ---------------- | ----------- | * | `YYYY` | `2014` | 4 digit year | * | `YY` | `14` | 2 digit year | * | `Q` | `1..4` | Quarter of year. Sets month to first month in quarter. | * | `M MM` | `1..12` | Month number | * | `MMM MMMM` | `January..Dec` | Month name in locale set by `moment.locale()` | * | `D DD` | `1..31` | Day of month | * | `Do` | `1st..31st` | Day of month with ordinal | * | `DDD DDDD` | `1..365` | Day of year | * | `X` | `1410715640.579` | Unix timestamp | * | `x` | `1410715640579` | Unix ms timestamp | * | * | `gggg` | `2014` | Locale 4 digit week year | * | `gg` | `14` | Locale 2 digit week year | * | `w ww` | `1..53` | Locale week of year | * | `e` | `1..7` | Locale day of week | * | `GGGG` | `2014` | ISO 4 digit week year | * | `GG` | `14` | ISO 2 digit week year | * | `W WW` | `1..53` | ISO week of year | * | `E` | `1..7` | ISO day of week | * | * | `H HH` | `0..23` | 24 hour time | * | `h hh` | `1..12` | 12 hour time used with `a A`. | * | `a A` | `am pm` | Post or ante meridiem | * | `m mm` | `0..59` | Minutes | * | `s ss` | `0..59` | Seconds | * | `S` | `0..9` | Tenths of a second | * | `SS` | `0..99` | Hundreds of a second | * | `SSS` | `0..999` | Thousandths of a second | * | `Z ZZ` | `+12:00` | Offset from UTC as `+-HH:mm`, `+-HHmm`, or `Z` | * * @param {string|array|matrix} d string vector of components * @param {string} fmt format string * @return {string|array|matrix} * * @example * ubique.datenum('31-12-2014','DD-MM-YYYY'); * // 1419984000 * * ubique.datenum(['31-12-2014','31-01-2015'],'DD-MM-YYYY'); * // [ 1419984000, 1422662400 ] * * ubique.datenum([['31-12-2014','31-01-2015'],['15-02-2015','01-03-2015']],'DD-MM-YYYY'); * // [ [ 1419984000, 1422662400 ], [ 1423958400, 1425168000 ] ] * * ubique.datenum([ 2015, 4, 5, 12, 20, 30, 0 ]); * // 1428236430 * * ubique.datenum([ [ 2013, 1, 31, 0, 0, 0, 0 ],[ 2014, 2, 28, 0, 0, 0, 0 ],[ 2015, 4, 30, 0, 0, 0, 0 ] ]); * // [ 1359590400, 1393545600, 1430352000 ] */ $u.datenum = function(d,fmt) { if (arguments.length < 1) { throw new Error('not enough input arguments'); } if ($u.isstring(d)) { if (!fmt) { throw new Error('insert format for date string'); } } var _datenum = function(a,fmt) { return $u.__moment.utc(a,fmt).unix(); } if ($u.isstring(d)) { return _datenum(d,fmt); } if ($u.isarray(d)) { var checknum = d.filter(function(el) { return $u.isnumber(el); }); if (checknum.length === d.length) { return $u.__moment.utc(d,'YYYYMMDDhhmmss').unix(); } else { return $u.arrayfun(d,_datenum,fmt); } } if ($u.ismatrix(d)) { if ($u.isarray(d[0])) { return d.map(function(a) { return $u.datenum(a,fmt); }); } return $u.arrayfun(d,_datenum,fmt); } } } /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method datestr * @summary Convert serial date number (Unix) to string format * @description Convert serial date number (Unix) to string format. Based on [moment.js](http://momentjs.com) * * |Identifier| Example | Description | * | ----------- | ---------------- | ----------- | * | `YYYY` | `2014` | 4 digit year | * | `YY` | `14` | 2 digit year | * | `Q` | `1..4` | Quarter of year. Sets month to first month in quarter. | * | `M MM` | `1..12` | Month number | * | `MMM MMMM` | `January..Dec` | Month name in locale set by `moment.locale()` | * | `D DD` | `1..31` | Day of month | * | `Do` | `1st..31st` | Day of month with ordinal | * | `DDD DDDD` | `1..365` | Day of year | * | `X` | `1410715640.579` | Unix timestamp | * | `x` | `1410715640579` | Unix ms timestamp | * | * | `gggg` | `2014` | Locale 4 digit week year | * | `gg` | `14` | Locale 2 digit week year | * | `w ww` | `1..53` | Locale week of year | * | `e` | `1..7` | Locale day of week | * | `GGGG` | `2014` | ISO 4 digit week year | * | `GG` | `14` | ISO 2 digit week year | * | `W WW` | `1..53` | ISO week of year | * | `E` | `1..7` | ISO day of week | * | * | `H HH` | `0..23` | 24 hour time | * | `h hh` | `1..12` | 12 hour time used with `a A`. | * | `a A` | `am pm` | Post or ante meridiem | * | `m mm` | `0..59` | Minutes | * | `s ss` | `0..59` | Seconds | * | `S` | `0..9` | Tenths of a second | * | `SS` | `0..99` | Hundreds of a second | * | `SSS` | `0..999` | Thousandths of a second | * | `Z ZZ` | `+12:00` | Offset from UTC as `+-HH:mm`, `+-HHmm`, or `Z` | * * @param {number|array|matrix} d ISO Unix datetime * @param {string} fmt format string (def: 'YYYY-MM-DD') * @return {number|array|matrix} * * @example * ubique.datestr(1419984000); * // 2014-12-31 * * ubique.datestr([ 1419984000, 1422662400 ],'DD-MMM-YY'); * // [ '31-Dec-14', '31-Jan-15' ] * * ubique.datestr([ [ 1419984000, 1422662400 ], [ 1423958400, 1425168000 ] ],'YY-MM-DD hh:mm:ss'); * // [ [ '14-12-31 12:00:00', '15-01-31 12:00:00' ], * // [ '15-02-15 12:00:00', '15-03-01 12:00:00' ] ] */ $u.datestr = function(d,fmt) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } fmt = fmt == null ? 'YYYY-MM-DD' : fmt; var _datestr = function(a,fmt) { return $u.__moment.utc(a,'X').format(fmt); } return $u.arrayfun(d,_datestr,fmt); } } /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { /** * Array Creation and Concatenation */ module.exports = function($u) { /** * @method isarray * @summary True for array * @description True for array * * @param {array} x input element * @return {boolean} * * @example * ubique.isarray([1.4,2.3,3]); * // true */ $u.isarray = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return Array.isArray(x) && !Array.isArray(x[0]); } } /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { /** * Array Dimensions */ module.exports = function($u) { /** * @method isempty * @summary True for empty array or matrix * @description True for empty array or matrix * * @param {array|matrix} x input matrix * @return {Boolean} * * @example * ubique.isempty([]); * // true * * ubique.isempty([[]]); * // true */ $u.isempty = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } if ($u.isarray(x) && x.length === 0) { return true; } if ($u.ismatrix(x) && x[0].length === 0) { return true; } return false; } } /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { /** * Data Type Identification */ module.exports = function($u) { /** * @method isfunction * @summary True for function * @description true for function * * @param {function} x function * @return {Boolean} * * @example * ubique.isfunction(function(a){return console.log(a);}); * // true * * ubique.isfunction(Math.log); * // true */ $u.isfunction = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return typeof x === 'function'; } } /***/ }, /* 12 */ /***/ function(module, exports, __webpack_require__) { /** * Data Type Identification */ module.exports = function($u) { /** * @method isinteger * @summary True for integer * @description True for integer * * @param {number} x element * @return {boolean} * * @example * ubique.isinteger(5); * // true */ $u.isinteger = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return $u.isnumber(x) && Math.round(x) === x; } } /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { /** * Logical Operations */ module.exports = function($u) { /** * @method islogical * @summary True for logical input * @description True for logical input * * @param {boolean} x element * @return {boolean} * * @example * ubique.islogical(true); * // true */ $u.islogical = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return typeof x === 'boolean'; } } /***/ }, /* 14 */ /***/ function(module, exports, __webpack_require__) { /** * Array Dimensions */ module.exports = function($u) { /** * @method ismatrix * @summary True for matrix * @description True for array of array (matrix) * * @param {matrix} x matrix * @return {Boolean} * * @example * ubique.ismatrix([[1,3,4]]); * // true * * ubique.ismatrix([[1],[3],[4]]); * // true */ $u.ismatrix = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } if ($u.isundefined(x) || $u.isnull(x) || !$u.isarray(x[0])) { return false; } return $u.isarray(x[0]); } } /***/ }, /* 15 */ /***/ function(module, exports, __webpack_require__) { /** * Numeric Types */ module.exports = function($u) { /** * @method isnan * @summary True only for NaN input * @description True only for NaN input. For [null,true,'hello',5,{},undefined,'NaN'] returns False. * * @param {NaN} x element * @return {boolean} * * @example * ubique.isnan(NaN); * // true */ $u.isnan = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return x != x; } } /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { /** * Data Type Identification */ module.exports = function($u) { /** * @method isnull * @summary True for null values * @description True for null values * * @param {null} x element * @return {boolean} * * @example * ubique.isnull(null); * // true */ $u.isnull = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return x === null; } } /***/ }, /* 17 */ /***/ function(module, exports, __webpack_require__) { /** * Data Type Identification */ module.exports = function($u) { /** * @method isnumber * @summary True for number * @description True for number or NaN value * * @param {number} x element * @return {boolean} * * @example * ubique.isnumber(5); * // true * ubique.isnumber(NaN); * // true */ $u.isnumber = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return typeof x === 'number'; } } /***/ }, /* 18 */ /***/ function(module, exports, __webpack_require__) { /** * Array Dimensions */ module.exports = function($u) { /** * @method isscalar * @summary True for scalar input * @description True for scalar input * * @param {number|array|matrix} x input * @return {Boolean} * * @example * ubique.isscalar(2); * // true * * ubique.isscalar([2]); * // true * * ubique.isscalar([[2]]); * // true */ $u.isscalar = function(x) { if ($u.nrows(x) === 1 && $u.ncols(x) === 1) { return true; } return false; } } /***/ }, /* 19 */ /***/ function(module, exports, __webpack_require__) { /** * Matrix Types */ module.exports = function($u) { /** * @method issingular * @summary True for singular matrix * @description True for singular matrix. A square matrix which does not have an inverse. A matrix is singular if and only if its determinant is zero. * * @param {matrix} x input matrix * @return {boolean} * * @example * ubique.issingular([[2,6],[1,3]]); * // false */ $u.issingular = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } if ($u.isnumber(x) || $u.isarray(x)) { throw new Error('input must be a matrix'); } if (!$u.issquare(x)) { throw new Error('input must be a square matrix'); } var n = $u.ncols(x); for (var i = 0;i < n;i++) { if (x[i][i] === 0) { return true; } } return false; } } /***/ }, /* 20 */ /***/ function(module, exports, __webpack_require__) { /** * Data Type Identification */ module.exports = function($u) { /** * @method isstring * @summary True for string values * @description True for string values * * @param {string} x element * @return {boolean|array} * * @example * ubique.isstring('test'); * // true */ $u.isstring = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return typeof x === 'string'; } } /***/ }, /* 21 */ /***/ function(module, exports, __webpack_require__) { /** * Data Type Identification */ module.exports = function($u) { /** * @method isundefined * @summary True for undefined values * @description True for undefined values * * @param {undefined} x element * @return {boolean} * * @example * ubique.isundefined(undefined); * // true */ $u.isundefined = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } return x === undefined; } } /***/ }, /* 22 */ /***/ function(module, exports, __webpack_require__) { /** * Array Dimensions */ module.exports = function($u) { /** * @method isvector * @summary True for vector input * @description True for vector input. Vector can have the same dimension of array but array is array and vector * is an array of array (= matrix with 1 column or row) * * @param {matrix} x matrix with dimension Mx1 or 1xN * @return {boolean} * * @example * ubique.isvector([[5,6,7]]); * // true * * ubique.isvector([[5],[6],[7]]); * // true */ $u.isvector = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } if ($u.ismatrix(x)) { if (($u.iscolumn(x) === true) || ($u.isrow(x) === true)) { return true; } return false; } return false; } } /***/ }, /* 23 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method month * @summary Month of date * @description Returns a number representing the month for each element in X. * Months are 0 indexed, Jan is 0 and Dec is 11. * Based on [moment.js](http://momentjs.com) * * @param {number|array|matrix} x serial date number (Unix) * @return {number|array|matrix} * * @example * ubique.month(1424708525); * // 1 * * ubique.month([1414886399,1414972799]); * // [ 10, 10 ] * * ubique.month([[1414886399,1414972799],[1415059199,1415145599]]); * // [ [ 10, 10 ], [ 10, 10 ] ] */ $u.month = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } var _month = function(a) { return $u.__moment.unix(a).month(); } return $u.arrayfun(x,_month); } } /***/ }, /* 24 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method now * @summary Current date and time as date number (unix) * @description Current date and time as date number (unix) * * @param {empty} empty no arguments * * @example * ubique.now(); * // 1430759861 */ $u.now = function() { return $u.datenum($u.clock()); } } /***/ }, /* 25 */ /***/ function(module, exports, __webpack_require__) { /** * Create and Concatenate Strings */ module.exports = function($u) { /** * @method randchar * @summary Generate a random alpha-numeric string * @description Generate a random alpha-numeric string * * @param {number} n number of characters to generate (def: 6) * @param {string} strset character set to get random sample * @return {string} * * @example * ubique.randchar(12,'ABCD!-|/%&$\1234567890'); * // D&80%BB/C%B * * ubique.randchar(16,'ABCDEFGHILMNOPQRSTUVZ-1234567890'); * // U68MP-U7ZI26T2HS */ $u.randchar = function(n,strset) { if (arguments.length === 0) { return ''; } strset = strset == null ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' : strset; return Array.apply(0, Array(n)).map(function() { return (function(charset) { return charset.charAt(Math.floor(Math.random() * charset.length)) }(strset)); }).join('') } } /***/ }, /* 26 */ /***/ function(module, exports, __webpack_require__) { /** * Parse Strings */ module.exports = function ($u) { /** * @method strfind * @summary Find one string within another * @description Find one string within another. If pattern length > text length returns null. * * @param {string} str data to be searched * @param {string} pattern search pattern * @return {array} indices of occurrences of pattern * * @example * var mystr = 'find indices in the string'; * * ubique.strfind(mystr,'in'); * // [ 1, 5, 13, 23 ] */ $u.strfind = function (str,pattern) { if (arguments.length < 2) { throw new Error('not enough input arguments'); } if ($u.isstring(str) && $u.isstring(pattern) && (str.length >= pattern.length)) { var i = str.indexOf(pattern); var posidx = []; while(i >= 0) { posidx.push(i); i = str.indexOf(pattern, i + 1); } return posidx; } else { throw new Error('unknown arguments'); } } } /***/ }, /* 27 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method today * @summary Current date * @description Current date * * @param {empty} empty no arguments * * @example * ubique.today(); * // 1430697600 */ $u.today = function() { var t = $u.clock(); return $u.datenum([t[0],t[1],t[2]]); } } /***/ }, /* 28 */ /***/ function(module, exports, __webpack_require__) { /** * Structures */ module.exports = function($u) { /** * @method vectorfun * @summary Apply a function to each vector column or row of a matrix * @description Apply a function to each vector column or row of a matrix. The syntax is: * * vectorfun(dim,x,func,arg1,arg2....) * * @param {number|string|boolean|...} args variable input arguments * @return {number|string|boolean|...} * * @example * var testfun = function(a,b,c){return ubique.mean(a)*b+c;}; * * ubique.vectorfun(0,[[5,6,5],[7,8,-1]],testfun,5,10) * // [ [ 36.666667 ], [ 33.333333 ] ] * * ubique.vectorfun(1,[[5,6,5],[7,8,-1]],testfun,5,10) * // [ [ 40, 45, 20 ] ] */ $u.vectorfun = function() { if (arguments.length < 3) { throw new Error('not enough input arguments'); } var args = $u.argsarray.apply(null,arguments); var argslen = args.length; var dim = args[0]; var x = args[1]; var fun = args[2]; var varargin = args.slice(3,args.length); if (dim !== 0 && dim !== 1) { throw new Error('dimension must be 0 (rows) or 1 (columns)'); } if (!$u.isfunction(fun)) { throw new Error('third input argument must be a function'); } if (dim === 1) { var ndim = $u.ncols(x); var narray = $u.getcol; } if (dim === 0) { var ndim = $u.nrows(x); var narray = $u.getrow; } if ($u.isarray(x)) { if ($u.isempty(varargin)) { return fun.apply(null,[x]); } return fun.apply(null,[].concat([x]).concat(varargin)); } var v = []; if ($u.ismatrix(x)) { for (var i = 0; i < ndim; i++) { var d = narray(x,i); var temp = fun.apply(null,[].concat([d]).concat(varargin)); v.push(temp); } } if (dim === 1) { if ($u.isarray(v)) { return [v]; } return $u.squeeze($u.transpose(v)); } if (dim === 0) { if ($u.isarray(v)) { return $u.transpose(v); } } return $u.squeeze(v); } } /***/ }, /* 29 */ /***/ function(module, exports, __webpack_require__) { /** * Dates and Time */ module.exports = function($u) { /** * @method weekday * @summary Day of week * @description Returns a number representing the day of the week for each element in X. * The ISO day of the week begins with 1 Monday, 2 Tuesday ... 7 Sunday. * Based on [moment.js](http://momentjs.com) * * @param {number|array|matrix} x serial date number (Unix) * @return {number|array|matrix} * * @example * ubique.weekday(1426636800); * // 3 * * ubique.weekday([ 1424908800, 1426636800 ]); * // [ 4, 3 ] * * ubique.weekday([ [ 1424908800, 1426636800 ], [ 1427328000, 1429315200 ] ]); * // [ [ 4, 3 ], [ 4, 6 ] ] */ $u.weekday = function(x) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } var _weekday = function(a) { return $u.__moment.utc(a,'X').isoWeekday(); } return $u.arrayfun(x,_weekday); } } /***/ }, /* 30 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method ceil * @summary Round toward positive infinity * @description Round toward positive infinity * * @param {number|array|matrix} x number or array of values * @param {number} x number of decimals * @return {number|array|matrix} * * @example * ubique.ceil(Math.PI,12); * // 3.141593 * * ubique.ceil(3.78); * // 4 * * ubique.ceil([4.51,-1.4]); * // [ 5, -1 ] * * ubique.ceil([[4.5134,-1.4345],[3.7809,0.0134]],2); * // [ [ 4.52, -1.43 ], [ 3.79, 0.02 ] ] */ $u.ceil = function(x,n) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } n = n == null ? 0 : n; var p = Math.pow(10,n); var _ceil = function(a) { return Math.ceil(a * p) / p; } return $u.arrayfun(x,_ceil); } } /***/ }, /* 31 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method cumdev * @summary Cumulative mean deviation * @description Cumulative mean deviation of the values in array X * * @param {array|matrix} x array or matrix of values * @param {number} dim dimension selected, 1: column 0: row (def: 1) * @return {array|matrix} * * @example * var b = [[-1,3,-1],[4,5,9]]; * var c = [5,6,3]; * * ubique.cumdev([5,6,3]); * // [ 0.333333, 1.666667, -0 ] * * ubique.cumdev([[-1,3,-1],[4,5,9]],0); * // [ [ -1.333333, 1.333333, 0 ], [ -2, -3, 0 ] ] * * ubique.cumdev([[-1,3,-1],[4,5,9]]); * // [ [ -2.5, -1, -5 ], [ 0, 0, 0 ] ] */ $u.cumdev = function(x,dim) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } dim = dim == null ? 1 : dim; var _cumdev = function(a) { return $u.cumsum($u.minus(a,$u.mean(a))); } return $u.vectorfun(dim,x,_cumdev); } } /***/ }, /* 32 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method cummax * @summary Cumulative max of array elements * @description Cumulative max of array elements * * @param {array|matrix} x array or matrix of values * @param {number} dim dimension selected, 1: column 0: row (def: 1) * @return {array|matrix} * * @example * ubique.cummax([5,6,3]); * // [ 5, 6, 6 ] * * ubique.cummax([[5,6,5],[7,8,-1]]); * // [ [ 5, 6, 5 ], [ 7, 8, 5 ] ] * * ubique.cummax([[5,6,5],[7,8,-1]],0); * // [ [ 5, 6, 6 ], [ 7, 8, 8 ] ] */ $u.cummax = function(x,dim) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } dim = dim == null ? 1 : dim; var _cummax = function(a) { var v = []; v[0] = a[0]; for (var i = 1;i < a.length;i++) { if (a[i] >= v[i - 1]) { v[i] = a[i]; } else { v[i] = v[i - 1]; } } return v; } return $u.vectorfun(dim,x,_cummax); } } /***/ }, /* 33 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method cummin * @summary Cumulative min of array elements * @description Cumulative min of array elements * * @param {array|matrix} x array or matrix of values * @param {number} dim dimension selected, 1: column 0: row (def: 1) * @return {array|matrix} * * @example * ubique.cummin([5,6,3]); * // [ 5, 5, 3 ] * * ubique.cummin([[5,6,5],[7,8,-1]]); * // [ [ 5, 6, 5 ], [ 5, 6, -1 ] ] * * ubique.cummin([[5,6,5],[7,8,-1]],0); * // [ [ 5, 5, 5 ], [ 7, 7, -1 ] ] */ $u.cummin = function(x,dim) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } dim = dim == null ? 1 : dim; var _cummin = function(a) { var v = []; v[0] = a[0]; for (var i = 1;i < a.length;i++) { if (a[i] < v[i - 1]) { v[i] = a[i]; } else { v[i] = v[i - 1]; } } return v; } return $u.vectorfun(dim,x,_cummin); } } /***/ }, /* 34 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method cumprod * @summary Cumulative product of array elements * @description Cumulative product of array elements * * @param {array|matrix} x array or matrix of values * @param {number} dim dimension selected, 1: column 0: row (def: 1) * @return {array|matrix} * * @example * ubique.cumprod([5,6,3]); * // [ 5, 30, 90 ] * * ubique.cumprod([[5,6,5],[7,8,-1]]); * // [ [ 5, 6, 5 ], [ 35, 48, -5 ] ] * * ubique.cumprod([[5,6,5],[7,8,-1]],0); * // [ [ 5, 30, 150 ], [ 7, 56, -56 ] ] */ $u.cumprod = function(x,dim) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } dim = dim == null ? 1 : dim; var _cumprod = function(a) { var v = []; v[0] = a[0]; for (var i = 1;i < a.length;i++) { v[i] = v[i - 1] * a[i]; } return v; } return $u.vectorfun(dim,x,_cumprod); } } /***/ }, /* 35 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method cumsum * @summary Cumulative sum of array elements * @description Cumulative sum of array elements * * @param {array|matrix} x array or matrix of values * @param {number} dim dimension selected, 1: column 0: row (def: 1) * @return {array|matrix} * * @example * ubique.cumsum([5,6,3]); * // [5, 11, 14] * * ubique.cumsum([[5,6,5],[7,8,-1]]); * // [ [ 5, 6, 5 ], [ 12, 14, 4 ] ] * * ubique.cumsum([[5,6,5],[7,8,-1]],0); * // [ [ 5, 11, 16 ], [ 7, 15, 14 ] ] */ $u.cumsum = function(x,dim) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } dim = dim == null ? 1 : dim; var _cumsum = function(a) { var v = []; v[0] = a[0]; for (var i = 1;i < a.length;i++) { v[i] = v[i - 1] + a[i]; } return v; } return $u.vectorfun(dim,x,_cumsum); } } /***/ }, /* 36 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method diff * @summary Differences between adjacent elements in array * @description Differences between adjacent elements in array or matrix * * @param {array|matrix} x array of values * @param {number} dim dimension selected, 1: column 0: row (def: 1) * @return {array|matrix} * * @example * ubique.diff([5,6,3]); * // [1, -3] * * ubique.diff([[5,6,5],[7,8,-1]]); * // [ [ 2, 2, -6 ] ] * * ubique.diff([[5,6,5],[7,8,-1]],0); * // [ [ 1, -1 ], [ 1, -9 ] ] */ $u.diff = function(x,dim) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } dim = dim == null ? 1 : dim; var _diff = function(a) { var v = []; for (var i = 1;i < a.length;i++) { v[i - 1] = a[i] - a[i - 1]; } return v; } return $u.vectorfun(dim,x,_diff); } } /***/ }, /* 37 */ /***/ function(module, exports, __webpack_require__) { /** * Arithmetic Operations */ module.exports = function($u) { /** * @method dot * @summary Arrays dot product X * Y * @description Arrays dot product X * Y. X and Y must be arrays of the same length * * @param {array} x number or array of values * @param {array} y number or array of values * @return {array} * * @example * ubique.dot([5,6,3],[0.5,-3,2.3]); * // -8.6 */ $u.dot = function(x,y) { if (arguments.length === 0) { throw new Error('not enough input arguments'); } if ($u.size(x)[0] !== $u.size(y)[0] || $u.size(x)[1] !== $u.size(y)[1]) { throw new Error('input size mismatch'); } return $u.sum($u.times(x,y)); } } /***/ }, /* 38 */ /***/ function(module, exports, __webpack_require__) { /** * Relational Operations */ module.exports = function($u) { /** * @method eq * @summary Equality X === Y * @description Equality X === Y * * @param {number|array|matrix} x left array * @param {number|array|matrix} y right array * @return {number|array|matrix} * * @example * ubique.eq(5,5); * // true * * ubique.eq(5,[5,6,3]); * // [ true, false, false ] * * ubique.eq(5,[[5,6],[3,5]]); * // [ [ true, false ], [ false, true ] ] * * ubique.eq([5,6,3],5); * // [ true, false, false ] * * ubique.eq([[5,6],[3,5]],5); * // [ [ true, false ], [ false, true ] ] * * ubique.eq([5,6,3],[2,6,0]); * // [ false, true, false ] * * ubique.eq([[5,6],[-1,2]],[[5,6],[3,5]]); * // [ [ true, true ], [ false, false ] ] */ $u.eq = function(x,y) { if (arguments.length < 2) { throw new Error('not enough inp