UNPKG

@cxra/routine-assistance

Version:

RA (Routine Assistance).

242 lines (228 loc) 9.87 kB
import { __awaiter } from 'tslib'; import * as i0 from '@angular/core'; import { inject, ChangeDetectorRef, Pipe, Injectable } from '@angular/core'; import { Subject, pipe } from 'rxjs'; import { takeUntil, tap, switchMap, finalize } from 'rxjs/operators'; import * as i1 from '@angular/platform-browser'; /** Тип описывает абстрагированные базовые понятия, для описания относительных значений типа @see Date */ var DateConcept; (function (DateConcept) { DateConcept["age"] = "age"; DateConcept["actual"] = "actual"; DateConcept["lastyear"] = "lastyear"; DateConcept["yesterday"] = "yesterday"; DateConcept["now"] = "now"; DateConcept["tomorrow"] = "tomorrow"; DateConcept["nextyear"] = "nextyear"; })(DateConcept || (DateConcept = {})); /* eslint-disable */ Date.formats = { withoutTime: 'DD.MM.YYYY', withHHMMTime: 'DD.MM.YYYY HH:mm', withHHMMSSTime: 'DD.MM.YYYY HH:mm:ss', withoutDate: 'HH:mm:ss' }; Date.HOURS_PER_DAY = 24; Date.MINUTES_PER_HOUR = 60; Date.SECONDS_PER_MINUTE = 60; Date.isConcept = (value) => Object .values(DateConcept) .some(o => o === value); Date.getConceptValue = (value) => { switch (value) { case DateConcept.age: return (new Date()).addYears(-110); case DateConcept.lastyear: return (new Date()).addYears(-1); case DateConcept.yesterday: return (new Date()).addDays(-1); case DateConcept.now: return new Date(); case DateConcept.tomorrow: return (new Date()).addDays(1); case DateConcept.nextyear: return (new Date()).addYears(1); default: return null; } }; const isLeapYear = (year) => (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)); const getMonthLength = (date) => { return [31, (isLeapYear(date.getFullYear()) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][date.getMonth()]; }; Date.prototype.addMilliseconds = function (value) { const result = new Date(this.valueOf()); result.setMilliseconds(result.getMilliseconds() + value); return result; }; Date.prototype.addSeconds = function (value) { return this.addMilliseconds(value * 1000); }; Date.prototype.addMinutes = function (value) { return this.addMilliseconds(value * 60000); }; Date.prototype.addHours = function (value) { return this.addMilliseconds(value * 3600000); }; Date.prototype.addDays = function (value) { return this.addMilliseconds(value * 86400000); }; Date.prototype.addWeeks = function (value) { return this.addMilliseconds(value * 604800000); }; Date.prototype.addMonths = function (value) { const result = new Date(this.valueOf()); result.setDate(1); result.setMonth(this.getMonth() + value); result.setDate(Math.min(this.getDate(), getMonthLength(result))); return result; }; Date.prototype.addYears = function (value) { return this.addMonths(value * 12); }; Object.shallow = (a, b) => { const keys1 = Object.keys(a); const keys2 = Object.keys(b); if (keys1.length !== keys2.length) { return false; } for (const key of keys1) { if (a[key] !== b[key]) { return false; } } return true; }; Object.isD = (value) => !Object.isND(value); Object.isND = (value) => (value === undefined || value === null); Object.getClone = (o) => JSON.parse(JSON.stringify(o)); /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/require-await */ /** * Декоратор, который оборачивает функцию setter'а в if (value), * то есть setter будет срабатывать только если значение не undefined и не null * * @example * @Input('id') * @ShouldByDefined() * private set _accountId(value: number) { * this.id$.next(value); * } * Тоже самое: * @Input('id') * private set _accountId(value: number) { * if(value) { * this.id$.next(value); * } * } */ const ShouldByDefined = () => (_target, _propertyKey, descriptor) => { const setter = descriptor.set; descriptor.set = function (...args) { return __awaiter(this, void 0, void 0, function* () { if (args[0]) { return setter === null || setter === void 0 ? void 0 : setter.apply(this, args); } return null; }); }; return descriptor; }; /* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/require-await */ /** * Декоратор, который оборачивает функцию setter'а в обработчик, который входной аргумент поступивший * (например из шаблона) возможно в виде строки, пытается привести к @see bool * * @example * @Input('can') * @InputAsBool() * private set _can(value: boolean) { * this.can$.next(value); * } */ const InputAsBool = () => (_target, _propertyKey, descriptor) => { const setter = descriptor.set; descriptor.set = function (...args) { return __awaiter(this, void 0, void 0, function* () { const _argument = args[0]; args[0] = _argument === '' || _argument === 'true' ? true : _argument === 'false' ? false : _argument; return setter === null || setter === void 0 ? void 0 : setter.apply(this, args); }); }; return descriptor; }; /** Operator to stop subscription with the owner destroyed */ function takeUntilOwner() { const _owner = inject(ChangeDetectorRef); const _destroyed$ = new Subject(); _owner.onDestroy(() => _destroyed$.next()); return (o) => o.pipe(takeUntil(_destroyed$)); } /** Оператор переключение на подписку с фиксацией состояния исполнения */ const switchMapWithState = (_predicate, _monitor) => pipe(tap(() => _monitor.next(true)), switchMap((value, index) => _predicate(value, index).pipe(finalize(() => _monitor.next(false))))); /** Проверяет является ли значение определенным */ class IsDefinedPipe { transform(value) { return Object.isD(value); } } IsDefinedPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: IsDefinedPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); IsDefinedPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: IsDefinedPipe, name: "isD" }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: IsDefinedPipe, decorators: [{ type: Pipe, args: [{ name: 'isD' }] }] }); /** Проверяет является ли значение неопределенным или null */ class IsUndefinedPipe { transform(value) { return Object.isND(value); } } IsUndefinedPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: IsUndefinedPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); IsUndefinedPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: IsUndefinedPipe, name: "isND" }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: IsUndefinedPipe, decorators: [{ type: Pipe, args: [{ name: 'isND' }] }] }); /** Is meant to be sanitized to declarative html for use in a template */ class StringAsSanitizedHtmlPipe { constructor(sanitized) { this.sanitized = sanitized; } transform(value) { return this.sanitized.bypassSecurityTrustHtml(value); } } StringAsSanitizedHtmlPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StringAsSanitizedHtmlPipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe }); StringAsSanitizedHtmlPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.12", ngImport: i0, type: StringAsSanitizedHtmlPipe, name: "asSanitizedHtml" }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StringAsSanitizedHtmlPipe, decorators: [{ type: Pipe, args: [{ name: 'asSanitizedHtml' }] }], ctorParameters: function () { return [{ type: i1.DomSanitizer }]; } }); class CXraDestroyEventEmitter extends Subject { ngOnDestroy() { this.next(); this.complete(); } } CXraDestroyEventEmitter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CXraDestroyEventEmitter, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); CXraDestroyEventEmitter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CXraDestroyEventEmitter }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: CXraDestroyEventEmitter, decorators: [{ type: Injectable }] }); /** * Generated bundle index. Do not edit. */ export { CXraDestroyEventEmitter, DateConcept, InputAsBool, IsDefinedPipe, IsUndefinedPipe, ShouldByDefined, StringAsSanitizedHtmlPipe, switchMapWithState, takeUntilOwner }; //# sourceMappingURL=cxra-routine-assistance.mjs.map