UNPKG

@namefully/ng

Version:
439 lines (428 loc) 13.1 kB
import { Component, Input, Pipe, Directive, ElementRef, InjectionToken, NgModule, Injectable, Inject, ɵɵdefineInjectable, ɵɵinject } from '@angular/core'; import { Namefully, Config } from 'namefully'; /** * @fileoverview added by tsickle * Generated from: namefully-utils.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // tslint:disable-next-line /** * @param {?} context * @param {?} fn * @param {?} vargs * @return {?} */ function executeInnerMethod(context, fn, vargs) { /** @type {?} */ var content = fn.apply(context, vargs); return Array.isArray(content) ? content.join(' ') : content; } /** * @fileoverview added by tsickle * Generated from: namefully.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Represents an Angular-based component that wraps up the basic functionality * of namefully. Remember, if not satisfied, one can always use some of the core * elements exported from `namefully` to fully enjoy the benefits offered by it. * * \@usageNotes * ```html * <ngx-namefully * [raw]="..." * [options]="..." * [method]="..." * [args]="..." * > * </ngx-namefully> * ``` * * \@example * - import the module first to your app * - then use it with the following props bindings * // in the AppModule for example: * ```ts * import { NamefullyModule } from '\@namefully/ng' * * \@NgModule({ * imports: [BrowserModule, NamefullyModule.forRoot(...)], * declarations: [AppComponent], * bootstrap: [AppComponent] * }) * export class AppModule {} * ``` * * // in the html template: * ```html * <ngx-namefully * [raw]="name" * [options]="options" * [method]="method" * [args]="args" * > * </ngx-namefully> * ``` * * // in the AppComponent.ts * ```ts * class AppComponent { * name = 'Mr Smith John Joe PhD' * options = { orderedBy: 'lastName' } * method = 'shorten' * args = [] * } * ``` */ var NamefullyComponent = /** @class */ (function () { function NamefullyComponent() { } /** * @return {?} */ NamefullyComponent.prototype.ngOnInit = /** * @return {?} */ function () { /** @type {?} */ var name = new Namefully(this.raw, this.options); this.content = executeInnerMethod(name, name[this.method || 'birthName'], this.args); }; NamefullyComponent.decorators = [ { type: Component, args: [{ selector: 'ngx-namefully', template: '{{content}}' }] } ]; NamefullyComponent.propDecorators = { raw: [{ type: Input }], options: [{ type: Input }], method: [{ type: Input }], args: [{ type: Input }] }; return NamefullyComponent; }()); if (false) { /** @type {?} */ NamefullyComponent.prototype.raw; /** @type {?} */ NamefullyComponent.prototype.options; /** @type {?} */ NamefullyComponent.prototype.method; /** @type {?} */ NamefullyComponent.prototype.args; /** @type {?} */ NamefullyComponent.prototype.content; } /** * @fileoverview added by tsickle * Generated from: namefully.pipe.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Use Angular pipe to transform (handle) person names * * @see {\@link https://angular.io/guide/pipes|Pipes} by Angular for further info * on how to use pipes. * * \@usageNotes * raw | namefully : options : method : args * * \@example * Let's say we want to compress the name `John Joe Smith` to `John J. Smith`: * {{ 'John Joe Smith' | namefully : null : 'zip' : ['middleName'] }} */ var NamefullyPipe = /** @class */ (function () { function NamefullyPipe() { } /** * Formats the name as specified */ /** * Formats the name as specified * @param {?} raw * @param {?=} options * @param {?=} method * @param {?=} args * @return {?} */ NamefullyPipe.prototype.transform = /** * Formats the name as specified * @param {?} raw * @param {?=} options * @param {?=} method * @param {?=} args * @return {?} */ function (raw, options, method, args) { /** @type {?} */ var name = new Namefully(raw, options); return executeInnerMethod(name, name[method !== null && method !== void 0 ? method : 'birthName'], args); }; NamefullyPipe.decorators = [ { type: Pipe, args: [{ name: 'namefully' },] } ]; return NamefullyPipe; }()); /** * @fileoverview added by tsickle * Generated from: namefully.directive.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Represents an Angular-based attribute directive that wraps up namefully's * core functionalities. Remember, if not satisfied, you can always use some of * of the core elements exported from `namefully` instead. * * \@usageNotes * ```html * <p [ngxNamefully]="..." * [nfOptions]="..." * [nfMethod]="..." * [nfArgs]="..." * > * </p> * ``` * * \@example * - import the module first to your app * - then use it with the following props bindings * // in the AppModule for example: * ```ts * import { NamefullyModule } from '\@namefully/ng' * * \@NgModule({ * imports: [BrowserModule, NamefullyModule.forRoot(...)], * declarations: [AppComponent], * bootstrap: [AppComponent] * }) * export class AppModule {} * ``` * * // in the html template: * ```html * <span [ngxNamefully]="name" * [nfOptions]="options" * [nfMethod]="method" * [nfArgs]="args" * > * </span> * ``` * * // in the AppComponent.ts * ```ts * class AppComponent { * name = 'Mr Smith John Joe PhD' * options = { orderedBy: 'lastname' } * method = 'shorten' * args = [] * } * ``` * @see https://angular.io/guide/attribute-directives */ var NamefullyDirective = /** @class */ (function () { function NamefullyDirective(elRef) { this.elRef = elRef; } /** * @return {?} */ NamefullyDirective.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _a; /** @type {?} */ var name = new Namefully(this.raw, this.options); this.elRef.nativeElement.innerHTML = executeInnerMethod(name, name[(_a = this.method) !== null && _a !== void 0 ? _a : 'birthName'], this.args); }; NamefullyDirective.decorators = [ { type: Directive, args: [{ selector: '[ngxNamefully]' },] } ]; /** @nocollapse */ NamefullyDirective.ctorParameters = function () { return [ { type: ElementRef } ]; }; NamefullyDirective.propDecorators = { raw: [{ type: Input, args: ['ngxNamefully',] }], options: [{ type: Input, args: ['nfOptions',] }], method: [{ type: Input, args: ['nfMethod',] }], args: [{ type: Input, args: ['nfArgs',] }] }; return NamefullyDirective; }()); if (false) { /** @type {?} */ NamefullyDirective.prototype.raw; /** @type {?} */ NamefullyDirective.prototype.options; /** @type {?} */ NamefullyDirective.prototype.method; /** @type {?} */ NamefullyDirective.prototype.args; /** * @type {?} * @private */ NamefullyDirective.prototype.elRef; } /** * @fileoverview added by tsickle * Generated from: namefully-config.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function ConfigToken() { } if (false) { /** @type {?} */ ConfigToken.prototype.default; /** @type {?} */ ConfigToken.prototype.custom; } /** @type {?} */ var CONFIG_TOKEN = new InjectionToken('ConfigToken'); /** * @fileoverview added by tsickle * Generated from: namefully.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Exposes a widget feature module comprising 4 Angular-based elements: * - a component: <ngx-namefully></ngx-namefully> * - a pipe: {{ ... | namefully }} * - a service: NamefullyService * - an attribute directive: [ngxNamefully] * * See the code documentation to see how to use each one of them. */ var NamefullyModule = /** @class */ (function () { function NamefullyModule() { } /** * @param {?=} config * @return {?} */ NamefullyModule.forRoot = /** * @param {?=} config * @return {?} */ function (config) { return { ngModule: NamefullyModule, providers: [ { provide: CONFIG_TOKEN, useValue: { default: Config.create(), // default defined by Namefully custom: config, }, }, ], }; }; NamefullyModule.decorators = [ { type: NgModule, args: [{ declarations: [NamefullyComponent, NamefullyPipe, NamefullyDirective], exports: [NamefullyComponent, NamefullyPipe, NamefullyDirective], },] } ]; return NamefullyModule; }()); /** * @fileoverview added by tsickle * Generated from: namefully.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Inject this service into your Angular component to handle person names * * \@usageNotes * - import the module first to your app * - then use it with the following props bindings * // in the AppModule for example: * ```ts * import { NamefullyModule } from '\@namefully/ng' * * \@NgModule({ * imports: [BrowserModule, NamefullyModule.forRoot(...)], * declarations: [AppComponent], * bootstrap: [AppComponent] * }) * export class AppModule {} * ``` * * // in the AppComponent.ts * ```ts * \@Component({ template: `<p>{{ superName.shorten() }}</p>` }) * class AppComponent implements OnInit { * name = 'Mr Smith John Joe PhD'; * superName: Namefully; * * constructor(private service: NamefullyService) {} * * ngOnInit(): void { * this.superName = this.service.build( * this.name, * // override forRoot config here * ); * } * } * ``` */ var NamefullyService = /** @class */ (function () { function NamefullyService(config) { this.config = !!config.custom ? Config.merge(config.custom) : config.default; } /** * Constructs `Namefully` * @param raw data to construct the name parts of a full name * @param options fallback config to override preset forRoot(config) */ /** * Constructs `Namefully` * @param {?} raw data to construct the name parts of a full name * @param {?=} options fallback config to override preset forRoot(config) * @return {?} */ NamefullyService.prototype.build = /** * Constructs `Namefully` * @param {?} raw data to construct the name parts of a full name * @param {?=} options fallback config to override preset forRoot(config) * @return {?} */ function (raw, options) { return new Namefully(raw, options || this.config); }; NamefullyService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ NamefullyService.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: Inject, args: [CONFIG_TOKEN,] }] } ]; }; /** @nocollapse */ NamefullyService.ɵprov = ɵɵdefineInjectable({ factory: function NamefullyService_Factory() { return new NamefullyService(ɵɵinject(CONFIG_TOKEN)); }, token: NamefullyService, providedIn: "root" }); return NamefullyService; }()); if (false) { /** * Holds a json-like copy of the preset configuration injected by Angular * @type {?} * @private */ NamefullyService.prototype.config; } /** * @fileoverview added by tsickle * Generated from: public-api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: namefully-ng.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { CONFIG_TOKEN, NamefullyComponent, NamefullyDirective, NamefullyModule, NamefullyPipe, NamefullyService }; //# sourceMappingURL=namefully-ng.js.map