Formatter
No summary available
import { Formatter } from "@schukai/monster/source/text/formatter.mjs";Introduction
The Formatter replaces markers inside strings with values from a data object. It supports nested markers, parameter blocks, and the full pipe syntax for transformations.
Basic Usage
import { Formatter } from "@schukai/monster/source/text/formatter.mjs";
const formatter = new Formatter({
title: "Hello",
name: "World"
});
formatter.format("${title} ${name}!");
Pipes and Callbacks
You can use pipe commands to transform values. Custom callbacks can be injected through the callbacks option.
const formatter = new Formatter({ value: "1" }, {
callbacks: {
quote: (v) => `"${v}"`
}
});
formatter.format("${value | call:quote}");
Marker Parameters
A marker can carry its own parameter list using :: and = separators. Parameters are forwarded to pipe commands.
formatter.format("${price::currency=EUR | money}");
/** this example does not use an extra script **/
Monster
Build fantastic websites!
Efficient Web Design with Custom Components
Monster is the foundation of our front-end projects and greatly simplifies the creation of websites and applications. Our library includes a wide range of pre-built, elegant and customizable components. From precise buttons that provide feedback on user actions to complex data lists with sorting and filtering capabilities, Monster gives you the tools you need to design quickly and consistently.
As an open-source project, Monster is constantly being expanded and refined by a dedicated team. Our goal is to constantly improve the functionality and at the same time make it intuitive to use to make your everyday work easier.
<monster-button id="my-button">
Click Me!
</monster-button>
const myButton = document.getElementById('my-button');
myButton.setOption("actions.click", () => {
myButton.setState("successful", 2000);
})
Below, you'll find the "Click Me!" button. When clicked, a checkmark briefly appears to confirm the operation was successful.
The accompanying source code, shown on the right, uses HTML to define the button and JavaScript to set its state to "successful" for 2000 milliseconds following the click.
This demonstrates a straightforward way to provide immediate feedback on user interfaces.
Web Components for Tomorrow's Needs
Customizable Components
Monster offers a diverse suite of web components that blend seamlessly into any design. Customize colors, shapes, and functionalities to fit your specific needs.
Optimized for consistent performance across all screen sizes, our components ensure a smooth user experience on every device.
Efficient Integration & Maintenance
With Monster's modular structure, you can swiftly add or remove components without overhauling your entire codebase.
This feature streamlines project maintenance and expedites the deployment of new features, enhancing overall productivity.
Future-Proof Technology
Committed to innovation, we continuously update Monster to align with the latest web standards and browser technologies.
This proactive approach ensures that your projects remain compatible and secure against future technological shifts.
The current width of the area is too small to display the content correctly.
Exported
FormatterDerived from
BaseWithOptionsOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the BaseWithOptions.
Properties
The Properties listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Properties from these parent classes. If you cannot find a specific Properties in this list, we recommend consulting the documentation of the BaseWithOptions.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the BaseWithOptions.
Constructor
constructor(object,options)object: objectoptions: options
${ and }Structural methods
setMarker(open,close)1.12.0open{array|string}: openclose{array|string|undefined}: close
- {Formatter}
{TypeError}value is not a string
${ and } ``formatter.setMarker('#'); // open and close are both # formatter.setMarker('[',']'); formatter.setMarker('i18n{','}');``setParameterChars(delimiter,assignment)1.24.0delimiter{string}: delimiterassignment{string}: assignment
- {Formatter}
{TypeError}value is not a string
:: and = ``formatter.setParameterChars('#'); formatter.setParameterChars('[',']'); formatter.setParameterChars('i18n{','}');``Other methods
format(text)text{string}: text
- {string}
{TypeError}value is not a string{Error}too deep nesting
Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.