diff --git a/.all-contributorsrc b/.all-contributorsrc index 1b3cf2e..501b968 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -369,6 +369,17 @@ "code", "doc" ] + }, + { + "login": "SleepWalker", + "name": "Sviatoslav", + "avatar_url": "https://avatars2.githubusercontent.com/u/2536916?v=4", + "profile": "https://github.com/SleepWalker", + "contributions": [ + "bug", + "code" + ] } - ] + ], + "repoType": "github" } diff --git a/README.md b/README.md index f7b138c..167f1d4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ All the benefits of npm scripts without the cost of a bloated package.json and l [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][LICENSE] -[![All Contributors](https://img.shields.io/badge/all_contributors-36-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-37-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -483,13 +483,14 @@ page. Thanks goes to these people ([emoji key][emojis]): -| [
Kent C. Dodds](http://kent.doddsfamily.us)
[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [💡](#example-kentcdodds "Examples") [📹](#video-kentcdodds "Videos") [👀](#review-kentcdodds "Reviewed Pull Requests") | [
David Wells](http://davidwells.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells "Code") | [
Abhishek Shende](https://twitter.com/abhishekisnot)
[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot "Tests") | [
Rowan Oulton](http://travelog.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=rowanoulton "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=rowanoulton "Documentation") [⚠️](https://github.com/kentcdodds/p-s/commits?author=rowanoulton "Tests") | [
Gilad Goldberg](https://github.com/giladgo)
[💻](https://github.com/kentcdodds/p-s/commits?author=giladgo "Code") | [
Tim McGee](https://github.com/tim-mcgee)
[💻](https://github.com/kentcdodds/p-s/commits?author=tim-mcgee "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=tim-mcgee "Documentation") | [
Nik Butenko](http://butenko.me)
[💡](#example-nkbt "Examples") [💻](https://github.com/kentcdodds/p-s/commits?author=nkbt "Code") | + +| [
Kent C. Dodds](http://kent.doddsfamily.us)
[💻](/kentcdodds/p-s/commits?author=kentcdodds "Code") [📖](/kentcdodds/p-s/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [💡](#example-kentcdodds "Examples") [📹](#video-kentcdodds "Videos") [👀](#review-kentcdodds "Reviewed Pull Requests") | [
David Wells](http://davidwells.io)
[💻](/kentcdodds/p-s/commits?author=DavidWells "Code") | [
Abhishek Shende](https://twitter.com/abhishekisnot)
[💻](/kentcdodds/p-s/commits?author=abhishekisnot "Code") [⚠️](/kentcdodds/p-s/commits?author=abhishekisnot "Tests") | [
Rowan Oulton](http://travelog.io)
[💻](/kentcdodds/p-s/commits?author=rowanoulton "Code") [📖](/kentcdodds/p-s/commits?author=rowanoulton "Documentation") [⚠️](/kentcdodds/p-s/commits?author=rowanoulton "Tests") | [
Gilad Goldberg](https://github.com/giladgo)
[💻](/kentcdodds/p-s/commits?author=giladgo "Code") | [
Tim McGee](https://github.com/tim-mcgee)
[💻](/kentcdodds/p-s/commits?author=tim-mcgee "Code") [📖](/kentcdodds/p-s/commits?author=tim-mcgee "Documentation") | [
Nik Butenko](http://butenko.me)
[💡](#example-nkbt "Examples") [💻](/kentcdodds/p-s/commits?author=nkbt "Code") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [
Tommy](http://www.tommyleunen.com)
[🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Atleunen "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=tleunen "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=tleunen "Tests") [👀](#review-tleunen "Reviewed Pull Requests") | [
Jayson Harshbarger](http://www.hypercubed.com)
[💡](#example-Hypercubed "Examples") [👀](#review-Hypercubed "Reviewed Pull Requests") | [
JD Isaacks](http://www.jisaacks.com)
[💻](https://github.com/kentcdodds/p-s/commits?author=jisaacks "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=jisaacks "Tests") | [
Christopher Hiller](https://boneskull.com)
[👀](#review-boneskull "Reviewed Pull Requests") [🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Aboneskull "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=boneskull "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=boneskull "Documentation") [⚠️](https://github.com/kentcdodds/p-s/commits?author=boneskull "Tests") | [
Robin Malfait](https://robinmalfait.com)
[💡](#example-RobinMalfait "Examples") | [
Eric McCormick](https://ericmccormick.io)
[👀](#review-edm00se "Reviewed Pull Requests") [📖](https://github.com/kentcdodds/p-s/commits?author=edm00se "Documentation") | [
Sam Verschueren](https://twitter.com/SamVerschueren)
[👀](#review-SamVerschueren "Reviewed Pull Requests") | -| [
Sorin Muntean](https://github.com/sxn)
[💻](https://github.com/kentcdodds/p-s/commits?author=sxn "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=sxn "Tests") [📖](https://github.com/kentcdodds/p-s/commits?author=sxn "Documentation") | [
Keith Gunn](https://github.com/gunnx)
[🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Agunnx "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=gunnx "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=gunnx "Tests") | [
Joe Martella](http://martellaj.github.io)
[🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Amartellaj "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=martellaj "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=martellaj "Tests") | [
Martin Segado](https://github.com/msegado)
[📖](https://github.com/kentcdodds/p-s/commits?author=msegado "Documentation") | [
Bram Borggreve](http://colmena.io/)
[🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Abeeman "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=beeman "Code") | [
Elijah Manor](http://elijahmanor.com)
[📹](#video-elijahmanor "Videos") | [
Ragu Ramaswamy](https://github.com/rrag)
[💻](https://github.com/kentcdodds/p-s/commits?author=rrag "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=rrag "Tests") [🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Arrag "Bug reports") | -| [
Erik Fox](http://www.erikfox.co/)
[🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Aerikfox "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=erikfox "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=erikfox "Documentation") [⚠️](https://github.com/kentcdodds/p-s/commits?author=erikfox "Tests") | [
Aditya Pratap Singh](http://blog.adityapsingh.com)
[👀](#review-addityasingh "Reviewed Pull Requests") | [
bumbleblym](https://github.com/bumbleblym)
[💻](https://github.com/kentcdodds/p-s/commits?author=bumbleblym "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=bumbleblym "Documentation") | [
Islam Attrash](https://twitter.com/IslamAttrash)
[💻](https://github.com/kentcdodds/p-s/commits?author=Attrash-Islam "Code") | [
JasonSooter](https://github.com/JasonSooter)
[📖](https://github.com/kentcdodds/p-s/commits?author=JasonSooter "Documentation") | [
Nate Cavanaugh](http://alterform.com)
[💻](https://github.com/kentcdodds/p-s/commits?author=natecavanaugh "Code") | [
Wissam Abirached](https://designingforscale.com)
[💻](https://github.com/kentcdodds/p-s/commits?author=wabirached "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=wabirached "Tests") | -| [
Paweł Mikołajczyk](https://github.com/Miklet)
[💻](https://github.com/kentcdodds/p-s/commits?author=Miklet "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=Miklet "Tests") | [
Kyle Welch](http://www.krwelch.com)
[💻](https://github.com/kentcdodds/p-s/commits?author=kwelch "Code") [⚠️](https://github.com/kentcdodds/p-s/commits?author=kwelch "Tests") | [
Lufty Wiranda](http://instagram.com/luftywiranda13)
[💻](https://github.com/kentcdodds/p-s/commits?author=luftywiranda13 "Code") | [
Bhargav Ponnapalli](http://imbhargav5.com)
[💻](https://github.com/kentcdodds/p-s/commits?author=imbhargav5 "Code") | [
falieson](https://github.com/Falieson)
[📖](https://github.com/kentcdodds/p-s/commits?author=Falieson "Documentation") [🔧](#tool-Falieson "Tools") | [
Suhas Karanth](https://github.com/sudo-suhas)
[🐛](https://github.com/kentcdodds/p-s/issues?q=author%3Asudo-suhas "Bug reports") [💻](https://github.com/kentcdodds/p-s/commits?author=sudo-suhas "Code") | [
Eric Skram](http://www.ericskram.com)
[📖](https://github.com/kentcdodds/p-s/commits?author=Vpr99 "Documentation") | -| [
Kether Saturnius](http://www.k3th3r.com)
[💻](https://github.com/kentcdodds/p-s/commits?author=iamkether "Code") [📖](https://github.com/kentcdodds/p-s/commits?author=iamkether "Documentation") | +| [
Tommy](http://www.tommyleunen.com)
[🐛](/kentcdodds/p-s/issues?q=author%3Atleunen "Bug reports") [💻](/kentcdodds/p-s/commits?author=tleunen "Code") [⚠️](/kentcdodds/p-s/commits?author=tleunen "Tests") [👀](#review-tleunen "Reviewed Pull Requests") | [
Jayson Harshbarger](http://www.hypercubed.com)
[💡](#example-Hypercubed "Examples") [👀](#review-Hypercubed "Reviewed Pull Requests") | [
JD Isaacks](http://www.jisaacks.com)
[💻](/kentcdodds/p-s/commits?author=jisaacks "Code") [⚠️](/kentcdodds/p-s/commits?author=jisaacks "Tests") | [
Christopher Hiller](https://boneskull.com)
[👀](#review-boneskull "Reviewed Pull Requests") [🐛](/kentcdodds/p-s/issues?q=author%3Aboneskull "Bug reports") [💻](/kentcdodds/p-s/commits?author=boneskull "Code") [📖](/kentcdodds/p-s/commits?author=boneskull "Documentation") [⚠️](/kentcdodds/p-s/commits?author=boneskull "Tests") | [
Robin Malfait](https://robinmalfait.com)
[💡](#example-RobinMalfait "Examples") | [
Eric McCormick](https://ericmccormick.io)
[👀](#review-edm00se "Reviewed Pull Requests") [📖](/kentcdodds/p-s/commits?author=edm00se "Documentation") | [
Sam Verschueren](https://twitter.com/SamVerschueren)
[👀](#review-SamVerschueren "Reviewed Pull Requests") | +| [
Sorin Muntean](https://github.com/sxn)
[💻](/kentcdodds/p-s/commits?author=sxn "Code") [⚠️](/kentcdodds/p-s/commits?author=sxn "Tests") [📖](/kentcdodds/p-s/commits?author=sxn "Documentation") | [
Keith Gunn](https://github.com/gunnx)
[🐛](/kentcdodds/p-s/issues?q=author%3Agunnx "Bug reports") [💻](/kentcdodds/p-s/commits?author=gunnx "Code") [⚠️](/kentcdodds/p-s/commits?author=gunnx "Tests") | [
Joe Martella](http://martellaj.github.io)
[🐛](/kentcdodds/p-s/issues?q=author%3Amartellaj "Bug reports") [💻](/kentcdodds/p-s/commits?author=martellaj "Code") [⚠️](/kentcdodds/p-s/commits?author=martellaj "Tests") | [
Martin Segado](https://github.com/msegado)
[📖](/kentcdodds/p-s/commits?author=msegado "Documentation") | [
Bram Borggreve](http://colmena.io/)
[🐛](/kentcdodds/p-s/issues?q=author%3Abeeman "Bug reports") [💻](/kentcdodds/p-s/commits?author=beeman "Code") | [
Elijah Manor](http://elijahmanor.com)
[📹](#video-elijahmanor "Videos") | [
Ragu Ramaswamy](https://github.com/rrag)
[💻](/kentcdodds/p-s/commits?author=rrag "Code") [⚠️](/kentcdodds/p-s/commits?author=rrag "Tests") [🐛](/kentcdodds/p-s/issues?q=author%3Arrag "Bug reports") | +| [
Erik Fox](http://www.erikfox.co/)
[🐛](/kentcdodds/p-s/issues?q=author%3Aerikfox "Bug reports") [💻](/kentcdodds/p-s/commits?author=erikfox "Code") [📖](/kentcdodds/p-s/commits?author=erikfox "Documentation") [⚠️](/kentcdodds/p-s/commits?author=erikfox "Tests") | [
Aditya Pratap Singh](http://blog.adityapsingh.com)
[👀](#review-addityasingh "Reviewed Pull Requests") | [
bumbleblym](https://github.com/bumbleblym)
[💻](/kentcdodds/p-s/commits?author=bumbleblym "Code") [📖](/kentcdodds/p-s/commits?author=bumbleblym "Documentation") | [
Islam Attrash](https://twitter.com/IslamAttrash)
[💻](/kentcdodds/p-s/commits?author=Attrash-Islam "Code") | [
JasonSooter](https://github.com/JasonSooter)
[📖](/kentcdodds/p-s/commits?author=JasonSooter "Documentation") | [
Nate Cavanaugh](http://alterform.com)
[💻](/kentcdodds/p-s/commits?author=natecavanaugh "Code") | [
Wissam Abirached](https://designingforscale.com)
[💻](/kentcdodds/p-s/commits?author=wabirached "Code") [⚠️](/kentcdodds/p-s/commits?author=wabirached "Tests") | +| [
Paweł Mikołajczyk](https://github.com/Miklet)
[💻](/kentcdodds/p-s/commits?author=Miklet "Code") [⚠️](/kentcdodds/p-s/commits?author=Miklet "Tests") | [
Kyle Welch](http://www.krwelch.com)
[💻](/kentcdodds/p-s/commits?author=kwelch "Code") [⚠️](/kentcdodds/p-s/commits?author=kwelch "Tests") | [
Lufty Wiranda](http://instagram.com/luftywiranda13)
[💻](/kentcdodds/p-s/commits?author=luftywiranda13 "Code") | [
Bhargav Ponnapalli](http://imbhargav5.com)
[💻](/kentcdodds/p-s/commits?author=imbhargav5 "Code") | [
falieson](https://github.com/Falieson)
[📖](/kentcdodds/p-s/commits?author=Falieson "Documentation") [🔧](#tool-Falieson "Tools") | [
Suhas Karanth](https://github.com/sudo-suhas)
[🐛](/kentcdodds/p-s/issues?q=author%3Asudo-suhas "Bug reports") [💻](/kentcdodds/p-s/commits?author=sudo-suhas "Code") | [
Eric Skram](http://www.ericskram.com)
[📖](/kentcdodds/p-s/commits?author=Vpr99 "Documentation") | +| [
Kether Saturnius](http://www.k3th3r.com)
[💻](/kentcdodds/p-s/commits?author=iamkether "Code") [📖](/kentcdodds/p-s/commits?author=iamkether "Documentation") | [
Sviatoslav](https://github.com/SleepWalker)
[🐛](/kentcdodds/p-s/issues?q=author%3ASleepWalker "Bug reports") [💻](/kentcdodds/p-s/commits?author=SleepWalker "Code") | This project follows the [all-contributors][all-contributors] specification. diff --git a/src/__tests__/kebab-and-camel-casify.js b/src/__tests__/kebab-and-camel-casify.js index 9c2734c..462ed2a 100644 --- a/src/__tests__/kebab-and-camel-casify.js +++ b/src/__tests__/kebab-and-camel-casify.js @@ -39,6 +39,27 @@ testScenario( 'deep objects', ) +testScenario( + { + default: 'nps _default foo', + _default: 'echo "default"', + foo: 'echo "foo"', + _a: 'echo "a"', + _: 'echo "this script name will be an empty string after conversion"', + '-': 'echo "this script name will be an empty string after conversion"', + }, + { + default: 'nps _default foo', + _default: 'echo "default"', + foo: 'echo "foo"', + _a: 'echo "a"', + a: 'echo "a"', + _: 'echo "this script name will be an empty string after conversion"', + '-': 'echo "this script name will be an empty string after conversion"', + }, + "won't overwrite existing scripts", +) + function testUnchanged(input, message = 'no change needed') { testScenario(input, input, message) } diff --git a/src/kebab-and-camel-casify.js b/src/kebab-and-camel-casify.js index 1459ae1..a8c131d 100644 --- a/src/kebab-and-camel-casify.js +++ b/src/kebab-and-camel-casify.js @@ -7,15 +7,20 @@ function kebabAndCamelCasify(obj) { const camel = camelCase(key) const kebab = kebabCase(key) let val = obj[key] + if (isPlainObject(obj[key])) { val = kebabAndCamelCasify(val) } - if (key !== camel || key !== kebab) { - result[camel] = val - result[kebab] = val - } else { - result[key] = val - } + + setIfPossible(result, camel, val) + setIfPossible(result, kebab, val) + return result }, obj) } + +function setIfPossible(obj, key, val) { + if (String(key).length && !(key in obj)) { + obj[key] = val + } +}