UNPKG

@namefully/ng

Version:
52 lines (51 loc) 1.54 kB
import { Namefully, Config, Name, JsonName, Parser } from 'namefully'; import { ConfigToken } from './namefully-config'; /** * 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 * ); * } * } * ``` */ export declare class NamefullyService { /** * Holds a json-like copy of the preset configuration injected by Angular */ private readonly config; constructor(config: ConfigToken); /** * Constructs `Namefully` * @param raw data to construct the name parts of a full name * @param options fallback config to override preset forRoot(config) */ build(raw: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>): Namefully; }