This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
45 lines (42 loc) · 1.59 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
const R = require("ramda");
const svgTagList = require("./src/tagList");
const { convertSVGToJSON, getSVGFiles, getSVGFile } = require("./src/parser");
/**
* Performs a sequence of operations that transforms svg files to JSON objects with necessary svg functions.
* @param {object} options - An object containing controls options to utilize when parsing the SVG content
* @returns {Function} Promise returning function
*/
const convertSVGFolder = (options) =>
R.composeP(
(files) => convertSVGToJSON(files, options),
getSVGFiles
);
/**
* Transforms an svg file to a JSON Object with necessary svg functions.
* @param {object} options - An object containing controls options to utilize when parsing the SVG content
* @returns {Function} Promise returning function
*/
const convertSVG = (options) =>
R.composeP(
(files) => convertSVGToJSON(files, options, false),
getSVGFile
);
/**
* Converts svg files into equivalent fusion functions and outputs to the specified
* file.
* @param {Object} opts - The additional parameters to embed within the JSON object
* @returns {Promise} A promise that is resolve upon completion.
*/
const svgFolderToJSON = (opts) => convertSVGFolder(opts.options)(opts.dirPath);
/**
* Converts an SVG to JSON given a path to SVG file
* @param {Object} opts - The additional parameters to embed within the JSON object
* @returns {Promise} A promise that is resolve upon completion.
*/
const svgToJSON = (opts) => convertSVG(opts.options)(opts.path);
module.exports = {
svgFolderToJSON,
svgToJSON,
svgTagList
};