How to use cson-parser - 10 common examples

To help you get started, we’ve selected a few cson-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GitSquared / edex-ui / file-icons-generator.js View on Github external
svg: '<path d="M 14.9994,6.99807L 14.9994,10.9981L 15.9994,10.9981L 15.9994,12.9981L 12.9994,12.9981L 12.9994,4.99807L 14.9994,4.99807L 11.9994,0.998068L 8.9994,4.99807L 10.9994,4.99807L 10.9994,12.9981L 7.9994,12.9981L 7.9994,10.9281C 8.7034,10.5611 9.1994,9.84707 9.1994,8.99807C 9.1994,7.78307 8.2144,6.79807 6.9994,6.79807C 5.7844,6.79807 4.7994,7.78307 4.7994,8.99807C 4.7994,9.84707 5.2954,10.5611 5.9994,10.9281L 5.9994,12.9981C 5.9994,14.1031 6.8934,14.9981 7.9994,14.9981L 10.9994,14.9981L 10.9994,18.0491C 10.2894,18.4141 9.7994,19.1451 9.7994,19.9981C 9.7994,21.2131 10.7844,22.1981 11.9994,22.1981C 13.2144,22.1981 14.1994,21.2131 14.1994,19.9981C 14.1994,19.1451 13.7084,18.4141 12.9994,18.0491L 12.9994,14.9981L 15.9994,14.9981C 17.1044,14.9981 17.9994,14.1031 17.9994,12.9981L 17.9994,10.9981L 18.9994,10.9981L 18.9994,6.99807L 14.9994,6.99807 Z"/>'
};
// Write the file
fs.writeFileSync(path.join(__dirname, "src", "assets", "icons", "file-icons.json"), JSON.stringify(fileIconsObject, "", 4));
console.log("Wrote file-icons.json");


var fileIconsMatchScript = `/*
 * Thanks everyone for pointing out this is probably on of the ugliest source code files on GitHub
 * This is script-generated code, however, so it might disqualify
 * See file-icons-generator.js at root dir of git tree
*/
function matchIcon(filename) {\n`;

