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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@need-some/i18n

v0.1.0

Published

String formatting with i18n support

Readme

need-some-i18n.js

Build Status License: MIT npm version need-some/i18n Dependencies

need-some is a collection of small yet useful functions. The i18n package provides string formatting extensions

Installation

Simply install as dependency

npm install @need-some/i18n --save

String replacemant

The string replacer is a tool that recursively applies parameters to variables in string inputs.

import { StringReplacer } from '../module/stringreplacer';
const replacer = new StringReplacer();
console.log(replacer.replace('hello')); // the most simple test outputs the input string 'hello'
console.log(replacer.replace('hello ${var}', {var: 'world'})); // a plain parameter is replaced to 'hello world'
console.log(replacer.replace('hello ${var} from ${who}', {var: 'world', who: 'need-some'})); // multiple parameters as well to 'hello world from need-some'

variable replacement

The variable replacement allows formatting and recursive calls.

Formatters need to be registered before use

import { StringReplacer } from '../module/stringreplacer';
import { marshal } from '@need-some/basic/converter/converters';
const replacer = new StringReplacer();
replacer.registerFormatter('upper', marshal(s => s.toUpperCase()));
replacer.registerFormatter('constant', marshal(s => 'hello world'));
replacer.registerFormatter('name', marshal(s => s.firstname + ' ' + s.lastname));

Default formatters can be registered for tested types

replacer.registerResolver('constant', value => value === undefined);
replacer.registerResolver('name', value => value && value.firstname);

Note that the formatters need to accept values of the variable type if they are called without parenthesis, but an object of type {value:any, params:any[]} if called with parenthesis

replacer.registerFormatter('concat', marshal(s => s.value + s.params[0]));

If both should be acceptable, the formatter needs to distinguish

replacer.registerFormatter('concat', marshal(s => s.params === undefined ? s : (s.value + s.params[0])));

This way even complex object can be simply inserted

console.log(replacer.replace('hello ${var}', {var: {firstname: 'The', lastname: 'Doctor'}}));

rule | input | parameters | output --- | --- | --- | --- lookup variable | ${param} | {param: 'booga'} | booga lookup child variable | ${param.x} | {param: {x: 'booga'}} | booga recursive lookup | ${${param}} | { param: 'booga', booga: 'loo' } | loo recursive cyclic lookup | ${${${param}}} | { param: 'booga', booga: 'param' } | booga recursive lookup of complex string | ${x${param}.${booga}} | { param: 'booga', booga: 'loo', xbooga:{loo: 'loo2' }} | loo2 pipe processing | ${param.x | upper} | {param: {x: 'booga'}} | BOOGA pipe with parameters | ${var | concat(1)} | {var: 'variant', two:'2'} | variant1 pipe with variable parameters | ${var | concat(${two})} | {var: 'variant', two:'2'} | variant2 pipe with parameter replacement | ${var | concat(${three|upper})} | {var: 'variant', three:'three'} | variantTHREE multiple pipes | ${param.x | upper | concat(${param.x})} | {param: {x: 'booga'}} | BOOGAbooga

methods

replace

Replace a string using the given parameters. The name can be used for a resolver or in a pipe call

  • input The string that should be formatted.

  • params The parameters to use in the replacement variables

  • returns a formatted string

    replace(input: string, params?: anyParam): string

registerFormatter

Register a formatter with a given name. The name can be used for a resolver or in a pipe call.

Note that the same marshaller can be registered using different names with different default params

  • name The name to register

  • formatter The formatter function

  • defaultParams params that are applied, if the name is used without own parameters or in a resolver

    registerFormatter(name: string, formatter: Marshaller<anyObject, anyObject>, defaultParams?: string[]): void

registerResolver

Register an automated formatter for defined objects. The resolvers are checked in the order they are registered.

Note that the resolvers are only used if no pipe is given at all.

  • name The registered formatter to be used as default

  • check Function to check if a given object can be formatted

    registerResolver(name: string, check: (object: anyObject) => boolean): void