The @bleco/aliaser
package provides a flexible and powerful utility for managing binding aliases within a LoopBack
application. This package enables you to define and apply aliases to bindings, allowing for more modular and
maintainable code. It is particularly useful when you want to redirect or transform values from one binding to another.
- Simple API: Easy to use functions for defining and applying aliases.
- Validation and Transformation: Built-in support for validation and transformation of aliased values.
- Promise Support: Asynchronous operations are fully supported, allowing for promise-based validation and transformation.
- High Test Coverage: The package is fully tested to ensure reliability and stability.
Install the package using npm or yarn:
npm install @bleco/aliaser
# OR
yarn add @bleco/aliaser
Below is a basic example of how to use @bleco/aliaser
:
import { Aliaser, Context, BindingKey } from '@bleco/aliaser';
// Create a new LoopBack context
const context = new Context();
// Define some bindings
context.bind('config').to({ prop: 'value' });
// Create an aliaser instance
const aliaser = Aliaser.create({ prop: 'config#prop' });
// Apply the aliases to the context
aliaser.bind(context);
// Retrieve the aliased value
const value = context.getSync('prop'); // Output: 'value'
In this example, we have a LoopBack context with a binding named config
that holds an object with a property prop
.
We create an Aliaser
instance and define an alias from prop
to config#prop
. Finally, we apply the aliases to the
context and retrieve the aliased value.
The main class for defining and applying aliases.
Creates a new Aliaser
instance.
Creates a new Aliaser
instance with the given aliasing definition.
Adds an aliasing definition.
Applies the defined aliases to the given LoopBack context.
An object representing the aliasing definition.
An optional configuration object for binding options.
Contributions are welcome! Please submit an issue or pull request with any improvements or bug fixes.
This package is licensed under the MIT License - see the LICENSE file for details.