// Parse the configuration file of file-icons/atom
let atomConfig = CSON.parse(fs.readFileSync(path.join(__dirname, "file-icons", "atom", "config.cson"), {encoding: "utf8"}));
Object.keys(atomConfig.directoryIcons).forEach(key => {
    let config = atomConfig.directoryIcons[key];
    if (config.icon.startsWith("_")) config.icon = config.icon.substr(1);
    if (Array.isArray(config.match)) {
        config.match.forEach(key => {
            let match = key[0];
            if (typeof match === "string") match = new RegExp(match.replace(/\./g, "\\.")+"$", "i"); // lgtm [js/incomplete-sanitization]
            fileIconsMatchScript += `    if (${match}.test(filename)) { return "${config.icon}"; }\n`;
        });
    } else {
        if (typeof config.match === "string") config.match = new RegExp(config.match.replace(/\./g, "\\.")+"$", "i"); // lgtm [js/incomplete-sanitization]
        fileIconsMatchScript += `    if (${config.match}.test(filename)) { return "${config.icon}"; }\n`;

        if (config.alias) {
            if (typeof config.alias === "string") config.alias = new RegExp(config.alias.replace(/\./g, "\\.")+"$", "i"); // lgtm [js/incomplete-sanitization]
            fileIconsMatchScript += `    if (${config.alias}.test(filename)) { return "${config.icon}"; }\n`;
github idleberg / atomizr-cli / src / converter / atom.ts View on Github external
const read = (input, options) => {
    let data, output;

    // Validate CSON
    try {
        data = parseCson.parse(input);
    } catch (error) {
        throw error;
    }

    output = {
        scope: null,
        completions: []
    };

    for (let k in data) {
        let v = data[k];

        if (options.scope !== null) {
            output.scope = options.scope;
        } else {
            // Get scope, convert if necessary
github outaTiME / applause / src / plugins / cson.js View on Github external
transform: function (pattern, opts, done) {
    var cson = pattern.cson;
    // function support
    if (_.isFunction(cson)) {
      cson.call(this, function (result) {
        // override cson function with value
        cson = result;
      });
    }
    try {
      done({
        json: CSON.parse(cson)
      });
    } catch (e) {
      done(e);
    }
  }
};
github Cloudstek / alfred-atom / src / index.ts View on Github external
configFile.on("change", (cache, file) => {
        // Read config file
        let _config: { [key: string]: any } = cson.parse(file) || {};

        _config = _config["*"] || {};

        cache.set("config", _config);
    });
github BetterThanTomorrow / calva / src / calva-fmt / update-grammar.js View on Github external
fs.readFile(contentPath, (_err, content) => {
        var grammar = cson.parse(content);
        let result = {
            information_for_contributors: [
                'This file is generated from ' + contentPath
            ]
        };

        let keys = ['name', 'scopeName', 'comment', 'injections', 'patterns', 'repository'];
        for (let key of keys) {
            if (grammar.hasOwnProperty(key)) {
                result[key] = grammar[key];
            }
        }

        try {
            fs.writeFileSync(dest, JSON.stringify(result, null, '\t').replace(/\n/g, '\r\n'));
            console.log('Updated ' + path.basename(dest));
github tunnckoCore / modern-javascript-snippets / verbfile.js View on Github external
files.map((file) => {
      let data = cson.parse(file.contents)[TOP_LEVEL_KEY]
      data = data || cson.parse(file.contents)['.source.json']

      return {
        path: file.path,
        contents: data
      }
    })
  )
github tunnckoCore / modern-javascript-snippets / verbfile.js View on Github external
files.map((file) => {
      let data = cson.parse(file.contents)[TOP_LEVEL_KEY]
      data = data || cson.parse(file.contents)['.source.json']

      return {
        path: file.path,
        contents: data
      }
    })
  )
github noseglid / atom-build / lib / atom-build.js View on Github external
function getConfig(file) {
  const fs = require('fs');
  const realFile = fs.realpathSync(file);
  delete require.cache[realFile];
  switch (require('path').extname(file)) {
    case '.json':
    case '.js':
      return require(realFile);

    case '.cson':
      return require('cson-parser').parse(fs.readFileSync(realFile));

    case '.yaml':
    case '.yml':
      return require('js-yaml').safeLoad(fs.readFileSync(realFile));
  }

  return {};
}
github vladimyr / radiocloud / stations.js View on Github external
module.exports = async function () {
  const cson = await readFile(path.join(__dirname, './stations.cson'));
  const stations = CSON.parse(cson);
  return pMap(stations.playlist.track, async station => {
    try {
      const stream = await getStreamInfo(station);
      if (!stream) return station;
      return Object.assign({}, station, { stream });
    } catch (err) {
      return station;
    }
  });
};
github microsoft / vscode / build / npm / update-grammar.js View on Github external
return download(contentPath).then(function (content) {
		var ext = path.extname(repoPath);
		var grammar;
		if (ext === '.tmLanguage' || ext === '.plist') {
			grammar = plist.parse(content);
		} else if (ext === '.cson') {
			grammar = cson.parse(content);
		} else if (ext === '.json' || ext === '.JSON-tmLanguage') {
			grammar = JSON.parse(content);
		} else {
			return Promise.reject(new Error('Unknown file extension: ' + ext));
		}
		if (modifyGrammar) {
			modifyGrammar(grammar);
		}
		return getCommitSha(repoId, repoPath).then(function (info) {
			let result = {
				information_for_contributors: [
					'This file has been converted from https://github.com/' + repoId + '/blob/master/' + repoPath,
					'If you want to provide a fix or improvement, please create a pull request against the original repository.',
					'Once accepted there, we are happy to receive an update request.'
				]
			};

cson-parser

Safe parsing of CSON files

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular cson-parser functions

Popular JavaScript code snippets

Find secure code to use in your application or website