@enter-at/iac-label
v1.1.1
Published
TypeScript library for generating consistent resource names and tags in cloud infrastructure, designed for use with Infrastructure as Code (IaC).
Maintainers
Readme
iac-label
TypeScript library for generating consistent resource names and tags in cloud infrastructure, designed for use with Infrastructure as Code (IaC).
Installation
npm install @enter-at/iac-labelUsage
import { Label } from '@enter-at/iac-label';Creating a Label
You can create a Label instance by providing the required properties via the ConstructorProps interface.
const context = {
project: 'my-project',
environment: 'dev',
service: 'my-service',
};
const label = new Label({
project: 'my-project',
environment: 'dev',
service: 'my-service',
});Alias for new Label():
const label = Label.from(context);Usage
.id
Returns a unique identifier for the label, derived from the label’s fields.
label.id;
// my-project-dev-my-service.tags
Returns a collection of tags derived from the label’s fields, including custom tags if provided.
label.tags;
// { Project: 'my-project', Environment: 'dev', Service: 'my-service' }.with
Returns a unique identifier for the label, with additional fields appended.
label.with("foo", "bar");
// my-project-dev-my-service-foo-barAdvanced Usage
Custom Delimiters
By default, the label uses a hyphen (-) as a delimiter.
You can specify a custom delimiter when creating a label.
const label = Label.from({
project: 'my-project',
environment: 'dev',
service: 'my-service',
delimiter: ':',
});
label.id;
// my-project:dev:my-serviceInheriting Context
You can inherit context from an existing label, allowing you to extend or override fields while maintaining consistency.
const label = Label.from({
project: 'my-project',
environment: 'dev',
service: 'my-service',
});
const newLabel = Label.from(label, {
environment: 'prod',
});
newLabel.id;
// my-project-prod-my-serviceContributing
Contributions are welcome! Please submit a pull request or open an issue for feature requests or bug fixes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
