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

localer

v2.5.2

Published

Locales collector from js sources.

Downloads

28

Readme

NPM

Localer

Locales collector from js sources.

Global usage

localer [...glob patterns to js source] [--strings to show code frames only for strings] [--html to generate html] [--summary to show list of added and unused locales] [--compare [...glob patterns to json] to show difference] [--exclude [...glob patterns to json] to exclude locales]

Examples

For example, you have this code:

const translate = __`Translate me!`; 
const withoutTranslation = __`Without translation`; 

and JSON file with translations:

{
	"Translate me!": "Переведи меня!",
	"Unused translation": "Неиспользованный перевод"
}

If you execute next command:

localer main.js --summary --compare ru.json

you'll get:


Summary:

    Added:
        Without translation

    Unused (maybe):
        Unused translation


File: main.js

String: Without translation

  1 | const translate = __`Translate me!`; 
> 2 | const withoutTranslation = __`Without translation`;
    |                            ^

Also you can create .localerrc.js file and define default parameters. Defaults:

module.exports = {
	sources:      [],
	transformers: [],
	exclude:      [],
	compare:      [],
	summary:      false,
	html:         false,
	strings:      false
};

API

class Locales(Array<LocaleSource>|Locales fromLocalesOrLocales, Array<String> fromUnused)

Properties:

Array<String> tags = ['__', '__n']

Tagged literals.

Array<String> fns = ['__', '__n', '__mf', '__l', '__h']

Functions with one argument.

Array<String> fns2 = ['__n']

Functions with few argument.

Convert convert

ANSI to HTML instance.

Object babylonOptions

Babylon parser options.

Array<Function> transformers = []

Code transformers.

Array<LocaleSource> locales = []

Locales soruces.

Array<String> unused = []

Unused locales.

Methods:

Locales from(Locales locales)

Import data from other instance.

Locales copy()

Create copy of this.

Locales fromCode(String code, String file)

Collect locales from source code.

Promise<Locales> fromFiles(String maskOrMasks)

Collect locales from JavaScript source files by glob pattern.

Locales exclude(Array<String|LocaleSource>|Object<String,any> arrayOrObjectToExlcude)

Exclude given locales from locales and unused.

Promise<Locales> excludeFiles(String|Array<String> maskOrMasks)

Exclude locales getted from JSON files from locales and unused.

Locales diff(Array<String|LocaleSource>|Object<String,any> arrayOrObjectBase)

Get difference between locales parsed from JavaScript sources and locales.

Promise<Locales> diffFiles(String|Array<String> maskOrMasks)

Get difference between locales parsed from JavaScript sources and locales from JSON files.

String terminalReport(Boolean withSummary = false)

Generate report for terminal.

String htmlReport(Boolean withSummary = false)

Generate report as html.

class LocaleSource(String|LocaleSource fileOrLocaleSource, String code, Node node, String fn, String string)

Properties:

String file

Path to file.

String type

Type of node.

Number line

Line of token.

Number column

Column of token.

String fn

Function name.

String string

Locale string.

String codeFrame

Code frame.

Methods:

Locales from(LocaleSource localeSource)

Import data from other instance.

LocaleSource copy()

Create copy of this.