Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit ca222f3

Browse files
author
Kent C. Dodds
committed
feat(init): Initial commit
0 parents  commit ca222f3

File tree

10 files changed

+159
-0
lines changed

10 files changed

+159
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Contributing
2+
3+
You **always** want to look at this file *before* contributing. In here you should find
4+
steps that you need to take to set up your development environment as well as instructions
5+
for coding standards and contributing guidelines.
6+
7+
You'll notice that when this file is present, GitHub will give you an alert when creating
8+
a new issue, indicating that you should check out the guidelines first:
9+
10+
![contributing-notice](other/contributing-notice.png)
11+
12+
## Set up instructions
13+
14+
1. Fork the repo
15+
2. Clone your fork
16+
3. Create a branch
17+
4. Run `npm install`
18+
5. Run `npm t && npm run build`. If everything works, then you're ready to make changes.
19+
6. Run `npm run test:watch`. See that it's watching your file system for changes.
20+
7. Make your changes and try to make the tests pass. If you can't or need help then commit what you have with `--no-verify` and make a PR
21+
8. If you get things working, add your changed files with `git add` and run `npm run commit` to get an interactive prompt for creating a commit message that follows [our standards](https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md)
22+
9. Push your changes to your fork with `git push`
23+
10. Create a pull request.
24+
11. Iterate on the solution.
25+
12. Get merged! 🎉 🎊
26+
27+
## Commit messages
28+
29+
We follow a convention for our commit messages, to learn about why and how, see [this free egghead.io series](http://kcd.im/write-oss)
30+

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# stack-overflow-copy-paste
2+
3+
[![travis build](https://img.shields.io/travis/eggheadio-github/stack-overflow-copy-paste.svg?style=flat-square)](https://travis-ci.org/eggheadio-github/stack-overflow-copy-paste)
4+
[![version](https://img.shields.io/npm/v/stack-overflow-copy-paste.svg?style=flat-square)](http://npm.im/stack-overflow-copy-paste)
5+
[![downloads](https://img.shields.io/npm/dm/stack-overflow-copy-paste.svg?style=flat-square)](http://npm-stat.com/charts.html?package=stack-overflow-copy-paste&from=2015-08-01)
6+
[![MIT License](https://img.shields.io/npm/l/stack-overflow-copy-paste.svg?style=flat-square)](http://opensource.org/licenses/MIT)
7+
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
8+
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)
9+
10+
11+
This is a collection of utility JavaScript functions copy/pasted and slightly modified from StackOverflow answers 😀
12+
13+
This repo is used as the basis for an Egghead.io series I'm working on entitled: Contributing to an Open Source Project on GitHub
14+
15+
## Usage
16+
17+
```javascript
18+
import {flatten, snakeToCamel} from 'stack-overflow-copy-paste'
19+
20+
flatten([[1, 2,], 3]) // [1, 2, 3]
21+
snakeToCamel('snake-case-string') // 'snakeCaseString'
22+
```
23+
24+
## LICENSE
25+
26+
MIT
27+

other/contributing-notice.png

6.06 KB
Loading

package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "stack-overflow-copy-paste",
3+
"version": "1.0.0",
4+
"description": "Utility functions copy/pasted (and modified slightly) from Stack Overflow",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"commit": "git-cz",
8+
"prebuild": "npm run lint && npm run clean",
9+
"clean": "rimraf dist && mkdir dist",
10+
"build": "babel src/ -d dist/",
11+
"test": "ava --require babel-register",
12+
"lint": "eslint src/"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/eggheadio-github/stack-overflow-copy-paste.git"
17+
},
18+
"keywords": [],
19+
"files": [
20+
"dist"
21+
],
22+
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/eggheadio-github/stack-overflow-copy-paste/issues"
26+
},
27+
"homepage": "https://github.com/eggheadio-github/stack-overflow-copy-paste#readme",
28+
"devDependencies": {
29+
"ava": "0.10.0",
30+
"babel-cli": "6.4.5",
31+
"babel-preset-es2015": "6.3.13",
32+
"babel-preset-stage-2": "6.3.13",
33+
"babel-register": "6.4.3",
34+
"commitizen": "2.5.0",
35+
"cz-conventional-changelog": "1.1.5",
36+
"eslint": "1.10.3",
37+
"eslint-config-kentcdodds": "5.0.1",
38+
"ghooks": "1.0.3",
39+
"nodemon": "1.8.1",
40+
"rimraf": "2.5.0",
41+
"validate-commit-msg": "1.1.1"
42+
},
43+
"config": {
44+
"ghooks": {
45+
"commit-msg": "validate-commit-msg",
46+
"pre-commit": "npm t && npm run build"
47+
},
48+
"commitizen": {
49+
"path": "node_modules/cz-conventional-changelog"
50+
}
51+
},
52+
"babel": {
53+
"presets": [
54+
"es2015",
55+
"stage-2"
56+
]
57+
},
58+
"eslintConfig": {
59+
"extends": "kentcdodds"
60+
}
61+
}

src/flatten.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default flatten
2+
3+
function flatten(arr) {
4+
return arr.reduce(function flattenReducer(flat, toFlatten) {
5+
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten)
6+
}, [])
7+
}

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import flatten from './flatten'
2+
import snakeToCamel from './snake-to-camel'
3+
4+
export {flatten, snakeToCamel}

src/snake-to-camel.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default snakeToCamel
2+
3+
const regex = /(\-\w)/g
4+
5+
function snakeToCamel(s) {
6+
return s.replace(regex, function snakeToCamelReplacer(m) {
7+
return m[1].toUpperCase()
8+
})
9+
}

test/flatten.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from 'ava'
2+
import flatten from '../src/flatten'
3+
4+
test('flattens an array of arrays', t => {
5+
const original = [[1, 2], 3, [4, 5]]
6+
const expected = [1, 2, 3, 4, 5]
7+
const actual = flatten(original)
8+
t.same(actual, expected)
9+
})

test/snake-to-camel.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import test from 'ava'
2+
import snakeToCamel from '../src/snake-to-camel'
3+
4+
test('converts snake-case to camelCase', t => {
5+
const original = 'snake-case-string'
6+
const expected = 'snakeCaseString'
7+
const actual = snakeToCamel(original)
8+
t.same(actual, expected)
9+
})
10+

0 commit comments

Comments
 (0)