Shapeshifter
Shapeshifter is a general format converter. It converts strings of one format (shape) into a string of another.
Installation
npm install @gotamedia/shapeshifter
Usage
API
const { OpenContentShapeProvider, ShapeBuilder } = require("@gotamedia/shapeshifter");
const shape = await new ShapeBuilder()
.useShapeProvider(new OpenContentShapeProvider())
.useInput(inputString)
.build();
console.log(shape.shift());
That's it! You can use any number of shape providers or plug in your own. To enable all available shape providers you can use a shape provider resolver.
const { ShapeBuilder, ShapeProviderResolver } = require("@gotamedia/shapeshifter");
const shape = await new ShapeBuilder()
.useShapeProviderResolver(new ShapeProviderResolver("/path/to/shape/providers/"))
.useInput(inputString)
.build();
console.log(shape.shift());
This saves you from updating the code anytime you want to use additional shape providers.
CLI
Shapeshifter also comes with a convenient CLI tool. You can use it to convert shapes in npm scripts or simply on the command line.
The shapeshifter command accepts input as stdin. This makes it easy to use with pipes. Here is a simple example using curl on the command line to fetch and convert an article from Open Content.
curl --silent --user [credentials] http://xlibris.oc.gota.infomaker.io:8080/opencontent/objects/[uuid] | shapeshifter
And here is an example of converting an article in a file.
shapeshifter < [path/to/article].xml
License
Shapeshifter is released under the MIT License.