serialized-tags
About
serialized-tags
is a fast and lightweight tag template parser for primitive objects and values, it comes with support for
Arrays, Objects, Strings, and Value, all four being wrapped in classes implementing the same interface, reducing the
need to check values in your code.
The nature of this parser is to allow developers to use language files in the format of their convenience (JSON, YAML...) and pass the output through this to parse the strings and prepare everything for later usage.
In a near future, this package will have a branch for webpack to allow developers use this on their web applications!
Usage
As mentioned before, you can use (parsed) JSON objects for this package, given this file:
You would parse this using the following code:
// Import the packageconst serializedTags = ; // Assume jsonString is a string containing the previous JSON// We will parse it into an object so serializedTags can work with itconst json = JSON; // Parse with serializedTagsconst parsed = json;
And now, we save it somewhere! Let's use parsed
now!
const salute = parseddisplay'world';// -> Hello world! const hug = parseddisplay'kyra' 'OSS';// -> kyra just hugged OSS! const pat = parseddisplay'the reader' 'kyra';// -> kyra just got patted by the reader! const otherSalute = parseddisplay'kyra';// Identical to: parsed.get('actions.other').get(0).display(['kyra']);// -> Hello kyra! Came back for more pats? const otherBye = parseddisplay'kyra';// Identical to: parsed.get('actions.other').get(1).display(['kyra']);// -> Bye kyra! I will see you later! // Or even, randoms!const otherRandom = parseddisplay'kyra';// -> Hello kyra! Came back for more pats?// -> Bye kyra! I will see you later!