0.20.0 • Published 7 years ago

xtractor v0.20.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

xtractor 🚜 Build Status npm version

Simple string extraction

xtractor statically analyzes js files or globs of files and extracts strings within designated function call

Usage

Import the library

var xtractor = require('xtractor');

or

import * as xtractor from 'xtractor';

Extract strings from a file

xtractor.extractFromFile(__dirname + '/source.js', ['_', 'i18n._'], function(err, strings) {
    // use strings
});

A promise-based API is also supported

xtractor.extractFromFile(__dirname + '/source.js', ['_', 'i18n._'])
.then(function(strings) {
    // use strings
})
.catch(function(err) {
    // process error
});

Extract strings from a glob

xtractor.extractGlob(__dirname + '/*.js', ['_', 'i18n._'], function(err, strings) {
    // use strings
});

Promised-based API

xtractor.extractGlob(__dirname + '/*.js', ['_', 'i18n._'])
.then(function(err, strings) {
    // use strings
})
.catch(function(err) {
    // process error
});

Specify an object with the glob as the glob property and a regexp ignore pattern as the ignorePattern property

xtractor.extractGlob({
    glob: __dirname + '/**/*.js',
    ignorePattern: /node_modules/
}, ['_', 'i18n._'], function(err, strings) {
    // use strings
});

Expected and output format

The expected format for extraction is a call to the marker function with either one or three arguments, depending on pluralization.

Suppose the marker function is i18n._():

Singular

const str = i18n._('You have new messages');

will output

{
    "msgid": "You have new messages",
    "loc": [
        {
            "filepath": "sample.js",
            "line": 1
        }
    ]
}

Plural

const str = i18n._('You have {{ count }} new message', 'You have {{ count }} new messages', count);

will output

{
    "msgid": [
        "You have {{ count }} new message",
        "You have {{ count }} new messages"
    ],
    "loc": [
        {
            "filepath": "sample.js",
            "line": 1
        }
    ]
}
0.20.0

7 years ago

0.18.0

7 years ago

0.17.0

7 years ago

0.16.0

8 years ago

0.15.0

8 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.0

8 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago