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

ts-fuse

v0.8.1

Published

[![npm version](https://img.shields.io/npm/v/ts-fuse.svg)](https://www.npmjs.com/package/ts-fuse) [![Downloads](https://img.shields.io/npm/dm/ts-fuse.svg)](https://www.npmjs.com/package/ts-fuse) [![GitHub](https://img.shields.io/github/license/esaiaswes

Downloads

3

Readme

TS-Fuse

npm version Downloads GitHub

Getting started | Documentation | Contributing | License

Getting started

TS-Fuse allows you to validate user input. Currently we support validating String, Number & Boolean variables. To get started install ts-fuse like this:

Installation

NPM

npm i ts-fuse

PNPM

pnpm i ts-fuse

Importing

TypeScript

import f from 'ts-fuse'

JavaScript

import f from 'ts-fuse'

Importing in JS is currently a bit weird, but the issue is known and the progress can be followed on this issue.

Create your first schema

import f from 'ts-fuse'

const stringSchema = f.String()

const value = 'This is your user input!'
const { success } = stringSchema.validate(value)

console.log(`Validation ${success ? 'was successful' : 'failed'}!`)

When you need more advanced validation, go and look at Documentation.

Documentation

Schema Validation

import f from 'ts-fuse'

// A schema can be used to validate a variable.
const stringSchema = f.String()

const stringValue = 'Hello World!'
const stringResult = stringSchema.validate(stringValue)
// Returns:
// {
//   success: true,
//   value: 'Hello World!'
// }

const numberValue = 5
const numberResult = stringSchema.validate(numberValue)
// Returns:
// {
//   success: false,
//   errors: [
//     {
//       code: 'type',
//       message: 'Value is not a valid string.',
//     }
//   ]
// }

Schema Types

Global

import f from 'ts-fuse'

/* On any schema a default value can be set. This is returned as a value if the value is undefined or null. */
const defaultStringSchema = f.String().default('default value')
const defaultNumberSchema = f.Number().default(0)

String

import f from 'ts-fuse'

/* A standard String schema will let you ensure the variable is a string. */
const stringSchema = f.String()

/* A string schema can also be used to ensure the string is a certain length. */
const lengthSchema = f.String().length(5) // Ensures the string is exactly 5 characters long.
const minLengthSchema = f.String().minLength(5) // Ensures the string is at least 5 characters long.
const maxLengthSchema = f.String().maxLength(5) // Ensures the string is at most 5 characters long.

/* A string schema can also be used to ensure the string matches a certain pattern. */
const regexSchema = f.String().regex(/^[a-z]+$/)

Number

import f from 'ts-fuse'

/* A standard Number schema will let you ensure the variable is a number. */
const numberSchema = f.Number()

/* A number schema can ensure the value is an Integer. */
const integerSchema = f.Number().int()

/* A number schema can also be used to ensure the number has a minimum and maximum value. */
const minSchema = f.Number().min(5) // Ensures the number is at least 5.
const maxSchema = f.Number().max(5) // Ensures the number is at most 5.

/* A number schema can also be used to ensure the number is a certain type. */
const positiveSchema = f.Number().positive() // Ensures the number is positive.
const negativeSchema = f.Number().negative() // Ensures the number is negative.

/* A number schema can also be used to ensure the integer has a certain parity. */
/* Disclaimer: This requires the schema to have an integer check first! */
const evenSchema = f.Number().even() // Ensures the number is even.
const oddSchema = f.Number().odd() // Ensures the number is odd.

Boolean

import f from 'ts-fuse'

/* A standard Boolean schema will let you ensure the variable is a boolean. */
const booleanSchema = f.Boolean()