Repository: kentcdodds/starwars-names Branch: main Commit: 12805ee6ba2d Files: 12 Total size: 11.2 KB Directory structure: gitextract_5bm1uug2/ ├── .gitattributes ├── .gitignore ├── .nvmrc ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── package.json ├── src/ │ ├── index.js │ ├── index.test.js │ └── starwars-names.json └── webpack.config.babel.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ * text=auto *.js text eol=lf ================================================ FILE: .gitignore ================================================ node_modules coverage dist .nyc_output ================================================ FILE: .nvmrc ================================================ 6 ================================================ FILE: .travis.yml ================================================ sudo: false language: node_js cache: directories: - node_modules branches: only: - master notifications: email: false before_script: - npm prune script: - npm run cover - npm run check-coverage - npm run build after_success: - npm run report-coverage - npm run semantic-release ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing To contribute to the project, please follow these steps: 1. Get approval for the idea by filing an issue and talking with me about the changes. 2. Fork the repo 3. Make a branch for your change 4. Run `npm install` 5. Run `npm start` 6. Make your changes 7. Test your changes (we have a githook that disallows anything less than 100% code coverage) 8. Run `git add -A` to add your changes (please don't add any changes to the `dist` directory). 9. Run `npm run commit` (**Do not** use `git commit`) - follow the prompts to create your git message 10. Push your changes with `git push` 11. Create the Pull Request 12. Get merged and celebrate 🎉 🎊! ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2016 Kent C. Dodds Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # starwars-names [![travis build](https://img.shields.io/travis/kentcdodds/starwars-names.svg?style=flat-square)](https://travis-ci.org/kentcdodds/starwars-names) [![codecov coverage](https://img.shields.io/codecov/c/github/kentcdodds/starwars-names.svg?style=flat-square)](https://codecov.io/github/kentcdodds/starwars-names) [![version](https://img.shields.io/npm/v/starwars-names.svg?style=flat-square)](http://npm.im/starwars-names) [![downloads](https://img.shields.io/npm/dm/starwars-names.svg?style=flat-square)](http://npm-stat.com/charts.html?package=starwars-names&from=2015-08-01) [![MIT License](https://img.shields.io/npm/l/starwars-names.svg?style=flat-square)](http://opensource.org/licenses/MIT) [![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) Get random names from Star Wars characters. Sponsor ![starwars-names](other/starwars-names.gif) ## Installation This package is distributed via npm: ``` npm install starwars-names ``` ## Usage ```javascript var names = require('starwars-names'); var allNames = names.all; var randomName = names.random(); var threeRandomNames = names.random(3); ``` ## Other This library was developed by [me](https://twitter.com/kentcdodds) as part of an [egghead.io](http://egghead.io/) series called "How to Write a JavaScript Library." I'm now also using it to give [a workshop](http://kcd.im/fem-oss) for [Frontend Masters](https://frontendmasters.com). ### Project Setup This project assumes you have [NodeJS v6](http://nodejs.org/) or greater installed. You should also have [npm v3](https://www.npmjs.com/) or greater installed as well (this comes packaged with Node 6). You'll also need a recent version of [git](https://git-scm.com/) installed as well. You may have come to this project from different varying sources. There are a different series of branches for each workshop/course I've done. To get started with the project, start with this: 1. [Sign up](https://github.com/join) for a GitHub Account (if you don't already have one) 2. [Fork](https://help.github.com/articles/fork-a-repo/) this repo 3. [Clone](https://help.github.com/articles/cloning-a-repository/) your fork 4. In the directory you cloned the repository, run `git fetch --all` If you need help with these steps, you might check out [this free Egghead.io course](http://kcd.im/pull-request) which can help you get things going. Finally, based on which version of the project you're looking for (workshop, egghead, or Frontend Masters) you'll run one of the following commands in the cloned directory: - **Frontend Masters Workshop**: `npm run setup:fem` - **Egghead Course**: `npm run setup:egghead` If you get any failures at this point something is wrong and needs to be fixed. Remember, [Google](https://google.com) and [StackOverflow](https://stackoverflow.com) are your friends. You might find it helpful to see a list of the available branches. Run: `git branch` for that. ================================================ FILE: package.json ================================================ { "name": "starwars-names", "version": "0.0.0-semantically-released", "description": "Get random Star Wars names", "main": "dist/index.js", "scripts": { "commit": "git-cz", "check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100", "report-coverage": "cat ./coverage/lcov.info | codecov", "start": "npm run test", "watch:test": "npm t -- --watch", "test": "mocha src/index.test.js --compilers js:babel-register", "cover": "nyc --reporter=lcov npm t", "prebuild": "rimraf dist", "build": "npm-run-all --parallel build:*", "build:main": "babel --copy-files --out-dir dist --ignore *.test.js src", "build:umd": "webpack --output-filename index.umd.js", "build:umd.min": "webpack --output-filename index.umd.min.js -p", "validate": "npm run cover && npm run check-coverage", "setup": "npm install && npm run validate", "setup:fem": "git checkout FEM/10.1-docs && npm install && npm run validate && rimraf .nyc_output coverage dist .git/hooks && git checkout FEM/00-scratch", "setup:egghead": "npm run setup && rimraf dist coverage && git checkout lesson/02-setting-up-github", "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, "repository": { "type": "git", "url": "https://github.com/kentcdodds/starwars-names.git" }, "keywords": [ "random", "star", "wars" ], "files": [ "dist", "README.md" ], "author": "Kent C. Dodds (http://kentcdodds.com/)", "license": "MIT", "bugs": { "url": "https://github.com/kentcdodds/starwars-names/issues" }, "homepage": "https://github.com/kentcdodds/starwars-names#readme", "dependencies": { "unique-random-array": "1.0.0" }, "devDependencies": { "babel-cli": "6.11.4", "babel-loader": "6.2.4", "babel-preset-es2015": "6.13.2", "babel-preset-stage-2": "6.13.0", "babel-register": "6.11.6", "chai": "3.5.0", "codecov": "1.0.1", "commitizen": "2.8.5", "cz-conventional-changelog": "1.1.6", "ghooks": "1.3.2", "json-loader": "0.5.4", "mocha": "3.0.1", "npm-run-all": "2.3.0", "nyc": "7.1.0", "rimraf": "2.5.4", "semantic-release": "^4.2.1", "webpack": "1.13.1" }, "engines": { "node": "6.x", "npm": "3.x" }, "config": { "ghooks": { "pre-commit": "npm run validate" }, "commitizen": { "path": "node_modules/cz-conventional-changelog" } }, "babel": { "presets": [ "es2015", "stage-2" ] } } ================================================ FILE: src/index.js ================================================ import uniqueRandomArray from 'unique-random-array'; import starWarsNames from './starwars-names.json'; const getRandomItem = uniqueRandomArray(starWarsNames); module.exports = { all: starWarsNames, random: random }; function random(number) { if (number === undefined) { return getRandomItem(); } else { const randomItems = []; for (let i = 0; i < number; i++) { randomItems.push(getRandomItem()); } return randomItems; } } ================================================ FILE: src/index.test.js ================================================ import {expect} from 'chai'; import starWars from './index'; describe('starwars-names', function() { describe('all', function() { it('should be an array of strings', function() { expect(starWars.all).to.satisfy(isArrayOfStrings); function isArrayOfStrings(array) { return array.every(function(item) { return typeof item === 'string'; }); } }); it('should contain `Luke Skywalker`', function() { expect(starWars.all).to.include('Luke Skywalker'); }); }); describe('random', function() { it('should return a random item from the starWars.all', function() { var randomItem = starWars.random(); expect(starWars.all).to.include(randomItem); }); it('should return an array of random items if passed a number', function() { var randomItems = starWars.random(3); expect(randomItems).to.have.length(3); randomItems.forEach(function(item) { expect(starWars.all).to.include(item); }); }); }); }); ================================================ FILE: src/starwars-names.json ================================================ [ "4-LOM", "Aayla Secura", "Admiral Ackbar", "Admiral Thrawn", "Ahsoka Tano", "Anakin Solo", "Asajj Ventress", "Aurra Sing", "Senator Bail Organa", "Barriss Offee", "Bastila Shan", "Ben Skywalker", "Bib Fortuna", "Biggs Darklighter", "Boba Fett", "Bossk", "Brakiss", "C-3PO", "Cad Bane", "Cade Skywalker", "Callista Ming", "Captain Rex", "Carnor Jax", "Chewbacca", "Clone Commander Cody", "Count Dooku", "Darth Bane", "Darth Krayt", "Darth Maul", "Darth Nihilus", "Darth Vader", "Dash Rendar", "Dengar", "Durge", "Emperor Palpatine", "Exar Kun", "Galen Marek", "General Crix Madine", "General Dodonna", "General Grievous", "General Veers", "Gilad Pellaeon", "Grand Moff Tarkin", "Greedo", "Han Solo", "IG 88", "Jabba The Hutt", "Jacen Solo", "Jaina Solo", "Jango Fett", "Jarael", "Jerec", "Joruus C'Baoth", "Ki-Adi-Mundi", "Kir Kanos", "Kit Fisto", "Kyle Katarn", "Kyp Durron", "Lando Calrissian", "Luke Skywalker", "Luminara Unduli", "Lumiya", "Mace Windu", "Mara Jade", "Mission Vao", "Natasi Daala", "Nom Anor", "Obi-Wan Kenobi", "Padmé Amidala", "Plo Koon", "Pre Vizsla", "Prince Xizor", "Princess Leia", "PROXY", "Qui-Gon Jinn", "Quinlan Vos", "R2-D2", "Rahm Kota", "Revan", "Satele Shan", "Savage Opress", "Sebulba", "Shaak Ti", "Shmi Skywalker", "Talon Karrde", "Ulic Qel-Droma", "Visas Marr", "Watto", "Wedge Antilles", "Yoda", "Zam Wesell", "Zayne Carrick", "Zuckuss" ] ================================================ FILE: webpack.config.babel.js ================================================ import {join} from 'path' const include = join(__dirname, 'src') export default { entry: './src/index', output: { path: join(__dirname, 'dist'), libraryTarget: 'umd', library: 'starWarsNames', }, devtool: 'source-map', module: { loaders: [ {test: /\.js$/, loader: 'babel', include}, {test: /\.json$/, 'loader': 'json', include}, ] } }