Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

proto-expand

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proto-expand - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

8

dist/index.d.ts

@@ -17,4 +17,4 @@ /**

* To do that:
* 1. quotes not preceded by backslash are replaced by double quotes
* 2. the ones preceded by backslash are replaced by a single quote
* 1. double quotes replace quotes not preceded by backslash
* 2. a single quote replaces quotes preceded by backslash
* @param str

@@ -24,3 +24,3 @@ */

/**
* Get an object, create a json and then entangle it to a `knot` entry
* Get an object, create a JSON and then entangle it to a `knot` entry
* @param obj

@@ -32,3 +32,3 @@ */

*/
declare const untangle: (str: string) => any;
declare const untangle: (str: string) => any[][];
/**

@@ -35,0 +35,0 @@ * Entangle a JSON to the text of a 'knot' entry

@@ -49,3 +49,3 @@ var __defProp = Object.defineProperty;

var parseKnotEntry = (str) => {
let cleanText = str.replace(/"/g, "\\'").replace(/(?<!\\)'/g, '"').replace(/\\'/g, "'").replace(/"(.*?)"/gs, (match) => match.replace(/\n/g, "\\n"));
let cleanText = str.replace(/(?<!\\)"/g, "\\'").replace(/(?<!\\)'/g, '"').replace(/\\'/g, "'").replace(/"(.*?)"/gs, (match) => match.replace(/\n/g, "\\n"));
try {

@@ -59,3 +59,3 @@ return JSON.parse(cleanText);

};
var knotEntry = (obj) => JSON.stringify(obj).replace(/'/g, "\\'").replace(/"/g, "'").replace(/\\\n/g, "\n").replace(/'/g, "'");
var knotEntry = (obj) => !obj ? obj : JSON.stringify(obj).replace(/'/g, "\\'").replace(/"/g, "'").replace(/\\\n/g, "\n").replace(/'/g, "'");
var untangle = (str) => {

@@ -62,0 +62,0 @@ const array = parseKnotStringToArray(str);

@@ -40,3 +40,3 @@ #!/usr/bin/env node

var parseKnotEntry = (str) => {
let cleanText = str.replace(/"/g, "\\'").replace(/(?<!\\)'/g, '"').replace(/\\'/g, "'").replace(/"(.*?)"/gs, (match) => match.replace(/\n/g, "\\n"));
let cleanText = str.replace(/(?<!\\)"/g, "\\'").replace(/(?<!\\)'/g, '"').replace(/\\'/g, "'").replace(/"(.*?)"/gs, (match) => match.replace(/\n/g, "\\n"));
try {

@@ -50,3 +50,3 @@ return JSON.parse(cleanText);

};
var knotEntry = (obj) => JSON.stringify(obj).replace(/'/g, "\\'").replace(/"/g, "'").replace(/\\\n/g, "\n").replace(/'/g, "'");
var knotEntry = (obj) => !obj ? obj : JSON.stringify(obj).replace(/'/g, "\\'").replace(/"/g, "'").replace(/\\\n/g, "\n").replace(/'/g, "'");
var untangle = (str) => {

@@ -425,3 +425,3 @@ const array = parseKnotStringToArray(str);

}
function readProcess(content, inputExtension) {
function parseInput(content, inputExtension) {
switch (inputExtension) {

@@ -432,4 +432,2 @@ case ".json":

return import_json5.default.parse(content);
case ".txt":
return ProcessDefinition.parseKnotString(content);
case ".yaml":

@@ -442,8 +440,6 @@ return import_yaml.default.parse(content);

}
function generateOutput(output, outputExtension) {
function formatOutput(output, outputExtension) {
switch (outputExtension) {
case ".json":
return JSON.stringify(output, null, 2);
case ".txt":
return output.exportToKnotString();
case ".yaml":

@@ -455,31 +451,44 @@ return import_yaml.default.stringify(output, { lineWidth: 0 });

}
function parseAndExpand(content, inputExtension, options) {
const pd = options.inputKnot ? ProcessDefinition.parseKnotString(content) : readProcess(content, inputExtension);
return options.expand ? pd.expand(extractDimensions(JSON.parse(readFile(options.expand)))) : pd;
function expand(pd, payloadFile) {
return pd.expand(extractDimensions(JSON.parse(readFile(payloadFile))));
}
program.name("process-parse").description("Parse process files with optional output formats and expansion.").usage("[options] <files ...>").argument("<files...>", "Files to parse. Format is recognized by extension (.yaml, .txt, .json, .json5)").option("-u, --untangle", "Format a 'knot' file as a valid JSON file, retaining the internal structure").option("-e, --entangle", "Convert a JSON file into a 'knot' file, retaining the internal structure").option("-j, --json", "Output as JSON files").option("-5, --json5", "Output as JSON5 files (default)").option("-y, --yaml", "Output as YAML files").option("-k, --knot", "Output as 'knot' files (uses '.txt' extension").option("-x, --expand <payload-file>", "Expand content before output using the specified payload file").option("-i, --input-knot", "Interpret input as a 'knot' file regardless of file extension").option("-o, --output <dir-name>", "Save generated files to the specified directory").showHelpAfterError().action((files, options) => {
var _a;
if (options.untangle && (options.knot || options.expand)) {
console2.log("Incompatible options");
process.exit(1);
function generateOutput(content, inputExtension, outputExtension, options, inputKnot) {
if (options.entangle)
return entangle(parseInput(content, inputExtension));
if (options.untangle)
return formatOutput(untangle(content), outputExtension);
if (options.expandUntangled) {
const inputProcess = ProcessDefinition.parseKnotString(entangle(parseInput(content, inputExtension)));
const pd2 = expand(inputProcess, options.expandUntangled);
return formatOutput(untangle(pd2.exportToKnot()), outputExtension);
}
const targetDir = (_a = options.dirName) != null ? _a : process.cwd();
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const pd = inputKnot ? ProcessDefinition.parseKnotString(content) : parseInput(content, inputExtension);
const processDefinition = options.expand ? expand(pd, options.expand) : pd;
return outputExtension == ".txt" ? processDefinition.exportToKnot() : formatOutput(processDefinition, outputExtension);
}
program.name("process-parse").description("Parse process files with optional output formats and expansion.").usage("[options] <files ...>").argument("<files...>", "Files to parse. Format is recognized by extension (.yaml, .txt, .json, .json5)").option("-u, --untangle", "Format a 'knot' file as a valid JSON file, retaining the internal structure").option("-e, --entangle", "Convert a JSON file into a 'knot' file, retaining the internal structure").option("-o, --overwrite", "Overwrite output files").option("-j, --json", "Output as JSON files").option("-5, --json5", "Output as JSON5 files (default)").option("-y, --yaml", "Output as YAML files").option("-k, --knot", "Output as 'knot' files (uses '.txt' extension").option("-x, --expand <payload-file>", "Expand content before output using the specified payload file").option("-X, --expand-untangled <payload-file>", 'Equivalent to "entangle -> expand -> untangle"').option("-i, --input-knot", "Interpret input as a 'knot' file regardless of file extension").option("-d, --dir <dir-name>", "Save generated files to the specified directory").showHelpAfterError().action((files, options) => {
if (options.dir && !fs.existsSync(options.dir)) fs.mkdirSync(options.dir, { recursive: true });
files.forEach((file) => {
var _a;
const inputExtension = import_path.default.extname(file);
const outputExtension = getOutputExtension(options);
const inputKnot = options.knot || inputExtension === ".txt";
if (inputKnot && (options.entangle || options.expandUntangled)) {
console2.log("Can not entangle a `KNOT`");
process.exit(1);
}
if (options.untangle && !inputKnot) {
console2.log("Only a 'KNOT' can be untangled");
process.exit(1);
}
const content = readFile(file);
let output;
if (options.entangle) {
output = entangle(readProcess(content, inputExtension));
} else {
const outputObject = options.untangle ? untangle(content) : parseAndExpand(content, inputExtension, options);
output = generateOutput(outputObject, outputExtension);
const output = generateOutput(content, inputExtension, outputExtension, options, inputKnot);
const fileName = import_path.default.basename(file, inputExtension);
const outputFileName = import_path.default.join((_a = options.dir) != null ? _a : "", `${fileName}${outputExtension}`);
if (!options.overwrite && fs.existsSync(outputFileName))
console2.log(`Refusing to override ${outputFileName} without '--overwrite' flag`);
else {
fs.writeFileSync(outputFileName, output);
console2.log(`Output written to ${outputFileName}`);
}
const fileName = import_path.default.basename(file, inputExtension);
const outputFileName = import_path.default.join(targetDir, `${fileName}${outputExtension}`);
fs.writeFileSync(outputFileName, output);
console2.log(`Output written to ${outputFileName}`);
});

@@ -486,0 +495,0 @@ });

{
"name": "proto-expand",
"version": "1.2.1",
"version": "1.2.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc