Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed May 4, 2019
1 parent b07d62a commit 0493e02
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 139 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Expand Up @@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
yarn.lock
13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
7 changes: 3 additions & 4 deletions .travis.yml
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
- '12'
- '10'
- '8'
54 changes: 35 additions & 19 deletions cli.js
@@ -1,24 +1,40 @@
#!/usr/bin/env node
'use strict';
var meow = require('meow');
var dogNames = require('./');
const meow = require('meow');
const dogNames = require('.');

var cli = meow({
help: [
'Examples',
' $ dog-names',
' Lucy',
'',
' $ dog-names --all --type male',
' Max',
' Buddy',
' ...',
'',
'Options',
' --all Get all names instead of a random name',
' --type Type of name: female|male|all Default: all'
]
const cli = meow(`
Usage:
$ dog-names
Options
--all Get all the names instead of a random name
--type Type of name [Default: all] [Values: female, male, all]
Examples
$ dog-names
Lucy
$ dog-names --all --type male
Max
Buddy
`, {
flags: {
all: {
type: 'boolean',
default: false
},
type: {
type: 'string',
default: 'all'
}
}
});

var type = cli.flags.type || 'all';
console.log(cli.flags.all ? dogNames[type].join('\n') : dogNames[type + 'Random']());
const {all, type} = cli.flags;

if (!['female', 'male', 'all'].includes(type)) {
throw new Error(`Invalid type provided: '${type}'. Valid types are: 'female', 'male', 'all'.`);
}

console.log(all ? dogNames[type].join('\n') : dogNames[type + 'Random']());
84 changes: 84 additions & 0 deletions index.d.ts
@@ -0,0 +1,84 @@
import femaleDogNames = require('./female-dog-names.json');
import maleDogNames = require('./male-dog-names.json');

declare const dogNames: {
/**
Top 100 female dog names sorted by popularity.
@example
```
import dogNames = require('dog-names');
dogNames.female;
//=> ['Bella', 'Lucy', …]
```
*/
readonly female: Readonly<typeof femaleDogNames>;

/**
Top 100 male dog names sorted by popularity.
@example
```
import dogNames = require('dog-names');
dogNames.male;
//=> ['Max', 'Buddy', …]
```
*/
readonly male: Readonly<typeof maleDogNames>;

/**
Top 200 dog names sorted by popularity.
@example
```
import dogNames = require('dog-names');
dogNames.all;
//=> ['Bella', 'Max', …]
```
*/
readonly all: Readonly<typeof femaleDogNames> & Readonly<typeof maleDogNames>;

/**
Random female dog name.
@example
```
import dogNames = require('dog-names');
dogNames.femaleRandom();
//=> 'Lucy'
```
*/
femaleRandom(): string;

/**
Random male dog name.
@example
```
import dogNames = require('dog-names');
dogNames.maleRandom();
//=> 'Toby'
```
*/
maleRandom(): string;

/**
Random dog name.
@example
```
import dogNames = require('dog-names');
dogNames.allRandom();
//=> 'Coco'
```
*/
allRandom(): string;
};

export = dogNames;
18 changes: 10 additions & 8 deletions index.js
@@ -1,13 +1,15 @@
'use strict';
var uniqueRandomArray = require('unique-random-array');
var femaleDogNames = require('./female-dog-names.json');
var maleDogNames = require('./male-dog-names.json');
const uniqueRandomArray = require('unique-random-array');
const femaleDogNames = require('./female-dog-names.json');
const maleDogNames = require('./male-dog-names.json');

var allDogNames = [];

femaleDogNames.forEach(function (el, i) {
allDogNames.push(el, maleDogNames[i]);
});
const allDogNames = femaleDogNames.reduce(
(allDogNames, femaleDogName, index) => {
allDogNames.push(femaleDogName, maleDogNames[index]);
return allDogNames;
},
[]
);

exports.female = femaleDogNames;
exports.male = maleDogNames;
Expand Down
9 changes: 9 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,9 @@
import {expectType} from 'tsd';
import dogNames = require('.');

expectType<readonly string[]>(dogNames.female);
expectType<readonly string[]>(dogNames.male);
expectType<readonly string[]>(dogNames.all);
expectType<string>(dogNames.femaleRandom());
expectType<string>(dogNames.maleRandom());
expectType<string>(dogNames.allRandom());
20 changes: 4 additions & 16 deletions license
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

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:
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 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.
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.
108 changes: 58 additions & 50 deletions package.json
@@ -1,52 +1,60 @@
{
"name": "dog-names",
"version": "1.0.2",
"description": "Get popular dog names",
"license": "MIT",
"repository": "sindresorhus/dog-names",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "ava"
},
"files": [
"index.js",
"cli.js",
"female-dog-names.json",
"male-dog-names.json"
],
"keywords": [
"cli-app",
"cli",
"superb",
"awesome",
"word",
"words",
"list",
"array",
"random",
"rand",
"animal",
"dog",
"dogs",
"puppy",
"name",
"names",
"female",
"male"
],
"dependencies": {
"meow": "^3.3.0",
"unique-random-array": "^1.0.0"
},
"devDependencies": {
"ava": "*"
}
"name": "dog-names",
"version": "1.0.2",
"description": "Get popular dog names",
"license": "MIT",
"repository": "sindresorhus/dog-names",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bin": "cli.js",
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts",
"cli.js",
"female-dog-names.json",
"male-dog-names.json"
],
"keywords": [
"cli-app",
"cli",
"superb",
"awesome",
"word",
"words",
"list",
"array",
"random",
"rand",
"animal",
"dog",
"dogs",
"puppy",
"name",
"names",
"female",
"male"
],
"dependencies": {
"meow": "^5.0.0",
"unique-random-array": "^2.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"tsd": {
"compilerOptions": {
"resolveJsonModule": true
}
}
}

0 comments on commit 0493e02

Please sign in to comment.