# xtractor

> String extraction for i18n

Latest version **0.20.0** (published 2017-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install xtractor
pnpm add xtractor
yarn add xtractor
bun add xtractor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.20.0 |
| Published | 2017-04-28 |
| First published | 2016-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Arthur Lee |
| Maintainers | arthuralee |

## Links

- npm: https://www.npmjs.com/package/xtractor
- Repository: https://github.com/pinterest-web/xtractor
- Homepage: https://github.com/pinterest-web/xtractor.git
- Issues: https://github.com/pinterest-web/xtractor/issues
- npm.io page: https://npm.io/package/xtractor

## Dependencies (11)

- [mocha](https://npm.io/package/mocha.md) ^2.5.3
- [eslint](https://npm.io/package/eslint.md) ^2.13.1
- [babylon](https://npm.io/package/babylon.md) ^6.17.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [babel-cli](https://npm.io/package/babel-cli.md) ^6.23.0
- [node-glob](https://npm.io/package/node-glob.md) ^1.2.0
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.11
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^6.1.2
- [babel-traverse](https://npm.io/package/babel-traverse.md) ^6.23.1
- [gettext-parser](https://npm.io/package/gettext-parser.md) ^1.2.2
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.22.0

## Recent versions

- 0.20.0 (latest) — 2017-04-28
- 0.18.0 — 2017-02-16
- 0.17.0 — 2017-02-16
- 0.16.0 — 2016-06-01
- 0.15.0 — 2016-05-31
- 0.13.0 — 2016-05-24
- 0.12.0 — 2016-05-18
- 0.11.0 — 2016-05-18
- 0.10.0 — 2016-05-17
- 0.9.0 — 2016-05-17
- 0.8.1 — 2016-05-10
- 0.8.0 — 2016-05-10
- 0.7.0 — 2016-05-10
- 0.6.1 — 2016-05-10
- 0.6.0 — 2016-05-10
- … 6 more at https://npm.io/package/xtractor/versions

## README

# xtractor 🚜 [![Build Status](https://img.shields.io/travis/pinterest-web/xtractor/master.svg?style=flat)](https://travis-ci.org/pinterest-web/xtractor) [![npm version](https://img.shields.io/npm/v/xtractor.svg?style=flat)](https://www.npmjs.com/package/xtractor)

> Simple string extraction

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

## Usage

Import the library
```js
var xtractor = require('xtractor');
```
or
```js
import * as xtractor from 'xtractor';
```

### Extract strings from a file

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

A promise-based API is also supported

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

### Extract strings from a glob

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

Promised-based API

```js
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

```js
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
```js
const str = i18n._('You have new messages');
```
will output
```json
{
    "msgid": "You have new messages",
    "loc": [
        {
            "filepath": "sample.js",
            "line": 1
        }
    ]
}
```

### Plural
```js
const str = i18n._('You have {{ count }} new message', 'You have {{ count }} new messages', count);
```
will output
```json
{
    "msgid": [
        "You have {{ count }} new message",
        "You have {{ count }} new messages"
    ],
    "loc": [
        {
            "filepath": "sample.js",
            "line": 1
        }
    ]
}
```

---
_Source: https://npm.io/package/xtractor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
