diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1c6314a --- /dev/null +++ b/.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/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1ed55d5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,22 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Node.js ${{ matrix.node-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: + - 20 + - 18 + - 16 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..239ecff --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/index.js b/index.js new file mode 100644 index 0000000..ab912a6 --- /dev/null +++ b/index.js @@ -0,0 +1,7 @@ +export default function unicornFun(input, {postfix = 'rainbows'} = {}) { + if (typeof input !== 'string') { + throw new TypeError(`Expected a string, got ${typeof input}`); + } + + return `${input} & ${postfix}`; +} diff --git a/license b/license new file mode 100644 index 0000000..81c4848 --- /dev/null +++ b/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Your Name (https://yourwebsite.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: + +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/package.json b/package.json new file mode 100644 index 0000000..67b5148 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "unicorn-fun", + "version": "0.0.0", + "description": "My awesome module", + "license": "MIT", + "repository": "YOUR-GITHUB-USERNAME/unicorn-fun", + "author": { + "name": "YOUR NAME", + "email": "YOUR EMAIL", + "url": "YOUR WEBSITE" + }, + "type": "module", + "exports": "./index.js", + "engines": { + "node": ">=16" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "keywords": [ + "unicorn", + "fun" + ], + "dependencies": {}, + "devDependencies": { + "ava": "^5.3.0", + "xo": "^0.54.2" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..126a2f1 --- /dev/null +++ b/readme.md @@ -0,0 +1,65 @@ +# node-module-boilerplate + +> Boilerplate to kickstart creating a Node.js module + +This is what I use for [my own modules](https://www.npmjs.com/~sindresorhus). + +Also check out [`node-cli-boilerplate`](https://github.com/sindresorhus/node-cli-boilerplate). + +## Getting started + +**Click the "Use this template" button.** + +Alternatively, create a new directory and then run: + +```sh +curl -fsSL https://github.com/sindresorhus/node-module-boilerplate/archive/main.tar.gz | tar -xz --strip-components=1 +``` + +There's also a [Yeoman generator](https://github.com/sindresorhus/generator-nm). + +--- + +**Remove everything from here and above** + +--- + +# unicorn-fun + +> My awesome module + +## Install + +```sh +npm install unicorn-fun +``` + +## Usage + +```js +import unicornFun from 'unicorn-fun'; + +unicornFun('unicorns'); +//=> 'unicorns & rainbows' +``` + +## API + +### unicornFun(input, options?) + +#### input + +Type: `string` + +Lorem ipsum. + +#### options + +Type: `object` + +##### postfix + +Type: `string`\ +Default: `'rainbows'` + +Lorem ipsum. diff --git a/test.js b/test.js new file mode 100644 index 0000000..4a65edc --- /dev/null +++ b/test.js @@ -0,0 +1,13 @@ +import test from 'ava'; +import unicornFun from './index.js'; + +test('main', t => { + t.throws(() => { + unicornFun(123); + }, { + instanceOf: TypeError, + message: 'Expected a string, got number', + }); + + t.is(unicornFun('unicorns'), 'unicorns & rainbows'); +});