@namefully/ng
Version:
namefully for Angular
439 lines (428 loc) • 15 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('namefully')) :
typeof define === 'function' && define.amd ? define('@namefully/ng', ['exports', '@angular/core', 'namefully'], factory) :
(global = global || self, factory((global.namefully = global.namefully || {}, global.namefully.ng = {}), global.ng.core, global.namefully));
}(this, (function (exports, core, namefully) { 'use strict';
/**
* @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.Namefully(this.raw, this.options);
this.content = executeInnerMethod(name, name[this.method || 'birthName'], this.args);
};
NamefullyComponent.decorators = [
{ type: core.Component, args: [{
selector: 'ngx-namefully',
template: '{{content}}'
}] }
];
NamefullyComponent.propDecorators = {
raw: [{ type: core.Input }],
options: [{ type: core.Input }],
method: [{ type: core.Input }],
args: [{ type: core.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.Namefully(raw, options);
return executeInnerMethod(name, name[method !== null && method !== void 0 ? method : 'birthName'], args);
};
NamefullyPipe.decorators = [
{ type: core.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.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: core.Directive, args: [{ selector: '[ngxNamefully]' },] }
];
/** @nocollapse */
NamefullyDirective.ctorParameters = function () { return [
{ type: core.ElementRef }
]; };
NamefullyDirective.propDecorators = {
raw: [{ type: core.Input, args: ['ngxNamefully',] }],
options: [{ type: core.Input, args: ['nfOptions',] }],
method: [{ type: core.Input, args: ['nfMethod',] }],
args: [{ type: core.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 core.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: namefully.Config.create(),
// default defined by Namefully
custom: config,
},
},
],
};
};
NamefullyModule.decorators = [
{ type: core.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 ? namefully.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.Namefully(raw, options || this.config);
};
NamefullyService.decorators = [
{ type: core.Injectable, args: [{ providedIn: 'root' },] }
];
/** @nocollapse */
NamefullyService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [CONFIG_TOKEN,] }] }
]; };
/** @nocollapse */ NamefullyService.ɵprov = core.ɵɵdefineInjectable({ factory: function NamefullyService_Factory() { return new NamefullyService(core.ɵɵ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;
}
exports.CONFIG_TOKEN = CONFIG_TOKEN;
exports.NamefullyComponent = NamefullyComponent;
exports.NamefullyDirective = NamefullyDirective;
exports.NamefullyModule = NamefullyModule;
exports.NamefullyPipe = NamefullyPipe;
exports.NamefullyService = NamefullyService;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=namefully-ng.umd.js.map