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 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 4 years ago

Package Health Score

62 / 100
Full package analysis

Popular cson-parser functions