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

typed-data-handler

v1.0.3

Published

A TypeScript utility library for handling and validating various data types.

Downloads

91

Readme

TypedDataHandler

npm version License publish-npm

TypedDataHandler is a TypeScript utility library that simplifies handling and validating various data types, including strings, numbers, dates, email addresses, and more. It provides functions and classes to perform common data manipulations, validations, conversions, and formatting.

Installation

To use TypedDataHandler in your TypeScript project, install it via npm:

npm install typed-data-handler

Features

  • Type Validation: Validate data against common types, such as strings, numbers, booleans, arrays, objects, and dates.
  • Email Validation: Validate email addresses to ensure they follow the correct format.
  • Data Conversion: Convert data from one type to another, e.g., string to number, parsing JSON data, or formatting dates.
  • String Manipulation: Utility functions to manipulate strings, like capitalizing the first letter, trimming whitespace, or extracting substrings.
  • Data Formatting: Functions to format data, such as formatting numbers with a specified number of decimal places or formatting dates in a specific format.
  • Data Parsing: Parse data from strings into appropriate data types, like parsing dates from strings or converting comma-separated values into arrays.
  • Data Serialization: Methods to serialize and deserialize data, making it easier to store and retrieve data from different sources.
  • Custom Validators: Define custom validation rules and add them to the library.

Usage

import { isEmail, formatDate, toNumber, capitalize } from 'typed-data-handler';

const email = '[email protected]';
if (isEmail(email)) {
  console.log('Valid email address');
} else {
  console.log('Invalid email address');
}

const date = new Date();
const formattedDate = formatDate(date, 'yyyy-MM-dd');
console.log(`Formatted date: ${formattedDate}`);

const numberString = '42';
const numberValue = toNumber(numberString);
console.log(`Parsed number: ${numberValue}`);

const text = 'hello world';
const capitalizedText = capitalize(text);
console.log(`Capitalized text: ${capitalizedText}`);

Contributing

Contributions are welcome! If you encounter any issues or have ideas for improvements, please open an issue or submit a pull request. Please ensure that your code adheres to the project's coding standards and includes appropriate tests.

License

This project is open-source and available under the MIT License.

Test Instructions

The "TypedDataHandler" library includes test suites to ensure its functionality and reliability. To run the tests locally, follow these steps:

Install Dependencies:

Before running the tests, make sure you have all the required dependencies installed. If you haven't done so already, install the project dependencies by running:

npm install

Run Tests Locally

To execute the test suite, use the following command in your terminal:

npm test

The test runner (Jest) will automatically find and run all the test files located in the tests folder.

View Test Results

After running the tests, Jest will display the test results in the terminal. You should see a list of test cases along with their status (passed or failed).

Additionally, Jest will generate a coverage report to show how much of your code is covered by the tests. You can find the coverage report in the coverage folder after running the tests.