Skip to content

Commit

Permalink
Merge 6cb3f9f into 1dccbe7
Browse files Browse the repository at this point in the history
  • Loading branch information
bingneef committed Apr 26, 2019
2 parents 1dccbe7 + 6cb3f9f commit 9ddbba0
Show file tree
Hide file tree
Showing 15 changed files with 3,884 additions and 1,851 deletions.
11 changes: 2 additions & 9 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"env": {
"test": {
"plugins": [
"rewire"
]
"plugins": ["rewire"]
}
},
"presets": [
["es2015"],
"stage-3"
]
"presets": ["@babel/preset-env"]
}


3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
dist
33 changes: 33 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": ["airbnb", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"],
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"],
"prefer-destructuring": [
"error",
{
"VariableDeclarator": {
"array": false,
"object": true
},
"AssignmentExpression": {
"array": true,
"object": false
}
},
{
"enforceForRenamedProperties": false
}
]
},
"env": {
"browser": true,
"es6": true,
"jest": true
},
"parserOptions": {
"sourceType": "module"
},
"parser": "babel-eslint"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ yarn-error.log

# External Libraries
.coveralls.yml

# Build
dist/*
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 11.13.0
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: node_js
sudo: false
node_js:
- 11.13.0
install:
- yarn install
stages:
- test
- build
- lint
jobs:
include:
- stage: test
script: yarn test:coveralls
- script: yarn prettier:check
- script: yarn lint
- stage: build
script: yarn build
deploy:
provider: npm
email: bingsteup@gmail.com
api_key:
secure: Qm/Wl+gqht8OticrUGmPoYvKl0gwKolC19nk2xK7Kbuybt6Ob083iGt1dg05m/E+bCXd5aYl6TVggIYffUemruEUgGucEI9fo4ITZo7Tu3ZJTAryLZG284h+ofTqvTGN1E2A4l7nX0XwR2TaISAXE/vzJU8uSJV1LmV/MgTUCOzDgQah/sOaeOlCUrXeGBJPZkxjE7jE8OSP1Bsq16LGL2c2TYWBe83pBGdlo5tjga5+P+jeQK/mAFXn3wKPH9sJmwoG6PmXcidsobBbwSih9p7Ms0SIUHnpYx7Q1l0CMzSYUMirfalUPwaqrDvoY3TUa03Mgyy4e3B5uRZB+diVhikIDr65JZhdcceZn3hSpsL0UmjRCgNLOw6wudARYR6bKuZxUADMvhx82S7mw39xtKv0C75AFTbZb5NQEKgi1FaEDobpb+lvSHc5MEAjUUaG/xSzBeTPMqxkSdpl6BjisUg/3T9fdC/Mm45WKyPHfsoJPu8hhyfgORvjrocDNlLNUqSyGVuWU9sVlo6nFahU+8uXJBJXRewqDYO1JGZOT6L4wLymMk7cUNYiRB3m7mPx4x4xGFbDHGItPGN3VfV1Gde96ZLmsM7W8JyGuzNcQuUuAdsi3mRSKRvwLeAVQVF1dOxaU7WJ5hHvKQX11mngTFjabulvTQ62+6BkOhc+Soo=
on:
# tags: true
# branch: master
skip_cleanup: true
repo: bingneef/map-array-response
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Map Array Response
[![Coverage Status](https://coveralls.io/repos/github/bingneef/map-array-response/badge.svg?branch=master)](https://coveralls.io/github/bingneef/map-array-response?branch=master)
[![Build Status](https://app.codeship.com/projects/17544140-d816-0135-9c8a-32bc1125dbb9/status?branch=master)
[![Build Status](https://travis-ci.org/bingneef/map-array-response.svg?branch=master)]
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0e52b6b0951d41a1822cb7d751896d4a)](https://www.codacy.com/app/bingneef/map-array-response?utm_source=github.com&utm_medium=referral&utm_content=bingneef/map-array-response&utm_campaign=Badge_Grade)
Empty file added dist/.gitkeep
Empty file.
49 changes: 0 additions & 49 deletions dist/map-array-response.js

This file was deleted.

32 changes: 25 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
{
"author": "Bing Steup",
"name": "map-array-response",
"version": "0.0.3",
"version": "0.1.0",
"description": "Map array responses on an object field",
"main": "dist/map-array-response.js",
"scripts": {
"test": "jest --env=jsdom",
"test:coveralls": "yarn test --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"build": "babel src/index.js -o dist/map-array-response.js",
"do:publish": "yarn build && yarn test:coveralls && yarn publish"
"test:full": "yarn prettier:check && yarn lint && yarn test:coveralls",
"prettier:check": "prettier --check 'src/**/*.js'",
"prettier:fix": "prettier --write src/**/*.js",
"lint": "eslint --ext .js .",
"lint:fix": "yarn lint --fix",
"build": "yarn babel src/index.js -o dist/map-array-response.js"
},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"babel-core": "^6.26.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^22.0.4",
"babel-plugin-rewire": "^1.1.0",
"babel-plugin-rewire": "^1.2.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"coveralls": "^3.0.0",
"jest": "^22.0.5",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.2.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"jest": "^24.7.1",
"prettier": "^1.17.0",
"rewire": "^3.0.2"
},
"keywords": [
"GraphQL",
"NodeJS"
],
"license": "MIT"
"license": "MIT",
"publishConfig": {
"access": "public"
}
}
55 changes: 37 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
// Find returns an value
export const mapValueResponse = (keys, field, values, { emptyValue = null } = {}) => (
mapper('find', keys, field, values)
.map(item => item == undefined ? emptyValue : item)
)

// Filter returns an array
export const mapArrayResponse = (...args) => mapper('filter', ...args, [])
// Get the attributes from nested values
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x] ? xs[x] : null), o);

// Share logic between mapArray and mapValue
const mapper = (funcName, keys, field, values) => {
if (!Array.isArray(keys)) {
throw 'Keys must be an array'
throw new Error("Keys must be an array");
}

if (typeof field !== 'string') {
throw 'Field must be a string'
if (typeof field !== "string") {
throw new Error("Field must be a string");
}

const splittedField = field.split('.')
return keys.map(key => values[funcName](item => key == get(splittedField, item)))
}
const splittedField = field.split(".");
return keys.map(key =>
values[funcName](item => key === get(splittedField, item))
);
};

// Get the attributes from nested values
const get = (p, o) => (
p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o)
)
// Find returns an value
export const mapValueResponse = (
keys,
field,
values,
{ emptyValue = null } = {}
) =>
mapper("find", keys, field, values).map(item =>
item === undefined ? emptyValue : item
);

// Filter returns an array
export const mapArrayResponse = (...args) => mapper("filter", ...args, []);

// Value to value
export const mapValueToValueResponse = mapValueResponse;

// Value to array
export const mapValueToArrayResponse = mapArrayResponse;

// Array to Value
export const mapArrayToValueResponse = (arrKeys, ...args) =>
arrKeys.map(keys => mapValueResponse(keys, ...args));

// Array to Array
export const mapArrayToArrayResponse = (arrKeys, ...args) =>
arrKeys.map(keys => mapArrayResponse(keys, ...args));
Loading

0 comments on commit 9ddbba0

Please sign in to comment.