Skip to content

Commit

Permalink
Fix: babel runtime (#2)
Browse files Browse the repository at this point in the history
* Chore: rm babel-runtime and update to babel 7

* Chore: update dependencies and add husky prepublish hook

* Style: eslint

* Test: src and coverage 100 percent

* Refactor: object.values to object.keys to support node 6

* Refactor: object.values to Object.keys to support node 6
  • Loading branch information
aichbauer committed Sep 7, 2018
1 parent 45418b2 commit 517132a
Show file tree
Hide file tree
Showing 7 changed files with 1,629 additions and 1,499 deletions.
6 changes: 2 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"presets": [
"env",
"es2017"
],
"plugins": ["transform-runtime"]
"@babel/env"
]
}
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"license": "MIT",
"private": false,
"scripts": {
"pretest": "npm run build && npm run lint",
"pretest": "yarn run build && yarn run lint",
"lint": "eslint src",
"test": "jest --coverage",
"build": "babel src --out-dir lib",
"prepublish": "npm run build"
"prepush": "yarn run test",
"prepublish": "yarn run build"
},
"keywords": [
"array",
Expand All @@ -34,13 +35,16 @@
]
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2017": "^6.24.1",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.9.0",
"jest": "^22.4.3"
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "^7.0.0-0",
"babel-jest": "^23.4.2",
"eslint": "^5.5.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"husky": "^0.14.3",
"jest": "^23.5.0",
"regenerator-runtime": "^0.12.1"
}
}
37 changes: 18 additions & 19 deletions src/modules/multi-column-search-array-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const checkIfValid = (data) => {
if (!Array.isArray(data)) {
throw new Error(`data has to be typeof: ${typeof []} data instanceof Array: ${[] instanceof Array} but got typeof: ${typeof data} data instanceof Array: ${data instanceof Array}`);
} else if (
Array.isArray(data) &&
data.length > 0 &&
typeof data[0] !== 'object'
Array.isArray(data)
&& data.length > 0
&& typeof data[0] !== 'object'
) {
throw new Error(`data has to be an array of objects but data[0] got typeof: ${typeof data[0]}`);
}
Expand All @@ -23,15 +23,15 @@ const createTableCheck = (data, options, tableCheck) => {
const currentSearch = searchEntry[1].type;

data.forEach((item, i) => {
const currentItemValue = item[searchEntry[0]] ?
item[searchEntry[0]].toString().toLowerCase() :
'';
const currentItemValue = item[searchEntry[0]]
? item[searchEntry[0]].toString().toLowerCase()
: '';
if (currentItem === searchEntry[0]) {
switch (currentSearch) {
case 'exact':
if (
currentItemValue === currentValue &&
currentValue.length > 0
currentItemValue === currentValue
&& currentValue.length > 0
) {
table[i][idx] = true;
} else if (currentValue.length === 0) {
Expand All @@ -43,8 +43,8 @@ const createTableCheck = (data, options, tableCheck) => {
case 'includes':
default:
if (
currentItemValue.includes(currentValue) &&
currentValue.length > 0
currentItemValue.includes(currentValue)
&& currentValue.length > 0
) {
table[i][idx] = true;
} else if (currentValue.length === 0) {
Expand All @@ -64,16 +64,15 @@ const createTableCheck = (data, options, tableCheck) => {

export const multiColumnSearchArrayTable = (data, options) => {
checkIfValid(data);
const opts = [];

const opts = Object
.entries(options)
.filter((entry) => (
typeof entry[1] === 'object' &&
(
entry[1].value ||
entry[1].value === ''
)
));
Object
.keys(options)
.forEach((key) => {
const arr = [];
arr.push(key.toString(), options[key]);
opts.push(arr);
});

const emptyTable = data.map(() => []);

Expand Down
12 changes: 6 additions & 6 deletions src/modules/search-array-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const checkIfValid = (data) => {
if (!Array.isArray(data)) {
throw new Error(`data has to be typeof: ${typeof []} data instanceof Array: ${[] instanceof Array} but got typeof: ${typeof data} data instanceof Array: ${data instanceof Array}`);
} else if (
Array.isArray(data) &&
data.length > 0 &&
typeof data[0] !== 'object'
Array.isArray(data)
&& data.length > 0
&& typeof data[0] !== 'object'
) {
throw new Error(`data has to be an array of objects but data[0] got typeof: ${typeof data[0]}`);
}
Expand All @@ -20,9 +20,9 @@ export const searchArrayTable = (data, options) => {

data.forEach((item) => {
const currentItemValues = Object
.values(item)
.map((val) => {
const result = val ? val.toString().toLowerCase() : '';
.keys(item)
.map((key) => {
const result = item[key] ? item[key].toString().toLowerCase() : '';

return result;
});
Expand Down
2 changes: 1 addition & 1 deletion test/modules/multi-column-search-array-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
expectedIncludesAr,
expectedWithNullAndUndefined,
} from '../fixtures/expected-results';
import { multiColumnSearchArrayTable as search } from '../../lib';
import { multiColumnSearchArrayTable as search } from '../../src';

test('check if data[0...n].first includes "ar"', () => {
const result = search(data, includes('ar'));
Expand Down
2 changes: 1 addition & 1 deletion test/modules/search-array-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
expectedIncludesAr,
expectedWithNullAndUndefined,
} from '../fixtures/expected-results';
import { searchArrayTable as search } from '../../lib';
import { searchArrayTable as search } from '../../src';

test('check if data[0...n] includes "ar"', () => {
const result = search(data, includes('ar'));
Expand Down

0 comments on commit 517132a

Please sign in to comment.