Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function splitLines(text, sep = detectNewLine(text) || '\n') {
return List(text.split(sep));
}
const deserializeCode = (opts, text) => {
const sep = detectNewline(text) || DEFAULT_NEWLINE
const lines = List(text.split(sep)).map((line) =>
Block.create({
type: opts.line,
nodes: [Text.create(line)],
}),
)
const code = Block.create({
type: opts.block,
nodes: lines,
})
return code
}
function deserializeCode(opts: Options, text: string): Block {
const sep = detectNewline(text) || DEFAULT_NEWLINE;
const lines = List(text.split(sep)).map(line =>
Block.create({
type: opts.lineType,
nodes: [Text.create(line)]
})
);
const code = Block.create({
type: opts.containerType,
nodes: lines
});
return code;
}
export default function (inputPath: string, options?: Options = {}) {
const input = fs.readFileSync(inputPath).toString()
const EOL = detectNewline(input)
const escapedEOL = escapeStringRegexp(EOL)
const closingTokens = [tokTypes.bracketR, tokTypes.braceR, tokTypes.braceBarR, tokTypes.parenR, tokTypes.backQuote]
.map(({ label }) => label)
.map(escapeStringRegexp)
const closingRegexp = new RegExp(`^\\s*((?:${closingTokens.join('|')}|\\s)+)\\s*${closingTokens[1]}.*$`, 'm')
const getClosingLineTokens = (line: string) => {
const matches = line.match(closingRegexp)
return matches ? matches[1] : ''
}
const lines = input.split(EOL)
let output = input
async _patchAsync(
specs: npmPackageArg.Result[],
packageType: 'dependencies' | 'devDependencies'
) {
const pkgPath = path.join(this.options.cwd || '.', 'package.json');
const pkgRaw = await fs.readFile(pkgPath, { encoding: 'utf8', flag: 'r' });
const pkg = JSON.parse(pkgRaw);
specs.forEach(spec => {
pkg[packageType] = pkg[packageType] || {};
pkg[packageType][spec.name!] = spec.rawSpec;
});
await fs.writeJson(pkgPath, pkg, {
spaces: detectIndent(pkgRaw).indent,
EOL: detectNewline(pkgRaw),
});
}
}
private async _patchAsync(
specs: npmPackageArg.Result[],
packageType: 'dependencies' | 'devDependencies'
) {
const pkgPath = path.join(this.options.cwd || '.', 'package.json');
const pkgRaw = await fs.readFile(pkgPath, { encoding: 'utf8', flag: 'r' });
const pkg = JSON.parse(pkgRaw);
specs.forEach(spec => {
pkg[packageType] = pkg[packageType] || {};
pkg[packageType][spec.name!] = spec.rawSpec;
});
await fs.writeJson(pkgPath, pkg, {
spaces: detectIndent(pkgRaw).indent,
EOL: detectNewline(pkgRaw),
});
}
}