Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
write-json.js16 linesDownload Raw Back to lib
1// write the json back, preserving the line breaks and indent
2const { writeFile } = require('node:fs/promises')
3const kIndent = Symbol.for('indent')
4const kNewline = Symbol.for('newline')
5
6module.exports = async (path, pkg) => {
7  const {
8    [kIndent]: indent = 2,
9    [kNewline]: newline = '\n',
10  } = pkg
11  delete pkg._id
12  const raw = JSON.stringify(pkg, null, indent) + '\n'
13  const data = newline === '\n' ? raw : raw.split('\n').join(newline)
14  return writeFile(path, data)
15}
16 
codekingpro/portable-devtools · Team Ai