@terminus/ngx-tools
Version:
[![CircleCI][circle-badge]][circle-link] [![codecov][codecov-badge]][codecov-project] [![semantic-release][semantic-release-badge]][semantic-release] [![MIT License][license-image]][license-url] <br> [![NPM version][npm-version-image]][npm-url] [![Github
16 lines (14 loc) • 8.59 kB
JavaScript
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@terminus/ngx-tools/type-guards"),require("@angular/forms"),require("@terminus/ngx-tools/coercion"),require("rxjs"),require("rxjs/internal/scheduler/async"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@terminus/ngx-tools/utilities",["exports","@terminus/ngx-tools/type-guards","@angular/forms","@terminus/ngx-tools/coercion","rxjs","rxjs/internal/scheduler/async","rxjs/operators"],e):e(((r=r||self).terminus=r.terminus||{},r.terminus["ngx-tools"]=r.terminus["ngx-tools"]||{},r.terminus["ngx-tools"].utilities={}),r.terminus["ngx-tools"]["type-guards"],r.ng.forms,r.terminus["ngx-tools"].coercion,r.rxjs,r.rxjs["internal/scheduler/async"],r.rxjs.operators)}(this,(function(r,e,t,n,o,i,u){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var a=function(){return(a=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)};function s(r){var e="function"==typeof Symbol&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&"number"==typeof r.length)return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function l(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,o,i=t.call(r),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(r){o={error:r}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return u}var c={};function f(r){if(c[r])throw new Error("Action type '"+r+"' is not unique!");return c[r]=!0,r}function p(r){var e=r.validator?r.validator({}):null;return!(!e||!e.required)}var v=function(r){var e=r.jitter,t=void 0===e||e,n=r.jitterFactor,o=void 0===n?.3:n,i=r.backOffFactor,u=void 0===i?2:i,a=r.baseWaitTime,s=void 0===a?100:a;return function(r){var e=s*Math.pow(u,r);return t&&(e*=1-o*Math.random()),e}};function d(r,t){return e.isString(r)||e.isBoolean(r)||!r?r:(r=r[(t=e.isArray(t)?t:t.split("."))[0]])&&t.length>1?d(r,t.slice(1)):r}var y=function(){function r(){}return r.getOldValue=function(r,e){var t=l(this.parsePath(e),2),n=t[0],o=t[1];return o&&r[o]?d(r[o].previousValue,n):void 0},r.getNewValue=function(r,e){var t=l(this.parsePath(e),2),n=t[0],o=t[1];return o&&r[o]?d(r[o].currentValue,n):void 0},r.parsePath=function(r){var e=r.split("."),t=e.shift();return t||(t=e[0]),[e,t]},r}();function h(r,e){if(r&&e)return y.getOldValue(r,e)!==y.getNewValue(r,e)}var g=function(r,e){return e?r.charAt(0).toUpperCase()+r.slice(1):r},m=g;function b(r){if(r.componentDestroyed$)return r.componentDestroyed$;var e=r.ngOnDestroy,t=new o.ReplaySubject;return r.ngOnDestroy=function(){e&&e.apply(r),t.next(!0),t.complete()},r.componentDestroyed$=t.asObservable(),r.componentDestroyed$}var w=function(r){this.full=r;var e=r.split(".");this.major=e[0],this.minor=e[1],this.patch=e.slice(2).join(".")},x=new w("8.0.6");r.NgChangeObjectValueParser=y,r.VERSION=x,r.Version=w,r.abbreviateNumber=function(r,e){if(void 0===e&&(e=1),!r)return"";var t=r.toExponential().split("e+").map((function(r){return+r}));if(t[1]<3)return r.toString();var n=t[1]%3;t[0]=t[0]*Math.pow(10,n);var o=["","K","M","B","T"][(t[1]-n)/3];return t[0].toFixed(e).toString()+o},r.applyMixins=function(r,e){e.forEach((function(e){Object.getOwnPropertyNames(e.prototype).forEach((function(t){r.prototype[t]=e.prototype[t]}))}))},r.arrayContainsObject=function(r,e,t){for(var n=!1,o=0;o<e.length;o++)if(t(e[o])===t(r)){n=!0;break}return n},r.compactArray=function(r){if(r&&!(r.length<1)){var e=[];return r.map((function(r){null!=r&&e.push(r)})),e}},r.componentDestroyed=b,r.debounce=function(r,e,t,n){void 0===t&&(t=!1),void 0===n&&(n=window);var o=null;return function(){var i=this,u=arguments,a=function(){o=null,t||r.apply(i,u)},s=t&&!o;o&&clearTimeout(o),o=n.setTimeout(a,e),s&&r.apply(i,u)}},r.defineType=f,r.defineTypeEnum=function(r){for(var e in r)r.hasOwnProperty(e)&&f(r[e])},r.exponentialBackoffDelayCalculator=v,r.generateUUID=function(){var r=new Uint16Array(8);window.crypto.getRandomValues(r);var e=function(r){for(var e=r.toString(16);e.length<4;)e="0"+e;return e};return e(r[0])+e(r[1])+"-"+e(r[2])+"-"+e(r[3])+"-"+e(r[4])+"-"+e(r[5])+e(r[6])+e(r[7])},r.getFormControlValue=function(r,t){if(r&&t){var n=r.get(t);return!e.isNull(n)&&e.isAbstractControl(n)?n.value:void 0}},r.groupBy=function(r,e){return r.reduce((function(r,t){var n=t[e];return r[n]||(r[n]=[]),r[n].push(t),r}),{})},r.hasRequiredControl=function(r){if(!r)return!1;if(r instanceof t.FormGroup){for(var e=!1,n=0;n<Object.keys(r.controls).length;n+=1){if(e=p(r.controls[Object.keys(r.controls)[n]]))break}return e}return p(r)},r.httpRetryer=function(r){var e=r.retries,t=void 0===e?2:e,a=r.delayCalculator,s=void 0===a?v({}):a,c=r.scheduler,f=void 0===c?i.async:c;return u.retryWhen((function(r){return o.zip(r,o.range(1,t+1)).pipe(u.mergeMap((function(r){var e=l(r,2),i=e[0],a=e[1];if(a>t||!function(r){if(r.hasOwnProperty("status")&&r.hasOwnProperty("headers")){var e=r;return 0===e.status||429===e.status||e.status>=500&&e.status<=599}return!1}(i))return o.throwError(i);var c=s(a);429===i.status&&(c=function(r){var e=r.headers.get("Retry-After");if(e)return n.coerceNumberProperty(e,null)||n.coerceDateProperty(e,null);return null}(i)||c);return o.timer(c,f).pipe(u.take(1))})))}))},r.inputHasChanged=h,r.isUnset=function(r){return e.isNull(r)||e.isUndefined(r)},r.noop=function(){},r.objectDeepGet=function r(e,t,n){if(!e)return n;var o=t.split(".");return(e=e[o[0]])&&o.length>1?r(e,o.slice(1).join("."),n):void 0===e&&n?n:e},r.objectDeepParse=d,r.objectDeepSet=function r(e,t,n){var o,i,u=t.split(".");if(1===u.length){var s=u[0];return a(a({},e),((o={})[s]=n,o))}var c=l(u),f=c[0],p=c.slice(1),v=r(e[f],p.join("."),n);return a(a({},e),((i={})[f]=v,i))},r.resetTypeCache=function(){c={}},r.retryWithBackoff=function(r){var e=r.retries,t=void 0===e?3:e,n=r.delayCalculator,i=void 0===n?v({}):n;return u.retryWhen((function(r){return o.zip(r,o.range(1,t)).pipe(u.mergeMap((function(r){var e=l(r,2),n=e[0],u=e[1];return u>=t?o.throwError(n):o.timer(i(u))})))}))},r.returnValuesByKeys=function(r,e){var t,n,o=r.map((function(r){return r.toString()})),i=[];try{for(var u=s(o),a=u.next();!a.done;a=u.next()){var l=a.value;e[l]&&i.push(e[l])}}catch(r){t={error:r}}finally{try{a&&!a.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}return i},r.roundNumber=function(r,t){if(void 0===t&&(t=0),e.isNumber(r)){var n=function(r,e){var t=r.toString().split("e");return+(t[0]+"e"+(t[1]?+t[1]+e:e))};return n(Math.round(n(r,+t)),-t)}},r.setFormControlValue=function(r,e,t){if(r&&e){var n=r.get(e);n&&n.setValue(t)}},r.toCamelCase=function(r,e){if(void 0===e&&(e=!1),r)return 1===(r=r.trim()).length?e?r.toUpperCase():r.toLowerCase():(/^[a-z\d]+$/.test(r)||(r!==r.toLowerCase()&&(r=function(r){for(var e=!1,t=!1,n=!1,o=0;o<r.length;o++){var i=r[o];e&&/[a-zA-Z]/.test(i)&&i.toUpperCase()===i?(r=r.slice(0,o)+"-"+r.slice(o),e=!1,n=t,t=!0,o++):t&&n&&/[a-zA-Z]/.test(i)&&i.toLowerCase()===i?(r=r.slice(0,o-1)+"-"+r.slice(o-1),n=t,t=!1,e=!0):(e=i.toLowerCase()===i,n=t,t=i.toUpperCase()===i)}return r}(r)),r=r.replace(/^[_.\- ]+/,"").toLowerCase().replace(/[_.\- ]+(\w|$)/g,(function(r,e){return e.toUpperCase()}))),g(r,e))},r.untilComponentDestroyed=function(r){return function(e){return e.pipe(u.takeUntil(b(r)))}},r.updateControlOnInputChanges=function(r,e,t){if(!r||!e||!t)return!1;if(h(r,e)){var n=y.getNewValue(r,e);return t.setValue(n),!0}return!1},r.ɵ0=m,Object.defineProperty(r,"__esModule",{value:!0})}));
//# sourceMappingURL=terminus-ngx-tools-utilities.umd.min.js.map