New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

serialized-tags

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serialized-tags

Read plain objects and turn plain strings into fast i18n-ready template strings

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

serialized-tags

NPM version NPM downloads Build status Build Status Total alerts Dependabot Status Patreon

npm installnfo

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:

{
    "hello": "Hello {0}!",
	"actions.hug": "{0} just hugged {1}!",
	"actions.pat": "{1} just got patted by {0}!",
	"actions.other": [
		"Hello {0}! Came back for more pats?",
		"Bye {0}! I will see you later!"
	]
}

You would parse this using the following code:

// Import the package
const serializedTags = require('serialized-tags');

// Assume jsonString is a string containing the previous JSON
// We will parse it into an object so serializedTags can work with it
const json = JSON.parse(jsonString);

// Parse with serializedTags
const parsed = new serializedTags.parse(json);

And now, we save it somewhere! Let's use parsed now!

const salute = parsed.get('hello').display(['world']);
// -> Hello world!

const hug = parsed.get('actions.hug').display(['kyra', 'OSS']);
// -> kyra just hugged OSS!

const pat = parsed.get('actions.pat').display(['the reader', 'kyra']);
// -> kyra just got patted by the reader!

const otherSalute = parsed.get('actions.other').first().display(['kyra']);
// Identical to: parsed.get('actions.other').get(0).display(['kyra']);
// -> Hello kyra! Came back for more pats?

const otherBye = parsed.get('actions.other').last().display(['kyra']);
// Identical to: parsed.get('actions.other').get(1).display(['kyra']);
// -> Bye kyra! I will see you later!

// Or even, randoms!
const otherRandom = parsed.get('actions.other').random().display(['kyra']);
// -> Hello kyra! Came back for more pats?
// -> Bye kyra! I will see you later!

Keywords

serialized-tags

FAQs

Package last updated on 29 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts