npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hyron/stringer

v1.3.8

Published

Help separate the string from code for ease of management and maintenance

Downloads

34

Readme

Build status Gitter npm

Stringer is lightweight library to separate string value from code

Feature

  • Support for multi-language
  • Human read-able syntax
  • Support Internal Reference
  • Support Passing Varable
  • Support for Comment
  • Support for Hyron Framework

Syntax

This syntax is applied in the .str file, which helps you define strings in the form of key-value.

.str file support multi-line, single comment line reference internal and load external variables except by the syntax below

# single comment line. it will be skip by compiler

---key_name---
string content bellow to next key or end of file

---var_1---
single line content

---var_2---
multi
line
content

---internal_reference---
<#var_1>

---var_loadable---
<?var_name>

Usage

Step 1: Installation

By NPM:

npm i @hyron/stringer

By YARN:

yarn add @hyron/stringer

Step 2: Declare string values

By default, stringer will loads strings from files with .str extension in ./strings directory.

You should use language code to named file. (e.g: vi.str for vietnamese)

The stringer will load the file default.str by default, unless you set the default language

Here is an example of strings directory:

/strings
  ├── default.str
  ├── en.str
  ├── vi.str
  ...

strings/default.str

---say_my_name---
Hi, <?myName>

Step 3: Use stringer

Stringer can be used by any app like other libraries:

const Stringer = require("@hyron/stringer");
var stringer = new Stringer();

var printMe = stringer.get("say_my_name", {
    myName : "thangphung"
});

console.log(printMe);
// Hi, thangphung

For Hyron framework

You can use stringer as a plugins in the hyron framework. You just need to install it to use.

Stringer can be access by this.$stringer

sayMyName(){
    return this.$stringer.get('say_my_name');
}

API References

setLanguage ( lang ): void

Set default language. If lang is null, string will be read from default.json file. Otherwise, it will be read from < lang >.str

params

  • lang ( string ) : language code, that was used to named file in strings/ directory

set ( key, val, lang? ) : void

Temporarily set string in runtime. The original file is left intact.

params

  • key ( string ) : string key, declared in .str file.
  • val ( string ) : parameters passed in string value.
  • lang ( string ) : language code, declared in string files.

get (key, args?): string

Fill source string by target string.

Stringer support internal reference represent with syntax: <#abort-key-name>.

  • To UPPERCASE string, postfix it by a '+' character: <#abort-key-name+>.
  • To lowercase string, postfix it by a '-' character: <#abort-key-name->.

Stringer support external reference represent with syntax : <?var-name>. Stringer will replaced this by args.var_name with this method.

params

  • key ( string ) : string args key name.
  • args ( object ) : argument to fill into string.

return

  • string : a string that have been filled by args

Examples

strings/default.str

---website---
http:\/\/hyron.com

// used to send to user
---email_content---
Dear <?client_name>

Thank you because the registered service of our own at website <#website>
We will constantly improve the quality of our services, to bring satisfaction to you. Hope you like it

<?signature>

In main.js you could use:

var message = stringer.get("email_content", {
    signature: "THANGPHUNG",
    client_name: "Alex"
});

The output

Dear Alex

Thank you because the registered service of our own at website http://hyron.com
We will constantly improve the quality of our services, to bring satisfaction to you. Hope you like it

THANGPHUNG