-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (24 loc) · 818 Bytes
/
Copy pathindex.js
File metadata and controls
31 lines (24 loc) · 818 Bytes
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
const binary = require('node-pre-gyp')
const path = require('path')
const bindingPath = binary.find(
path.resolve(path.join(__dirname, './package.json'))
)
const fuso = require(bindingPath)
function isNonEmptyString(str) {
return typeof str === 'string' && str.length > 0
}
function transform(json, template) {
if (!isNonEmptyString(json)) {
throw new TypeError('1st argument (json) must be a non-empty string')
}
if (!template || typeof template !== 'object') {
throw new TypeError('2nd argument (template) must be an object')
}
const template_string = JSON.stringify(template)
let result = fuso.transform(json, template_string)
if (!result) {
throw new TypeError('Invalid input: Malformed json')
}
return result
}
module.exports = transform