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

smash-template-engine-filters

v1.7.1

Published

Basic filters for SmashTemplateEngine

Downloads

28

Readme

SmashTemplateEngineFilters Build Status codecov

Some Filters designed to be used in SmashTemplateEngine.

It includes :   - Translate   - Date   - Size   - Plural   - UcFirst

Getting Started

Installing

All you need is to install the npm package.

npm install smash-template-engine-filters

You can now require the package and create an instance of it :

const Filters = require('smash-template-engine-filters');
const filters = new Filters();

Usage

Each filters has 2 required methods :   - getName()   - execute()

Translate Filter

From a keyword it will return a translation in the wished language.

const translations = {
    'HELLO_KEYWORD': {
        en: "Hello World !",
        de: "Hallo !",
        fr: "Bonjour !"
    }
};

const translator = new filters.Translate(translations);
translator.execute("HELLO_KEYWORD"); // Hello World !

translator.setLanguage("fr"); // set the language
translator.setFallbackLanguage("en"); // Fallback language is en by default
translator.execute("HELLO_KEYWORD"); // Bonjour !

You can also add variable into translations, it is made so :

const translations = {
    'HELLO_NAME_KEYWORD': {
        en: "Hello %name% !",
        de: "Hallo %name% !",
        fr: "Bonjour %name% !"
    }
};

const translator = new filters.Translate(translations);

translator.execute("HELLO_NAME_KEYWORD", { name: "James" }); // Hello James !

Date Filter

It will convert a UNIX timestamp into a string formatted as you wish and translated into the language you want.

A date format can be specified has second parameter. If not defined, the format will be defined thanks to the language set in the translator. It means that the Translate filter has to be instanced.

const translator = new filters.Translate(translations);

const date = new filters.date(translator);
const timestamp = 1517407220;
date.execute(timestamp) // January 31, 2018

But you can set the format you want as parameter :

const timestamp = 1517407220;
date.execute(timestamp, {format : "MM-DD-YYYY"}) // 31-01-2018

This filter is based on MomentJS, check it out for specific format.

Size Filter

It convert a Bytes number into a appropriated unit :

const size = new filters.size(translator);

size.execute(1)                      // "1 B"
size.execute(10)                     // "10 B"
size.execute(100)                    // "100 B"
size.execute(1000)                   // "1 KB"
size.execute(10000)                  // "10 KB"
size.execute(100000)                 // "100 KB"
size.execute(1000000)                // "1 MB"
size.execute(10000000)               // "10 MB"
size.execute(100000000)              // "100 MB"
size.execute(1000000000)             // "1 GB"
size.execute(10000000000)            // "10 GB"
size.execute(100000000000)           // "100 GB"
size.execute(1000000000000)          // "1 TB"
size.execute(10000000000000)         // "10 TB"
size.execute(100000000000000)        // "100 TB"
size.execute(1000000000000000)       // "1 PB"
size.execute(10000000000000000)      // "10 PB"
size.execute(100000000000000000)     // "100 PB"

ucFirst Filter

It transforms the first character of a string to uppercase.

If an object with property "word" is set as second parameter, it will return this string with its first character turned into uppercase.

const ucFirst = new filters.ucFirst();

ucFirst.execute("lowercase"); // "Lowercase"
ucFirst.execute("lowercase", {word:"parameter"}); // Parameter

plural Filter

It can turn almost (not ) every english words to its plural.

const plural = new filters.plural();
plural.execute("arch"); // "arches"
plural.execute("buzz"); // "buzzes"
plural.execute("alley"); // "alleys"
plural.execute("ally"); // "allies"
plural.execute("calf"); // "calves"
plural.execute("knife"); // "knives"
plural.execute("buffalo"); // "buffaloes"
plural.execute("bluff"); // "bluffs"
plural.execute("index"); // "indexes"