Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

poeditor-utils

Package Overview
Dependencies
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poeditor-utils - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/client.d.ts

202

lib/utils.js

@@ -1,66 +0,140 @@

'use strict';
var Client = require('poeditor-client');
var Promise = require('bluebird');
var Immutable = require('immutable');
var fs = Promise.promisifyAll(require('fs'));
var stringify = require('json-stable-stringify');
var Translation = require('./Translation');
exports.getProject = function (apiToken, projectName) {
var client = new Client(apiToken);
return Promise.resolve(client.projects.list())
.then(function (projects) {
return Immutable.List(projects)
.find(function (project) {
return project.name == projectName;
});
});
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
exports.getTranslations = function (project) {
return Promise.resolve(project.languages.list())
.map(function (language) {
return Promise.resolve(language.terms.list())
.map(function (term) {
return new Translation(term.term, language.code, term.translation);
});
})
.then(function (items) {
return Immutable.fromJS(items).flatten(1).toJS();
});
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.writeTranslations = function (translations, getFile) {
var writes = Immutable.List(translations)
.groupBy(getFile)
.map(function (translations) {
return Immutable.List(translations)
.reduce(function (result, translation) {
return result.set(translation.term, translation.value);
}, Immutable.Map());
})
.map(function (translations, file) {
var data = stringify(translations, {
space: '\t'
});
return fs.writeFileAsync(file, data)
.then(function () {
return file;
});
})
.toList()
.toJS();
return Promise.all(writes);
};
exports.pullTranslations = function (apiToken, projectName, getFile) {
return exports.getProject(apiToken, projectName)
.then(function (project) {
return exports.getTranslations(project);
})
.then(function (translations) {
return exports.writeTranslations(translations, getFile);
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var util = require("util");
var stringify = require("json-stable-stringify");
var client_1 = require("./client");
var fs = require("./fs");
function getProject(apiToken, projectName) {
return __awaiter(this, void 0, void 0, function () {
var client;
return __generator(this, function (_a) {
client = client_1.createClient(apiToken);
return [2 /*return*/, Promise.resolve(client.projects.list())
.then(function (projects) { return projects.find(function (project) { return project.name == projectName; }); })];
});
});
}
exports.getProject = getProject;
function getTranslations(project) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, Promise.resolve(project.languages.list())
.then(function (languages) {
return Promise.all(languages.map(function (language) {
return Promise.resolve(language.terms.list())
.then(function (terms) { return terms.map(function (term) {
var translation = new LegacyTranslation();
translation.projectName = project.name;
translation.languageCode = language.code;
translation.term = term.term;
translation.value = term.translation;
return translation;
}); });
}))
.then(function (translations) { return [].concat.apply([], translations); });
})];
});
});
}
exports.getTranslations = getTranslations;
var LegacyTranslation = /** @class */ (function () {
function LegacyTranslation() {
}
Object.defineProperty(LegacyTranslation.prototype, "language", {
get: function () {
return translationGetLanguageDeprecation(this);
},
set: function (value) {
translationSetLanguageDeprecation(this, value);
},
enumerable: true,
configurable: true
});
return LegacyTranslation;
}());
exports.LegacyTranslation = LegacyTranslation;
var translationLanguageDeprecate = function (fn) { return util.deprecate(fn, 'poeditor-utils Translation.language is deprecated and will be removed in future versions. Please use Translation.languageCode instead.'); };
var translationGetLanguageDeprecation = translationLanguageDeprecate(function (translation) { return translation.languageCode; });
var translationSetLanguageDeprecation = translationLanguageDeprecate(function (translation, value) { return translation.languageCode = value; });
function groupTranslations(translations, grouper) {
return translations.reduce(function (map, translation) {
var key = grouper(translation);
var translations = map.get(key);
if (!translations) {
map.set(key, [translation]);
}
else {
translations.push(translation);
}
return map;
}, new Map());
}
exports.groupTranslations = groupTranslations;
function formatTranslations(translations) {
return stringify(translations.reduce(function (obj, translation) {
obj[translation.term] = translation.value;
return obj;
}, {}), {
space: '\t',
});
}
exports.formatTranslations = formatTranslations;
function writeTranslations(translations, getPathCallback) {
return __awaiter(this, void 0, void 0, function () {
var translationsByPath;
return __generator(this, function (_a) {
translationsByPath = groupTranslations(translations, getPathCallback);
return [2 /*return*/, Promise.all(Array.from(translationsByPath.entries()).map(function (_a) {
var path = _a[0], translations = _a[1];
var data = formatTranslations(translations);
return fs.writeFileAsync(path, data).then(function () { return path; });
}))];
});
});
}
exports.writeTranslations = writeTranslations;
function pullTranslations(apiToken, projectName, getPathCallback) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, exports.getProject(apiToken, projectName)
.then(function (project) { return exports.getTranslations(project); })
.then(function (translations) { return exports.writeTranslations(translations, getPathCallback); })];
});
});
}
exports.pullTranslations = pullTranslations;
{
"name": "poeditor-utils",
"version": "0.1.0",
"description": "high-level POEditor API utilities",
"version": "0.2.0",
"description": "higher-level POEditor utilities for Node.js",
"keywords": [
"POEditor",
"localization",
"api",
"utility"
"utils"
],
"homepage": "https://github.com/famousgarkin/node-poeditor-utils",
"repository": {
"type": "git",
"url": "https://github.com/smartsupp/node-poeditor-utils"
},
"license": "MIT",
"author": "Ján Dzurek <famousgarkin@outlook.com>",
"main": "index.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"/lib"
],
"scripts": {
"test": "jasmine"
"test": "make build test"
},
"devDependencies": {
"eslint": "^1.10.3",
"jasmine": "^2.4.1",
"native-promise-only": "^0.8.1",
"rewire": "^2.5.1"
"engines": {
"node": ">=8"
},
"dependencies": {
"bluebird": "^3.0.6",
"immutable": "^3.7.6",
"json-stable-stringify": "^1.0.0",
"poeditor-client": "0.0.4"
},
"devDependencies": {
"@types/jasmine": "^3.3.9",
"@types/node": "^11.11.3",
"jasmine": "^3.3.1",
"ts-node": "^8.0.3",
"typescript": "^3.3.3333"
}
}
# poeditor-utils
[![Build Status](https://travis-ci.org/famousgarkin/node-poeditor-utils.svg?branch=master)](https://travis-ci.org/famousgarkin/node-poeditor-utils)
higher-level POEditor utilities for Node.js
high-level [POEditor API][1] utilities for Node.js
* uses [POEditor API v1][1] via [poeditor-client][2]
* API is still a subject to change
* based around [poeditor-client][2]
* API is a subject to change
[1]: https://poeditor.com/api_reference/
[2]: https://github.com/janjakubnanista/poeditor-client
```js
var utils = require('poeditor-utils');
import * as utils from 'poeditor-utils'
```
## utils.getProject(apiToken, projectName)
## ~~utils.Client(apiToken)~~ [DEPRECATED]
* `apiToken` `String` POEditor API token
* `projectName` `String` POEditor project name
* `apiToken: string` - POEditor API token
Returns a promise which resolves with a [poeditor-client][2] `Project` representation of the project. See the docs there for more.
Exposes the [poeditor-client][2] `Client` for practicality. See their docs for more.
```js
utils.getProject('my token', 'my project')
.then(function (project) {
console.log(project); // Project {...}
});
```
## ~~utils.getProject(apiToken, projectName)~~ [DEPRECATED]
* `apiToken: string` - POEditor API token
* `projectName: string` - POEditor project name
Returns a promise which resolves with a [poeditor-client][2] `Project` representation of the project. See their docs for more.
## utils.pullTranslations(apiToken, projectName, getPathCallback)
* `apiToken` `String` POEditor API token
* `projectName` `String` POEditor project name
* `getPathCallback(translation)` `Function` produces destination file path for given translation
* `translation` `Object` translation of a single term to a single language
* `translation.term` `String`
* `translation.language` `String`
* `translation.value` `String`
* `apiToken: string` - POEditor API token
* `projectName: string` - POEditor project name
* `getPathCallback: (translation) => string` - produces destination file path for given translation
* `translation: Object` - translation of a single term to a single language with the following properties:
* `projectName: string`
* `languageCode: string`
* `term: string`
* `value: string`
Gets translations for all the project languages and writes them to files as produced by `getPathCallback` as a stable sorted JSON. Returns a promise which resolves with an `Iterable` of output files.
Gets translations for all the project languages and writes them to files by `getPathCallback` as a stable sorted JSON. Returns a promise which resolves with an array of file paths written.
```js
utils.pullTranslations('my token', 'my project', function (translation) {
console.log(translation); // Translation {...}
return 'my-translations/' + translation.language + '.json';
utils.pullTranslations('API token', 'project name', (translation) => {
console.log(translation) // Translation {...}
return 'translations/' + translation.languageCode + '.json'
})
.then(function (files) {
console.log(files); // ['my-translations/en.json', ...]
});
.then((paths) => {
console.log(paths) // ['translations/en.json', ...]
})
```
## utils.Client
Exposes the [poeditor-client][2] `Client` for practicality. See the docs there for more.
### new utils.Client(apiToken)
* `apiToken`: POEditor API token
```js
var client = new utils.Client('my token');
```
[1]: https://poeditor.com/api_reference/
[2]: https://github.com/janjakubnanista/poeditor-client

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc