From 9451f26da98990b5a55aa9bbe533de3f8786c32e Mon Sep 17 00:00:00 2001 From: Edgar Toll Date: Tue, 19 Feb 2019 16:33:03 +0100 Subject: [PATCH] begin typescript boilerplate see #16 --- typescript/.editorconfig | 12 ++++++++ typescript/.gitattributes | 1 + typescript/.gitignore | 3 ++ typescript/.npmrc | 1 + typescript/.travis.yml | 5 +++ typescript/license | 9 ++++++ typescript/package.json | 62 ++++++++++++++++++++++++++++++++++++++ typescript/readme.md | 47 +++++++++++++++++++++++++++++ typescript/source/index.ts | 9 ++++++ typescript/test/test.ts | 11 +++++++ 10 files changed, 160 insertions(+) create mode 100644 typescript/.editorconfig create mode 100644 typescript/.gitattributes create mode 100644 typescript/.gitignore create mode 100644 typescript/.npmrc create mode 100644 typescript/.travis.yml create mode 100644 typescript/license create mode 100644 typescript/package.json create mode 100644 typescript/readme.md create mode 100644 typescript/source/index.ts create mode 100644 typescript/test/test.ts diff --git a/typescript/.editorconfig b/typescript/.editorconfig new file mode 100644 index 0000000..1c6314a --- /dev/null +++ b/typescript/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/typescript/.gitattributes b/typescript/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/typescript/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/typescript/.gitignore b/typescript/.gitignore new file mode 100644 index 0000000..c406da7 --- /dev/null +++ b/typescript/.gitignore @@ -0,0 +1,3 @@ +node_modules +yarn.lock +dist diff --git a/typescript/.npmrc b/typescript/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/typescript/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/typescript/.travis.yml b/typescript/.travis.yml new file mode 100644 index 0000000..2ae9d62 --- /dev/null +++ b/typescript/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - '10' + - '8' + - '6' diff --git a/typescript/license b/typescript/license new file mode 100644 index 0000000..76dcfda --- /dev/null +++ b/typescript/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) <%= name %> <<%= email %>> (<%= website %>) + +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. diff --git a/typescript/package.json b/typescript/package.json new file mode 100644 index 0000000..0f2f02d --- /dev/null +++ b/typescript/package.json @@ -0,0 +1,62 @@ +{ + "name": "<%= moduleName %>", + "version": "0.0.0", + "description": "", + "license": "MIT", + "repository": "<%= githubUsername %>/<%= moduleName %>", + "author": { + "name": "<%= name %>", + "email": "<%= email %>", + "url": "<%= website %>" + }, + "engines": { + "node": ">=6" + }, + "scripts": { + "build": "del dist && tsc", + "prepare": "npm run build", + "pretest": "npm run build", + "test": "xo && ava" + }, + "main": "dist", + "types": "dist", + "files": [ + "dist", + "!*.test.*" + ], + "keywords": [ + "" + ], + "dependencies": {}, + "devDependencies": { + "@sindresorhus/tsconfig": "^0.2.1", + "@types/node": "^11.9.0", + "@typescript-eslint/eslint-plugin": "^1.3.0", + "ava": "^1.2.1", + "del-cli": "^1.1.0", + "eslint-config-xo-typescript": "^0.8.0", + "ts-node": "^8.0.2", + "typescript": "^3.3.3", + "xo": "^0.24.0" + }, + "ava": { + "babel": false, + "compileEnhancements": false, + "extensions": [ + "ts" + ], + "require": [ + "ts-node/register" + ] + }, + "xo": { + "extends": "xo-typescript", + "extensions": [ + "ts" + ], + "rules": { + "@typescript-eslint/promise-function-async": "off", + "ava/no-ignored-test-files": "off" + } + } +} diff --git a/typescript/readme.md b/typescript/readme.md new file mode 100644 index 0000000..edf1cdd --- /dev/null +++ b/typescript/readme.md @@ -0,0 +1,47 @@ +# <%= moduleName %> [![Build Status](https://travis-ci.org/<%= githubUsername %>/<%= moduleName %>.svg?branch=master)](https://travis-ci.org/<%= githubUsername %>/<%= moduleName %>) + +> + + +## Install + +``` +$ npm install <%= moduleName %> +``` + + +## Usage + +```js +const <%= camelModuleName %> = require('<%= moduleName %>'); + +<%= camelModuleName %>('unicorns'); +//=> 'unicorns & rainbows' +``` + + +## API + +### <%= camelModuleName %>(input, [options]) + +#### input + +Type: `string` + +Lorem ipsum. + +#### options + +Type: `Object` + +##### foo + +Type: `boolean`
+Default: `false` + +Lorem ipsum. + + +## License + +MIT © [<%= name %>](https://github.com/<%= githubUsername %>) diff --git a/typescript/source/index.ts b/typescript/source/index.ts new file mode 100644 index 0000000..9fb791e --- /dev/null +++ b/typescript/source/index.ts @@ -0,0 +1,9 @@ +'use strict'; + +export default function(input: string) { + if (typeof input !== 'string') { + throw new TypeError(`Expected a string, got ${typeof input}`); + } + + return input + ' & rainbows'; +}; diff --git a/typescript/test/test.ts b/typescript/test/test.ts new file mode 100644 index 0000000..95bb918 --- /dev/null +++ b/typescript/test/test.ts @@ -0,0 +1,11 @@ +import test from 'ava'; +import moduleName from '.'; + +test('title', t => { + const err = t.throws(() => { + moduleName(123); + }, TypeError); + t.is(err.message, 'Expected a string, got number'); + + t.is(moduleName('unicorns'), 'unicorns & rainbows'); +});