npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@well-do-it-too/ts-universal-package

v1.0.7

Published

A universal TypeScript package template for creating libraries compatible with React, Node.js, and web projects

Downloads

9

Readme

ISC License TypeScript Node.js GitHub release (latest by date) GitHub tag (latest by date)

ts-universal-package

A universal TypeScript package template for creating libraries that can be used in React, Node.js, and web projects.

Features

  • TypeScript support
  • Compatible with browser and Node.js environments
  • Easy to use and extend
  • Includes example functions
  • Configured with ESLint, Prettier, and Husky for code quality
  • Uses Rollup for building and bundling
  • Vitest for testing

Demo

You can see a live demo of this package in action at our GitHub Pages demo site.

This demo showcases the basic functionality of the package, including:

  • Greeting function
  • Number doubling function
  • Package name retrieval

Feel free to inspect the source code of the demo page for an example of how to integrate this package into your web projects.

Installation

npm install @well-do-it-too/ts-universal-package

Usage

In a TypeScript/JavaScript project

import { greet, doubleNumber, getMyName } from '@well-do-it-too/ts-universal-package';

console.log(greet('World')); // Output: Hello, World!
console.log(doubleNumber(5)); // Output: 10
console.log(getMyName()); // Output: Well Do It Too

In a browser

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Universal Package Demo</title>
</head>
<body>
    <h1>Universal Package Demo</h1>
    <div id="result"></div>

    <script src="https://unpkg.com/@well-do-it-too/ts-universal-package"></script>
    <script>
        const resultDiv = document.getElementById('result');
        const greeting = welldoittoo.greet('Browser');
        const doubledNumber = welldoittoo.doubleNumber(21);
        const name = welldoittoo.getMyName();

        resultDiv.innerHTML = `
            <p>${greeting}</p>
            <p>Double of 21 is: ${doubledNumber}</p>
            <p>Name: ${name}</p>
        `;
    </script>
</body>
</html>

Integration Guide

React Project

  1. Install the package:

    npm install @well-do-it-too/ts-universal-package
  2. Import and use in your React component:

    import React from 'react';
    import { greet, doubleNumber } from '@well-do-it-too/ts-universal-package';
    
    function MyComponent() {
      return (
        <div>
          <h1>{greet('React')}</h1>
          <p>Double of 10 is: {doubleNumber(10)}</p>
        </div>
      );
    }
    
    export default MyComponent;

Node.js Project

  1. Install the package:

    npm install @well-do-it-too/ts-universal-package
  2. Use in your Node.js script:

    const { greet, doubleNumber } = require('@well-do-it-too/ts-universal-package');
    
    console.log(greet('Node.js'));
    console.log(`Double of 7 is: ${doubleNumber(7)}`);

Web Project (via CDN)

You can include the package directly in your HTML file using a CDN:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web Project Demo</title>
</head>
<body>
    <div id="result"></div>

    <script src="https://unpkg.com/@well-do-it-too/ts-universal-package"></script>
    <script>
        const { greet, doubleNumber } = welldoittoo;
        
        const resultDiv = document.getElementById('result');
        resultDiv.innerHTML = `
            <h1>${greet('Web')}</h1>
            <p>Double of 15 is: ${doubleNumber(15)}</p>
        `;
    </script>
</body>
</html>

Examples

You can find example usage of this package in the example/ directory of this repository. This includes:

  • Basic HTML usage
  • Node.js script example
  • React component example

To run the examples locally:

  1. Clone the repository
  2. Navigate to the example/ directory
  3. Open the HTML file in a browser or run the Node.js script

Development

  1. Clone the repository:

    git clone https://github.com/Well-do-it-too/ts-universal-package.git
    cd ts-universal-package
  2. Install dependencies:

    pnpm install
  3. Run tests:

    pnpm test
  4. Build the package:

    pnpm build
  5. Run pre-commit checks:

    pnpm pre-commit

Using Make commands

Run these commands with make <command>:

  • make or make help: Shows all available Make commands.
  • make rmdist: Removes the dist folder.
  • make build: Builds the project (includes removing dist folder).
  • make test: Runs the test suite.
  • make version-up: Updates the project version.
  • make pre: Runs pre-commit checks.

Git Tag Management

The project includes additional commands for managing Git tags:

  • make tag: Displays the latest Git tag.
  • make tag-new: Displays the next Git tag that would be created.
  • make tag-up: Creates and pushes a new Git tag. Note: This command can only be run from the 'main' branch.

Scripts

  • pnpm clean: Remove node_modules and pnpm-lock.yaml
  • pnpm rmdist: Remove the dist folder
  • pnpm build: Build the package
  • pnpm test: Run tests
  • pnpm lint: Run ESLint
  • pnpm format: Format code with Prettier
  • pnpm check: Run linter and Prettier checks
  • pnpm version-up: Update package version
  • pnpm pre-commit: Run pre-commit checks

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the ISC License.

Links


Developed with ❤️ by Well-do-it-too