@pipli/core v0.0.6
Core
core
is a Node.js package that contains a collection of utility functions and tools that can be used across different services and projects. The goal of this package is to reduce code duplication by providing a common set of tools and utilities that can be easily shared between different services.
Installation
To use core
package in your project, run:
npm i --save @pipli/core
Usage
To use core
in your project, simply require it in your code:
import { capitalize } from 'core'
const myString = 'hello, world'
const capitalizedString = capitalize(myString)
console.log(capitalizedString) // Output: "Hello, world"
Publishing package
- First, make sure you're logged in to npm by running the following command in your terminal and entering your npm credentials when prompted:
npm login
- Update the version number in your package.json file
npm version <new-version>
Replace with the new version number (e.g. 1.0.1).
Once you're logged in, you can build your package by running the following command in your package directory:
npm run build
This will create a lib
folder containing the compiled and bundled code for your package.
Make sure to run npm run format
and npm run lint
before building the package to check for any eslint error.
- Now you're ready to publish your package to the npm registry. You can do this by running the following command:
npm publish
That's it! Your package is now published and ready for others to use.
Documenting Utility Functions and classes with TypeDoc
TypeDoc provides a set of tags for documenting TypeScript code. Here's an example of how to use TypeDoc syntax to document a utility function:
/**
* Capitalizes the first letter of a string.
*
* @param str - The input string to capitalize.
* @returns The capitalized string.
*/
export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}
classes can be documented using the below syntax
export class Statistics {
/**
* Returns the average of two numbers.
*
* @remarks
* This method is part of the {@link core-library#Statistics | Statistics subsystem}.
*
* @param x - The first input number
* @param y - The second input number
* @returns The arithmetic mean of `x` and `y`
*/
public static getAverage(x: number, y: number): number {
return (x + y) / 2.0;
}
}
You can use the following command to generate documentation for the package
npm run doc:generate
This command generates documentation for the package and outputs it to the docs directory.