Skip to content

Commit

Permalink
refactor (#24)
Browse files Browse the repository at this point in the history
* refactor helpers

* refactor tests

* refactor Grammar

* change size
  • Loading branch information
MikeDevice authored May 2, 2020
1 parent 157d68c commit b08646c
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 301 deletions.
6 changes: 2 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"extends": "airbnb-base",
"globals": {
"define": true
},
"rules": {
"array-callback-return": "off",
"consistent-return": "off",
"no-loop-func": "off",
"no-underscore-dangle": "off",
"no-loop-func": "off"
"object-curly-newline": "off"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![GitHub release](https://img.shields.io/github/release/MikeDevice/first-follow.svg)](https://github.com/MikeDevice/first-follow/releases)
[![Coverage Status](https://coveralls.io/repos/github/MikeDevice/first-follow/badge.svg?branch=master)](https://coveralls.io/github/MikeDevice/first-follow?branch=master)

A small tool for calculating first, follow and predict sets for a grammar. Its size is only 804 bytes (minified and gzipped). No dependencies. [Size Limit](https://github.com/ai/size-limit) controls the size.
A small tool for calculating first, follow and predict sets for a grammar. Its size is only 697 bytes (minified and gzipped). No dependencies. [Size Limit](https://github.com/ai/size-limit) controls the size.


## Installation
Expand Down
230 changes: 0 additions & 230 deletions lib/Grammar.js

This file was deleted.

4 changes: 0 additions & 4 deletions lib/constants.js

This file was deleted.

27 changes: 6 additions & 21 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
const { EMPTY_CHAIN } = require('./constants');
exports.uniq = (arr) => arr.filter((item, index) => arr.indexOf(item) === index);

exports.addToSet = (dest, src, { skipEmptyChain } = {}) => new Set([
...dest,
...skipEmptyChain
? [...src].filter((item) => item !== EMPTY_CHAIN)
: src,
]);
exports.union = (arr1, arr2) => exports.uniq(arr1.concat(arr2));

exports.mapSetsToArrays = (sets) => {
const result = {};

Object.keys(sets).map((key) => {
result[key] = [...sets[key]];
});

return result;
};
exports.compact = (arr) => arr.filter(Boolean);

exports.indexBy = (arr, func) => {
const iteratee = func || ((a) => a);
exports.indexBy = (arr) => {
const result = {};

arr.forEach((item, index) => {
const key = iteratee(item, index);
result[key] = item;
arr.forEach((item) => {
result[item] = item;
});

return result;
Expand Down
Loading

0 comments on commit b08646c

Please sign in to comment.