1.4.5 • Published 4 months ago

@bleco/aliaser v1.4.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

@bleco/aliaser

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.

Features

  • 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.

Installation

Install the package using npm or yarn:

npm install @bleco/aliaser
# OR
yarn add @bleco/aliaser

Usage

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.

API

Aliaser

The main class for defining and applying aliases.

constructor()

Creates a new Aliaser instance.

static create(definition: AliasingDefinition): Aliaser

Creates a new Aliaser instance with the given aliasing definition.

add(definition: AliasingDefinition): Aliaser

Adds an aliasing definition.

bind(context: Context, options?: AliasingBindOptions): this

Applies the defined aliases to the given LoopBack context.

AliasingDefinition

An object representing the aliasing definition.

AliasingBindOptions

An optional configuration object for binding options.

Contributing

Contributions are welcome! Please submit an issue or pull request with any improvements or bug fixes.

License

This package is licensed under the MIT License - see the LICENSE file for details.

1.4.5

4 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.2.0

7 months ago

0.5.10

10 months ago

0.5.11

10 months ago

0.6.6

7 months ago

0.5.16

9 months ago

1.4.2

6 months ago

0.5.14

9 months ago

1.4.1

6 months ago

0.5.15

9 months ago

1.4.0

6 months ago

0.5.12

10 months ago

0.5.13

9 months ago

1.1.0

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

0.6.3

8 months ago

0.6.2

8 months ago

0.6.5

7 months ago

0.6.4

8 months ago

0.6.1

8 months ago

0.6.0

9 months ago

0.5.8

11 months ago

0.5.7

11 months ago

0.5.9

11 months ago

0.4.15

1 year ago

0.5.4

12 months ago

0.5.3

12 months ago

0.5.6

11 months ago

0.5.5

12 months ago

0.5.0

1 year ago

0.5.2

12 months ago

0.5.1

12 months ago

0.4.13

1 year ago

0.4.14

1 year ago

0.4.12

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.10

1 year ago

0.4.11

1 year ago

0.4.5

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.1

2 years ago

0.4.2

1 year ago

0.3.22

2 years ago

0.4.0

2 years ago

0.3.20

2 years ago

0.3.9

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.21

2 years ago

0.3.10

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago