Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(usecase/nodecli): Rest/Spreadプロパティを使って書き直し #351

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/base.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ module.exports = {
},
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
rules: {
"indent": [
Expand Down
9 changes: 5 additions & 4 deletions source/use-case/nodecli/md-to-html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,17 @@ program.parse(process.argv);
markedのデフォルト設定と同じですが、アプリケーション側でデフォルト設定を持っておくことで、将来的にmarkedの挙動が変わったときにも影響を受けにくくなります。

markedのオプションはオブジェクトを渡す形式です。
オブジェクトのデフォルト値を明示的な値で上書きするときには`Object.assign`メソッドを使うと便利です。([オブジェクトのコピー・マージ](../../../basic/object/README.md)を参照)
オブジェクトのデフォルト値を明示的な値で上書きするときにはRest/Spreadプロパティを使うと便利です。([オブジェクトのコピー・マージ](../../../basic/object/README.md)を参照)
次のようにデフォルトのオプションを表現したオブジェクトに対して、コマンドライン引数をパースして得られたオブジェクトを上書きします。

<!-- 差分コードなので -->
<!-- doctest:disable -->
```js
const markedOptions = Object.assign({}, {
const markedOptions = {
gfm: true,
sanitize: false
}, program);
sanitize: false,
...program
};
```

あとは`markedOptions`オブジェクトからmarkedにオプションを渡すだけです。
Expand Down
7 changes: 4 additions & 3 deletions source/use-case/nodecli/md-to-html/src/main-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ program
program.parse(process.argv);
const filePath = program.args[0];

const markedOptions = Object.assign({}, {
const markedOptions = {
gfm: true,
sanitize: false
}, program);
sanitize: false,
...program
};

fs.readFile(filePath, "utf8", (err, file) => {
if (err) {
Expand Down