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

meetup-trn-extractor

v0.2.2

Published

A utility to extract copy from JavaScript files for translation

Downloads

11

Readme

Meetup TRN Extractor

Build Status Coverage Status

A utility to extract copy from JavaScript files for translation

Installation

npm i --save meetup-trn-extractor

Example usage

This will look for trn (case insensitive) function calls within the searched files in the format:

  trn(key: string, body: string, params?: Object)

CLI

./node_modules/.bin/meetup-trn-extractor [options]

Options:
  --files, -f               glob pattern for input files (wrap in '', or escape
                            * with \*)                       [string] [required]
  --outfile, -o             Send the output to a file                   [string]
  --exclude-empty-trns, -x  Exclude files that do not contain TRNs
                                                      [boolean] [default: false]
  --babylon-plugins, -p     Any number of Babylon plugins
                                                        [array] [default: ["*"]]
  --help                    Show help                                  [boolean]

Examples:
  ./node_modules/.bin/meetup-trn-extractor
  --files='src/**/*!(.test).js'
  --outfile=output.json
  --exclude-empty-trns
  --babylon-plugins jsx flow
  ./node_modules/.bin/meetup-trn-extractor -f src/\*\*/\*!(.test).js -o output.json -p flow jsx

Node

import Extractor from 'meetup-trn-extractor'

const extractor = new Extractor({
  // https://github.com/babel/babylon#options
  babylonConfig: { sourceType: 'module', plugins: ['*'] },
  trnFnName: 'trn'
})

// Extractor.extract(globPattern: string) => Promise<Object[]>
extractor.extract('src/**/*.js').then((trns: Object[]) => console.log(trns))

Example output

[
  {
    "file": "/usr/local/git_repo/meetup-trunk/static/script/mu/shared/validator.js",
    "trns": []
  },
  {
    "file": "/usr/local/git_repo/meetup-trunk/static/script/mu/shared/validatorRules.js",
    "trns": [
      {
        "key": "validation.isChecked",
        "body": "This checkbox is required.",
        "params": []
      },
      {
        "key": "validation.error.minLength",
        "body": "Should be at least {MIN} characters",
        "params": [
          "MIN"
        ]
      }
    ]
  }
]

Caveats

This currently does not extract trns from trn calls in the following formats

  // don't concat strings
  trn('some.key', 'some ' + 'copy') // won't work
  trn(['some', 'key'].join('.'), 'some copy') // won't work

  trn('some.key', 'some copy') // will work

Contributing

Versioning

npm version major|minor|patch to create a git commit + tag incrementing the major, minor or patch version in package.json. git push && git push --tags to push the version commit + tag to GitHub.

Publishing

npm publish to publish the latest version to NPM.