├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── index.d.ts ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 22 14 | - 20 15 | - 18 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export type Options = { 2 | /** 3 | Lorem ipsum. 4 | 5 | @default rainbows 6 | */ 7 | readonly postfix?: string; 8 | }; 9 | 10 | /** 11 | My awesome module 12 | 13 | @param input - Lorem ipsum. 14 | @returns Lorem ipsum. 15 | 16 | @example 17 | ``` 18 | import unicornFun from 'unicorn-fun'; 19 | 20 | unicornFun('unicorns'); 21 | //=> 'unicorns & rainbows' 22 | ``` 23 | */ 24 | export default function unicornFun(input: string, options?: Options): string; 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | export default function unicornFun(input, {postfix = 'rainbows'} = {}) { 2 | if (typeof input !== 'string') { 3 | throw new TypeError(`Expected a string, got ${typeof input}`); 4 | } 5 | 6 | return `${input} & ${postfix}`; 7 | } 8 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Your Name (https://yourwebsite.com) 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unicorn-fun", 3 | "version": "0.0.0", 4 | "description": "My awesome module", 5 | "license": "MIT", 6 | "repository": "YOUR-GITHUB-USERNAME/unicorn-fun", 7 | "funding": "https://github.com/sponsors/YOUR-GITHUB-USERNAME", 8 | "author": { 9 | "name": "YOUR NAME", 10 | "email": "YOUR EMAIL", 11 | "url": "YOUR WEBSITE" 12 | }, 13 | "type": "module", 14 | "exports": { 15 | "types": "./index.d.ts", 16 | "default": "./index.js" 17 | }, 18 | "sideEffects": false, 19 | "engines": { 20 | "node": ">=18" 21 | }, 22 | "scripts": { 23 | "test": "xo && ava && tsc index.d.ts" 24 | }, 25 | "files": [ 26 | "index.js", 27 | "index.d.ts" 28 | ], 29 | "keywords": [ 30 | "unicorn", 31 | "fun" 32 | ], 33 | "devDependencies": { 34 | "ava": "^6.1.3", 35 | "typescript": "^5.5.4", 36 | "xo": "^0.59.3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # node-module-boilerplate 2 | 3 | > Boilerplate to kickstart creating a Node.js module 4 | 5 | This is what I use for [my own modules](https://www.npmjs.com/~sindresorhus). 6 | 7 | Also check out [`node-cli-boilerplate`](https://github.com/sindresorhus/node-cli-boilerplate). 8 | 9 | ## Getting started 10 | 11 | **Click the "Use this template" button.** 12 | 13 | Alternatively, create a new directory and then run: 14 | 15 | ```sh 16 | curl -fsSL https://github.com/sindresorhus/node-module-boilerplate/archive/main.tar.gz | tar -xz --strip-components=1 17 | ``` 18 | 19 | --- 20 | 21 | **Remove everything from here and above** 22 | 23 | --- 24 | 25 | # unicorn-fun 26 | 27 | > My awesome module 28 | 29 | ## Install 30 | 31 | ```sh 32 | npm install unicorn-fun 33 | ``` 34 | 35 | ## Usage 36 | 37 | ```js 38 | import unicornFun from 'unicorn-fun'; 39 | 40 | unicornFun('unicorns'); 41 | //=> 'unicorns & rainbows' 42 | ``` 43 | 44 | ## API 45 | 46 | ### unicornFun(input, options?) 47 | 48 | #### input 49 | 50 | Type: `string` 51 | 52 | Lorem ipsum. 53 | 54 | #### options 55 | 56 | Type: `object` 57 | 58 | ##### postfix 59 | 60 | Type: `string`\ 61 | Default: `'rainbows'` 62 | 63 | Lorem ipsum. 64 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import unicornFun from './index.js'; 3 | 4 | test('main', t => { 5 | t.throws(() => { 6 | unicornFun(123); 7 | }, { 8 | instanceOf: TypeError, 9 | message: 'Expected a string, got number', 10 | }); 11 | 12 | t.is(unicornFun('unicorns'), 'unicorns & rainbows'); 13 | }); 14 | --------------------------------------------------------------------------------