novo-elements
Version:
557 lines (544 loc) • 20.4 kB
JavaScript
import * as i0 from '@angular/core';
import { Pipe, Injectable, NgModule } from '@angular/core';
import { Helpers, can } from 'novo-elements/utils';
// NG2
class DecodeURIPipe {
transform(encodedString) {
let decodedString = '';
if (!Helpers.isBlank(encodedString) && typeof encodedString === 'string') {
decodedString = decodeURIComponent(encodedString);
}
return decodedString;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DecodeURIPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: DecodeURIPipe, isStandalone: false, name: "decodeURI" }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DecodeURIPipe }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DecodeURIPipe, decorators: [{
type: Pipe,
args: [{
name: 'decodeURI',
standalone: false,
}]
}, {
type: Injectable
}] });
// NG2
class DefaultPipe {
transform(value, defaultValue) {
return value || defaultValue;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DefaultPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: DefaultPipe, isStandalone: false, name: "default" }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DefaultPipe }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DefaultPipe, decorators: [{
type: Pipe,
args: [{
name: 'default', pure: true,
standalone: false,
}]
}, {
type: Injectable
}] });
class GroupByPipe {
transform(input, prop) {
if (!Array.isArray(input)) {
return input;
}
const arr = {};
for (const value of input) {
const field = can(value).have(prop);
if (Helpers.isBlank(arr[field])) {
arr[field] = [];
}
arr[field].push(value);
}
return Object.keys(arr).map((key) => ({ key, value: arr[key] }));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: GroupByPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: GroupByPipe, isStandalone: false, name: "groupBy" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: GroupByPipe, decorators: [{
type: Pipe,
args: [{
name: 'groupBy',
standalone: false,
}]
}] });
// NG2
class HighlightPipe {
transform(value, term) {
return term ? value.replace(new RegExp(this.escapeRegexp(term.trim()), 'gi'), '<strong>$&</strong>') : value;
}
escapeRegexp(queryToEscape) {
// Ex: if the capture is "a" the result will be \a
return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: HighlightPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: HighlightPipe, isStandalone: false, name: "highlight" }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: HighlightPipe }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: HighlightPipe, decorators: [{
type: Pipe,
args: [{
name: 'highlight', pure: true,
standalone: false,
}]
}, {
type: Injectable
}] });
class IsoDateRangePipe {
constructor() { }
transform(dates) {
// TODO: Lookup Locale to convert to Users DateFormat
const [start, end] = dates.map((date) => {
if (date instanceof Date) {
return date.toISOString().slice(0, 10);
}
return date.slice(0, 10);
});
return `${start} - ${end}`;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoDateRangePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: IsoDateRangePipe, isStandalone: false, name: "isoDateRange" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoDateRangePipe, decorators: [{
type: Pipe,
args: [{
name: 'isoDateRange',
standalone: false,
}]
}], ctorParameters: () => [] });
class IsoDatePipe {
constructor() { }
transform(date) {
if (date instanceof Date) {
return date.toISOString().slice(0, 10);
}
return date.slice(0, 10);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: IsoDatePipe, isStandalone: false, name: "isoDate" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoDatePipe, decorators: [{
type: Pipe,
args: [{
name: 'isoDate',
standalone: false,
}]
}], ctorParameters: () => [] });
class IsoTimeRangePipe {
constructor() { }
transform(dates) {
// TODO: Lookup Locale to convert to 12hour
const [start, end] = dates.map((date) => {
if (date instanceof Date) {
return date.toISOString().slice(11, 16);
}
return date.slice(11, 16);
});
return `${start} - ${end}`;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoTimeRangePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: IsoTimeRangePipe, isStandalone: false, name: "isoTimeRange" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoTimeRangePipe, decorators: [{
type: Pipe,
args: [{
name: 'isoTimeRange',
standalone: false,
}]
}], ctorParameters: () => [] });
class IsoTimePipe {
constructor() { }
transform(date) {
// TODO: Lookup Locale to convert to 12hour
if (date instanceof Date) {
return date.toISOString().slice(11, 16);
}
return date.slice(11, 16);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoTimePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: IsoTimePipe, isStandalone: false, name: "isoTime" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IsoTimePipe, decorators: [{
type: Pipe,
args: [{
name: 'isoTime',
standalone: false,
}]
}], ctorParameters: () => [] });
// NG2
// Rule storage - pluralize and singularize need to be run sequentially,
// while other rules can be optimized using an object for instant lookups.
const pluralRules = [];
const singularRules = [];
const uncountables = {};
const irregularPlurals = {};
const irregularSingles = {};
/**
* Title case a string.
*/
function toTitleCase(str) {
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
}
/**
* Sanitize a pluralization rule to a usable regular expression.
*/
function sanitizeRule(rule) {
if (typeof rule === 'string') {
return new RegExp('^' + rule + '$', 'i');
}
return rule;
}
/**
* Pass in a word token to produce a function that can replicate the case on
* another word.
*/
function restoreCase(word, token) {
// Upper cased words. E.g. "HELLO".
if (word === word.toUpperCase()) {
return token.toUpperCase();
}
// Title cased words. E.g. "Title".
if (word[0] === word[0].toUpperCase()) {
return toTitleCase(token);
}
// Lower cased words. E.g. "test".
return token.toLowerCase();
}
/**
* Interpolate a regexp string.
*/
function interpolate(str, args) {
return str.replace(/\$(\d{1,2})/g, (match, index) => {
return args[index] || '';
});
}
/**
* Sanitize a word by passing in the word and sanitization rules.
*/
function sanitizeWord(token, word, collection) {
// Empty string or doesn't need fixing.
if (!token.length || uncountables.hasOwnProperty(token)) {
return word;
}
let len = collection.length;
// Iterate over the sanitization rules and use the first one to match.
while (len--) {
const rule = collection[len];
// If the rule passes, return the replacement.
if (rule[0].test(word)) {
return word.replace(rule[0], (match, index, words) => {
const result = interpolate(rule[1], [match, index, words]);
if (match === '') {
return restoreCase(words[index - 1], result);
}
return restoreCase(match, result);
});
}
}
return word;
}
/**
* Replace a word with the updated word.
*/
function replaceWord(replaceMap, keepMap, rules) {
return (word) => {
// Get the correct token and case restoration functions.
const token = word.toLowerCase();
// Check against the keep object map.
if (keepMap.hasOwnProperty(token)) {
return restoreCase(word, token);
}
// Check against the replacement map for a direct word replacement.
if (replaceMap.hasOwnProperty(token)) {
return restoreCase(word, replaceMap[token]);
}
// Run all the rules against the word.
return sanitizeWord(token, word, rules);
};
}
class Pluralize {
static pluralize(word, count = 1, inclusive) {
const pluralized = count === 1 ? Pluralize.singular(word) : Pluralize.plural(word);
return (inclusive ? `${count} ` : '') + pluralized;
}
static singular(word) {
return replaceWord(irregularSingles, irregularPlurals, pluralRules)(word);
}
static plural(word) {
return replaceWord(irregularPlurals, irregularSingles, singularRules)(word);
}
static addPluralRule(rule, replacement) {
pluralRules.push([sanitizeRule(rule), replacement]);
}
static addSingularRule(rule, replacement) {
singularRules.push([sanitizeRule(rule), replacement]);
}
static addUncountableRule(word) {
if (typeof word === 'string') {
uncountables[word.toLowerCase()] = true;
return;
}
// Set singular and plural references for the word.
Pluralize.addPluralRule(word, '$0');
Pluralize.addSingularRule(word, '$0');
}
static addIrregularRule(single, plural) {
const one = plural.toLowerCase();
const many = single.toLowerCase();
irregularSingles[one] = many;
irregularPlurals[many] = one;
}
}
/**
* Irregular rules.
*/
[
// Pronouns.
['I', 'we'],
['me', 'us'],
['he', 'they'],
['she', 'they'],
['them', 'them'],
['myself', 'ourselves'],
['yourself', 'yourselves'],
['itself', 'themselves'],
['herself', 'themselves'],
['himself', 'themselves'],
['themself', 'themselves'],
['is', 'are'],
['this', 'these'],
['that', 'those'],
// Words ending in with a consonant and `o`.
['echo', 'echoes'],
['dingo', 'dingoes'],
['volcano', 'volcanoes'],
['tornado', 'tornadoes'],
['torpedo', 'torpedoes'],
// Ends with `us`.
['genus', 'genera'],
['viscus', 'viscera'],
// Ends with `ma`.
['stigma', 'stigmata'],
['stoma', 'stomata'],
['dogma', 'dogmata'],
['lemma', 'lemmata'],
['schema', 'schemata'],
['anathema', 'anathemata'],
// Other irregular rules.
['ox', 'oxen'],
['axe', 'axes'],
['die', 'dice'],
['yes', 'yeses'],
['foot', 'feet'],
['eave', 'eaves'],
['goose', 'geese'],
['tooth', 'teeth'],
['quiz', 'quizzes'],
['human', 'humans'],
['proof', 'proofs'],
['carve', 'carves'],
['valve', 'valves'],
['thief', 'thieves'],
['genie', 'genies'],
['groove', 'grooves'],
['pickaxe', 'pickaxes'],
['whiskey', 'whiskies'],
].forEach((rule) => {
return Pluralize.addIrregularRule(rule[0], rule[1]);
});
/**
* Pluralization rules.
*/
[
[/s?$/i, 's'],
[/([^aeiou]ese)$/i, '$1'],
[/(ax|test)is$/i, '$1es'],
[/(alias|[^aou]us|tlas|gas|ris)$/i, '$1es'],
[/(e[mn]u)s?$/i, '$1s'],
[/([^l]ias|[aeiou]las|[emjzr]as|[iu]am)$/i, '$1'],
[/(alumn|syllab|octop|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
[/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
[/(seraph|cherub)(?:im)?$/i, '$1im'],
[/(her|at|gr)o$/i, '$1oes'],
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
[/sis$/i, 'ses'],
[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
[/([^aeiouy]|qu)y$/i, '$1ies'],
[/([^ch][ieo][ln])ey$/i, '$1ies'],
[/(x|ch|ss|sh|zz)$/i, '$1es'],
[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
[/(m|l)(?:ice|ouse)$/i, '$1ice'],
[/(pe)(?:rson|ople)$/i, '$1ople'],
[/(child)(?:ren)?$/i, '$1ren'],
[/eaux$/i, '$0'],
[/m[ae]n$/i, 'men'],
['thou', 'you'],
].forEach((rule) => {
return Pluralize.addPluralRule(rule[0], rule[1]);
});
/**
* Singularization rules.
*/
[
[/s$/i, ''],
[/(ss)$/i, '$1'],
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(?:sis|ses)$/i, '$1sis'],
[/(^analy)(?:sis|ses)$/i, '$1sis'],
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
[/([^aeiouy]|qu)ies$/i, '$1y'],
[/(^[pl]|zomb|^(?:neck)?t|[aeo][lt]|cut)ies$/i, '$1ie'],
[/(\b(?:mon|smil))ies$/i, '$1ey'],
[/(m|l)ice$/i, '$1ouse'],
[/(seraph|cherub)im$/i, '$1'],
[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|tlas|gas|(?:her|at|gr)o|ris)(?:es)?$/i, '$1'],
[/(e[mn]u)s?$/i, '$1'],
[/(movie|twelve)s$/i, '$1'],
[/(cris|test|diagnos)(?:is|es)$/i, '$1is'],
[/(alumn|syllab|octop|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
[/(alumn|alg|vertebr)ae$/i, '$1a'],
[/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
[/(matr|append)ices$/i, '$1ix'],
[/(pe)(rson|ople)$/i, '$1rson'],
[/(child)ren$/i, '$1'],
[/(eau)x?$/i, '$1'],
[/men$/i, 'man'],
].forEach((rule) => {
return Pluralize.addSingularRule(rule[0], rule[1]);
});
/**
* Uncountable rules.
*/
[
// Singular words with no plurals.
'advice',
'adulthood',
'agenda',
'aid',
'alcohol',
'ammo',
'athletics',
'bison',
'blood',
'bream',
'buffalo',
'butter',
'carp',
'cash',
'chassis',
'chess',
'clothing',
'commerce',
'cod',
'cooperation',
'corps',
'digestion',
'debris',
'diabetes',
'energy',
'equipment',
'elk',
'excretion',
'expertise',
'flounder',
'fun',
'gallows',
'garbage',
'graffiti',
'headquarters',
'health',
'herpes',
'highjinks',
'homework',
'housework',
'information',
'jeans',
'justice',
'kudos',
'labour',
'literature',
'machinery',
'mackerel',
'media',
'mews',
'moose',
'music',
'news',
'pike',
'plankton',
'pliers',
'pollution',
'premises',
'rain',
'research',
'rice',
'salmon',
'scissors',
'series',
'sewage',
'shambles',
'shrimp',
'species',
'staff',
'swine',
'trout',
'traffic',
'transporation',
'tuna',
'wealth',
'welfare',
'whiting',
'wildebeest',
'wildlife',
'you',
// Regexes.
/pox$/i, // "chickpox", "smallpox"
/ois$/i,
/deer$/i, // "deer", "reindeer"
/fish$/i, // "fish", "blowfish", "angelfish"
/sheep$/i,
/measles$/i,
/[^aeiou]ese$/i, // "chinese", "japanese"
].forEach(Pluralize.addUncountableRule);
class PluralPipe {
transform(value) {
return Pluralize.pluralize(value);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: PluralPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: PluralPipe, isStandalone: false, name: "plural" }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: PluralPipe }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: PluralPipe, decorators: [{
type: Pipe,
args: [{
name: 'plural',
standalone: false,
}]
}, {
type: Injectable
}] });
// NG2
class NovoPipesModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NovoPipesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: NovoPipesModule, declarations: [PluralPipe, DecodeURIPipe, GroupByPipe, HighlightPipe, DefaultPipe, IsoTimePipe, IsoDatePipe, IsoTimeRangePipe, IsoDateRangePipe], exports: [PluralPipe, DecodeURIPipe, GroupByPipe, HighlightPipe, DefaultPipe, IsoTimePipe, IsoDatePipe, IsoTimeRangePipe, IsoDateRangePipe] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NovoPipesModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: NovoPipesModule, decorators: [{
type: NgModule,
args: [{
declarations: [PluralPipe, DecodeURIPipe, GroupByPipe, HighlightPipe, DefaultPipe, IsoTimePipe, IsoDatePipe, IsoTimeRangePipe, IsoDateRangePipe],
exports: [PluralPipe, DecodeURIPipe, GroupByPipe, HighlightPipe, DefaultPipe, IsoTimePipe, IsoDatePipe, IsoTimeRangePipe, IsoDateRangePipe],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { DecodeURIPipe, DefaultPipe, GroupByPipe, HighlightPipe, IsoDatePipe, IsoDateRangePipe, IsoTimePipe, IsoTimeRangePipe, NovoPipesModule, PluralPipe };
//# sourceMappingURL=novo-elements-pipes.mjs.map