UNPKG

@toreda/strong-types

Version:

Better TypeScript code in fewer lines.

75 lines (73 loc) 2.83 kB
/** * MIT License * * Copyright (c) 2019 - 2021 Toreda, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ import { Transform } from './transform'; import { TransformNB } from './transform/nb'; /** * Container holding the transform function chain used to transform * values before saving. Transforms are applied in the order they are * stored in the transforms or transformsNB array. * * @category Transforms */ export declare class Transforms<T> { readonly transforms: Transform<T>[]; readonly transformsNB: TransformNB<T>[]; readonly fallbackDefault: T; constructor(fallbackDefault: T); /** * Add nullable transform function to chain. * @param transform Nullable transform fn to be added to chain. * @returns Boolean indicating add success or failure. * true - Transform fn added to chain successfully. * false - Transform fn not added to chain. */ addNB(transform: TransformNB<T>): boolean; /** * Add transform function to chain. * @param transform Transform fn to be added to chain. * @returns Boolean indicating add success or failure. * true - Transform fn added to chain successfully. * false - Transform fn not added to chain. */ add(transform: Transform<T>): boolean; /** * Run transform chain, applying each transforms once the order added to * the chain. * @param value * @returns */ run(value: T): T; /** * Run transform chain, applying each transforms once the order added to * the chain. * @param value * @returns */ runNB(value: T | null): T | null; /** * Remove all transform functions from chain. Fallback value * remains the same. */ reset(): void; }