1.3.2 • Published 3 years ago

loco-api-js v1.3.2

Weekly downloads
459
License
MIT
Repository
github
Last release
3 years ago

loco-api-js

standard-readme compliant latest-release license npm-latest size-cjs size-es

Javascript API wrapper for Loco translation system's REST API

Convenience API wrapper around the Loco REST API, written in modern Javascript. Modules are provided as CommonJS, UMD and ESM.

Table of Contents

Install

npm i loco-api-js
yarn add loco-api-js

Usage

See and run example.js or try it out in a REPL

// ESM (Bundlers, Modern engines)
import LocoClient from 'loco-api-js';

// CJS (Node)
const LocoClient = require('loco-api-js');

const loco = new LocoClient('<your-api-key>');

(async () => {
  console.log(await loco.getAssets());
  console.log(await loco.getAsset('some.asset.path'));
  console.log(await loco.getAsset(['some', 'asset', 'path']));
  console.log(await loco.getAssetsByTags(['1.5.0']));
  console.log(await loco.getTranslation('some.asset.path', 'en'));
  console.log(await loco.exportToFile({
    tags: ['production'],
    withoutTags: ['unused'],
  }));
  console.log(await loco.exportArchive({
    tags: ['production'],
    withoutTags: ['unused'],
  }));
})();

API

LocoClient

These options can be provided in an object as a second argument when creating the client to interact with.

OptionTypeRequirementDescriptionDefault
fileNamestringOptionalWhen provided, methods that export a file (JSON/ZIP) will use this nameloco-locales
debugbooleanOptionalWill be more verbose in output and show for example the API req. URLfalse

Client.exportToFile, Client.exportArchive

Provide as an object to the methods that export a file.

OptionTypeRequirementDescriptionDefault
tagsArray<string>OptionalOnly assets with these tags will be includedundefined
withoutTagsArray<string>OptionalAssets that carry this tag will not be includedundefined

Maintainers

@thibmaek

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2019 - current Thibault Maekelbergh