Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* 'rename' event represents a file create or delete. So we need to explicitely
* determine whether this is a file create or delete.
* https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
*/
const isFile = (await getStat(changedFile)).isFile();
if (!isFile) {
return this.logger.info(`path ${changedFile} is not a regular file. ignoring`);
}
}
const fileContent = await readFile(changedFile);
const fileChecksum = checksum(fileContent);
if (ext === '.cson') {
const data = cson.parse(fileContent.toString());
if (data && data.isTrashed) {
// If the note was deleted from BoostNote, isTrashed is set to true.
return {
event: this.constants.events.FILE_DELETE,
file: changedFile
};
}
return {
event: this.constants.events.FILE_CREATE_OR_UPDATE,
file: changedFile,
type: data.type || this.constants.fileTypes.UNKNOWN,
raw: data,
checksum: fileChecksum
};
}
return new Promise((resolve, reject) => {
cson.parse(obj, {}, (err, result: Object) => {
/* istanbul ignore next */
if (err) {
return reject(err)
}
resolve(result)
})
})
},
let toJSON = (text, name) => {
let space = "\t"
try {
let parsed = CSON.parse(text)
console.log(chalk.green.bold(`Translated ${name}`))
return JSON.stringify(parsed, null, space)
} catch (error) {
console.log(chalk.red.bold(`Translate ${name} failed`))
return null
}
}
const syncSnippetsFromAtom = (userDirectory) => {
let atomPreSnipsterMap = {}
try {
atomPreSnipsterMap = cson.parse(fs.readFileSync(os.homedir() + '/.atom/snippets.cson', 'utf-8'))
write.sync(os.homedir() + '/.atom/snippets.cson.snipster-backup-' + Date.now(), fs.readFileSync(os.homedir() + '/.atom/snippets.cson', 'utf-8'))
} catch(e) {
console.log(chalk.red("Snipster tried to find your pre-existing Atom snippets, but the snippets file does not exist. Please check that you have Atom installed.\nIf you feel there is an error, please submit an issue to ") + chalk.yellow('https://github.com/jhanstra/snipster/issues.'))
}
let snippetFilesSynced = transferMapToSnipster(atomPreSnipsterMap, 'atom', userDirectory)
}
isRoyale: +isRoyale
}),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': launcher.cookieText,
'Referer': this.referer
}
}
);
const objMatch = startGameToken.match(/PS\.game\.startGame\(([^)]*)\)/);
if(!objMatch) throw new ErrorServer();
const startObject = CSON.parse(objMatch[1]);
return {
game: startObject.gameCode + ':0',
arg: startObject.param
};
},
json = result[0];
});
} else {
try {
xmlOrJSON = xmlOrJSON.replace(
/("(?:\\.|[^"])*")|(?:,\s*)+([\]\}])|(\w+)\s*:|([\]\}]\s*[\[\{])|(\/\/.*|\/\*(?:[^\*]|\*(?=[^\/]))*?\*\/)/g,
function(_, str, extraComma, noQuote, missingComma, comment) {
if (comment)
return "";
if (missingComma)
return missingComma[0] + "," + missingComma.slice(1);
return str || extraComma || '"' + noQuote + '":';
});
json = JSON.parse(xmlOrJSON);
} catch(e) {
json = cson.parse(xmlOrJSON);
}
}
callback && callback(json);
return json;
};
const validateShipTag = async () => {
const file = await fs.readFile('shiptag.cson')
const { data } = CSON.parse(file)
const count = size(data.mapname)
assert(count > 0)
assert(size(data.color) === count)
assert(size(data.fleetname['zh-CN']) === count)
assert(size(data.fleetname['zh-TW']) === count)
assert(size(data.fleetname['ja-JP']) === count)
assert(size(data.fleetname['en-US']) === count)
}
async function CSON2JSON(name) {
const data = await fs.readFile(`${name}.cson`)
await writeJSON(`${name}.json`, CSON.parse(data))
}
fs.readFile(configPath, "utf8", (err, file) =>{
if (err) reject(err.message);
var config = CSON.parse(file);
resolve(config);
});
});
parse(rule) {
var reg = /-{3}[\s\S]+?-{3}/;
var cson = rule.comment.match(reg)[0].replace(/---/g, "");
var md = rule.comment.replace(reg, "");
this.cson = CSON.parse(cson);
this.md = md;
}
inject() {