Skip to content

Commit

Permalink
Merge 0b2812e into 9a20286
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Jun 5, 2017
2 parents 9a20286 + 0b2812e commit b41518b
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 10 deletions.
28 changes: 28 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/cjs/index.js",
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "launch",
"name": "Launch File",
"program": "${file}",
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"vsicons.presets.angular": false
}
15 changes: 15 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,15 @@
<a name="0.1.2"></a>
## [0.1.2](https://github.com/danielo515/object-translate/compare/v0.1.1...v0.1.2) (2017-03-15)



<a name="0.1.1"></a>
## [0.1.1](https://github.com/danielo515/object-translate/compare/v0.1.0...v0.1.1) (2017-01-12)



<a name="0.1.0"></a>
# 0.1.0 (2017-01-12)



1 change: 1 addition & 0 deletions README.md
Expand Up @@ -6,6 +6,7 @@
[![David](https://img.shields.io/david/danielo515/object-translate.svg?style=flat-square)](https://david-dm.org/danielo515/object-translate)
[![Coverage Status](https://img.shields.io/coveralls/danielo515/object-translate.svg?style=flat-square)](https://coveralls.io/github/danielo515/object-translate)
[![npm](https://img.shields.io/npm/dt/object-translate.svg?style=flat-square)](https://www.npmjs.com/package/object-translate)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)


> Easily turn objects into other objects.
Expand Down
42 changes: 42 additions & 0 deletions __tests__/index.test.js
Expand Up @@ -169,6 +169,48 @@ describe(`object-translate`, () => {
const result = converter(original);
expect(result).toEqual(expected);

});
it(`Function processor without path or alternatives returns null`, () => {

const original = {
a: {
b: {
c: `cvalue`
}
},
d: {
e: {
f: `fvalue`
}
}
};
const expected = {
more: {
deep: {
cvalue: null,
fvalue: `fvalue from function`
}
}
};
const processor = o => (`${o} from function`);
const mapping = {
more: {
deep: {
cvalue: {
processor,
},
fvalue: {
processor,
path: `d.e.f`
}
}
}
};

const converter = Generator(mapping);
const result = converter(original);
expect(result).toEqual(expected);

});
it(`Using a function for concatenating two values`, () => {

Expand Down
28 changes: 20 additions & 8 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "object-translate",
"version": "0.1.2",
"version": "1.0.0",
"description": "Easily turn objects into other objects.",
"main": "cjs/index.js",
"browser": "dist/objectTranslate.js",
Expand All @@ -23,18 +23,21 @@
"precommit": "npm run lint:test",
"prepush": "npm run lint:test",
"release": "release-it",
"recommend-bump": "conventional-recommended-bump -p angular",
"changelog": "standard-changelog",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"lint": "npm run lint:eslint",
"lint:eslint": "eslint src/*.js",
"test": "clear && jest",
"test:coverage": "jest --coverage ",
"test:watch": "clear && jest --watch",
"test:coverage": "jest --coverage",
"test:watch": "clear && jest --watch --coverage",
"lint:test": "npm run lint && npm run test:coverage",
"build": "clear && npm run lint:test && npm run build:cjs && npm run build:es && npm run build:umd",
"build:watch": "clear && rimraf cjs && cross-env BABEL_ENV=cjs babel -w src --out-dir cjs",
"build:es": "rimraf es && cross-env BABEL_ENV=es babel src --out-dir es",
"build:cjs": "rimraf cjs && cross-env BABEL_ENV=cjs babel src --out-dir cjs",
"build:umd": "rimraf dist && cross-env BABEL_ENV=es rollup -c & cross-env BABEL_ENV=es NODE_ENV=production rollup -c"
"build:umd": "rimraf dist && cross-env BABEL_ENV=es rollup -c & cross-env BABEL_ENV=es NODE_ENV=production rollup -c",
"cm": "git-cz"
},
"keywords": [],
"author": "Danielo Rodriguez Rivero (rdanielo@gmail.com)",
Expand All @@ -45,24 +48,33 @@
"babel-core": "^6.17.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.16.0",
"commitizen": "^2.9.6",
"conventional-recommended-bump": "^1.0.0",
"coveralls": "^2.11.15",
"cross-env": "^3.1.3",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.12.0",
"eslint-config-devine": "^1.6.1",
"eslint-plugin-babel": "^4.0.0",
"husky": "^0.12.0",
"jest": "^18.1.0",
"rimraf": "^2.5.4",
"release-it": "^2.5.1",
"husky": "^0.12.0",
"rimraf": "^2.5.4",
"rollup": "^0.39.2",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-bundle-size": "^1.0.1",
"rollup-plugin-commonjs": "^7.0.0",
"rollup-plugin-uglify": "^1.0.1"
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-uglify": "^1.0.1",
"standard-changelog": "^1.0.1"
},
"dependencies": {
"object-path": "^0.11.3",
"traverse": "^0.6.6"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
7 changes: 5 additions & 2 deletions src/index.js
Expand Up @@ -29,7 +29,8 @@ module.exports = (mapDefinition, defaults) => {
}
if (hasProcessor) {
if (!hasAlternatives && !item.path) {
return;
console.warn(`You have provided a processor func. without path or alternatives. Null will be returned`);
return null;
}
path = hasAlternatives
? path
Expand All @@ -38,7 +39,9 @@ module.exports = (mapDefinition, defaults) => {
}
}

const originalValue = Op[getMethod](originalObj, path) || Op[getMethod](defaults, path);
let originalValue = Op[ getMethod ](originalObj, path);
// try to use a default value ONLY if the original value is undefined. Values like false, 0, '', null, will pass as they are
originalValue = originalValue === undefined ? Op[ getMethod ](defaults, path) : originalValue;

const newValue = process(originalValue, originalObj);

Expand Down

0 comments on commit b41518b

Please sign in to comment.