<commit_before>'use strict';

var fs         = require('fs');
var Errorifier = require('./index.js');

console.log('\n[ Standard NodeJS errors ]\n');

var data;

try {
  data = fs.readFileSync('filename');
} catch (err) {
  console.log(err.message);

  // { [Error: ENOENT, open 'filename']
  //   errno: 34,
  //   code: 'ENOENT',
  //   path: 'filename' }
}

// inline mode
// throw new Errorifier('NotValidJSON, The format of the JSON is invalid');

// object mode
var err = new Errorifier({
  message: 'The format of the JSON is invalid',
  code: 'NotValidJSON',
  errno: 127,
  foo: 'bar'
});

console.log('\n[ handling err codes ]\n');

switch (err.code) {
  case 'NotValidJSON':
    console.log('your error logic here');
    break;
  default:
    console.log('undefined code');
    break;
}
<commit_msg>little suite of tests 😁<commit_after>'use strict';

var fs         = require('fs');
var Errorifier = require('./index.js');

console.log('\n[ Standard NodeJS errors ]\n');

var data;

try {
  data = fs.readFileSync('filename');
} catch (err) {
  console.log(err.message);

  // { [Error: ENOENT, open 'filename']
  //   errno: 34,
  //   code: 'ENOENT',
  //   path: 'filename' }
}

console.log('\n[ object constructor ]\n');

var errObjt = new Errorifier({
  message: 'The format of the JSON is invalid',
  code: 'NotValidJSON',
  errno: 127,
  foo: 'bar'
});

console.log('\n[ handling err codes ]\n');

switch (errObjt.code) {
  case 'NotValidJSON':
    console.log('your error logic here');
    break;
  default:
    console.log('undefined code');
    break;
}

// inline mode
console.log('\n[ string constructor ]\n');

var errString = new Errorifier('NotValidJSON, The format of the %s is invalid', 'JSON');

console.log(errString.message);

console.log('\n[ constructor comparation ]\n');

console.log('same message?', errString.message === errObjt.message);
console.log('same code?', errString.code === errObjt.code);
console.log('same typeof?', typeof errString === typeof errObjt);

{'fraction_non_alphanumeric': 0.17582417582417584, 'fraction_numerical': 0.004995004995004995, 'mean_word_length': 3.562642369020501, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5575567', 'n_tokens_mistral': 686, 'n_tokens_neox': 675, 'n_words': 193}