Skip to content

Commit

Permalink
Merge pull request #49 from groupon/parse-no-content
Browse files Browse the repository at this point in the history
fix: avoid error on empty cson/json
  • Loading branch information
aaarichter authored Mar 15, 2021
2 parents 315ab2b + ec50444 commit 85ef301
Show file tree
Hide file tree
Showing 7 changed files with 829 additions and 1,557 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ npm-debug.log
test/tmp
test/log
/.idea
.nyc_output
/.nyc_output
/coverage
7 changes: 0 additions & 7 deletions coffeelint.json

This file was deleted.

18 changes: 16 additions & 2 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ function isMissingError(error) {
return error.code === 'ENOENT';
}

function parseCSON(filename, content) {
/**
* @param {string} filename
* @param {string} content
* @returns {{}}
*/
function parseCSON(filename, content = '') {
if (content.trim().length === 0) return {};

try {
return CSON.parse(content);
} catch (err) {
Expand All @@ -69,7 +76,14 @@ function parseCSON(filename, content) {
}
}

function parseJSON(filename, content) {
/**
* @param {string} filename
* @param {string} content
* @returns {{}}
*/
function parseJSON(filename, content = '') {
if (content.trim().length === 0) return {};

try {
return JSON.parse(content);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/shared-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const { EventEmitter } = require('events');

const path = require('path');

const freeze = require('deep-freeze');
const freeze = require('deep-freeze-es6');

const { Observable } = require('rx-lite');

Expand Down
Loading

0 comments on commit 85ef301

Please sign in to comment.