Welcome to template-ts-npm, an elegant and modular TypeScript project template designed to streamline the development of npm libraries. Developed by Monadica, this template offers a solid foundation to build, test, and distribute modern TypeScript packages effortlessly.
- TypeScript: Type-safe development with easy compilation to various JavaScript module formats.
- ESM Support: Out-of-the-box ESM format support for broad compatibility.
- Testing with Jest: Write robust unit tests with Jest.
- Linting and Formatting: Ensure code consistency with ESLint and Prettier.
- Automatic Documentation: Generate documentation from TSDoc comments with TypeDoc.
- Automated Semantic Versioning: Manage versioning with
standard-version
for seamless releases.
To use this template for your next TypeScript npm package, follow these steps:
Clone this repository to your local machine and navigate to the project directory.
git clone https://github.com/monadicarts/template-ts-npm.git
cd template-ts-npm
- Install Dependencies
Install the required dependencies using npm or yarn.
npm install
- Customize Project
Replace template-ts-npm with your project name in package.json, README.md, and other relevant files.
- Start Coding
You’re now ready to start building your own TypeScript npm package!
template-ts-npm/
├── src/ # Main source code
│ └── index.ts # Entry point of the library
├── dist/ # Compiled output
├── __tests__/ # Unit tests
├── .husky/ # Git hooks for automated checks
├── .eslintrc.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript configuration
├── rollup.config.js # Rollup configuration (optional, for advanced bundling)
├── jest.config.js # Jest configuration for testing
├── typedoc.json # TypeDoc configuration for documentation
└── README.md # Project documentation
After setting up the template and customizing it for your project, you can start adding your TypeScript code in the src/ directory.
Export your public API in src/index.ts, and this will serve as the entry point for your npm package. Here’s an example of a basic function and class you can add:
// src/index.ts
export const greet = (name: string): string => `Hello, ${name}!`;
export class Greeter {
constructor(public greeting: string) {}
greet(name: string): string {
return `${this.greeting}, ${name}!`;
}
}
Compile and publish your package when ready, following the Scripts section below.
A set of npm scripts are preconfigured to streamline development and publishing:
npm run build
: Compiles TypeScript to a JavaScript ESM module.npm test
: Runs Jest tests.npm run lint
: Checks code for linting errors using ESLint.npm run format
: Formats code with Prettier.npm run docs
: Generates documentation with TypeDoc.npm run release
: Bumps version and updates changelog based on commit messages using standard-version.npm publish
: Publishes the package to npm.
This template includes configuration files for various tools, such as:
- TypeScript (
tsconfig.json
): Configures compiler options and output. - ESLint (
.eslintrc.js
): Configures linting rules for code consistency. - Prettier (
.prettierrc
): Configures formatting rules for consistent style. - Jest (
jest.config.js
): Configures Jest for unit testing. - TypeDoc (
typedoc.json
): Configures TypeDoc for documentation generation.
We welcome contributions! To contribute:
- Fork the repository and create a new branch (
git checkout -b feature/YourFeature
). - Make your changes and commit them (
git commit -m "Add feature"
). - Push to the branch (
git push origin feature/YourFeature
). - Open a Pull Request.
If you have any questions or suggestions, please reach out to us at monadicarts@gmail.com.
This project is licensed under the MIT License.
Developed and maintained by Monadica.
Thank you for using template-ts-npm
! We hope this template helps you create amazing TypeScript npm packages with ease.
- GitHub: github.com/monadicarts
- Website: monadica.com
- Email: monadicarts@gmail.com
Happy Coding! 🚀