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-extended-types

v1.1.0

Published

Set of complementary basic types related to the ones provided by TypeScript to make your application even more type-safe

Downloads

27,065

Readme

ts-extended-types

npm minified size minified & gziped size

Set of complementary basic types related to the ones provided by TypeScript to make your application even more type-safe

Install

Install with npm:

$ npm install --save ts-extended-types

Basic usage

import {int, stringInt, double, stringDouble, LocalDate, LocalTime, LocalDateTime, uuid } from 'ts-extended-types';

var intNumber: int;
var veryBigInt: stringInt
var doubleNumber: double;
var veryBigDoubleNumber: stringDouble
var localDate: LocalDate;
var localTime: LocalTime;
var localDateTime: LocalDateTime;
var uuidString: uuid;

Type definitions

  • int: type that represents a integer number. It can be assigned to a number, but it cannot be assigned from a number.
  • stringInt: type that represents a integer number. It can be assigned to a number, but it cannot be assigned from a number: it can be so long that can be represented using a string instead of a number.
  • double: type that represents a floating point number with double precision. It can be assigned to a number, but it cannot be assigned from a number.
  • stringDouble: type that represents a floating point number with double precision; it can be so long that can be represented using a string instead of a number.
  • LocalDate: type that represents a local date without time (without timezone). Provided methods:
    • getFullYear(): int: Gets the year
    • getMonth(): int: Gets the month (value between 0 to 11)
    • getDate(): int: Gets the day-of-the-month
    • getDay(): int: Gets the day of the week (0 represents Sunday)
  • LocalTime: type that represents a local time without date (without timezone). Provided methods:
    • getHours(): int: Gets the hours
    • getMinutes(): int: Gets the minutes
    • getSeconds(): int: Gets the seconds
    • getMilliseconds(): int: Gets the milliseconds
  • LocalDateTime: type that represents a local date with time (without timezone). Provided methods: all methods provided by LocalDate and LocalTime plus:
    • getTime(): int: Gets the time value in milliseconds
  • uuid: type that represents an uuid string. It can be assigned to a string, but it cannot be assigned from a string.

Note:

  • In JavaScript int or double don't exists, all of these values are represented using a number.
  • In JavaScript stringInt or stringDouble don't exists, all of these values are represented using a number or a string.
  • In JavaScript LocalDate, LocalTime or LocalDateTime don't exists, all of these values are represented using the Date object.
  • In JavaScript uuid don't exists, this value is represented using a string.

Provided functions

Provided int functions

  • isInt(value: any) => value is int: Returns true if the value is a int number, otherwise returns false.
  • asInt(value: number) => int: Cast the number provided by argument as int, throws an error if the provided number is not an integer.
  • roundToInt(value: number) => int: Round the provided number to an integer and then cast it to int.
  • truncateToInt(value: number) => int: Truncate the provided number to an integer and then cast it to int.
  • floorToInt(value: number) => int: Floor the provided number to an integer and then cast it to int.
  • ceilToInt(value: number) => int: Ceil the provided number to an integer and then cast it to int.

Provided stringInt functions

  • isStringInt(value: any) => value is stringInt: Returns true if the value is a stringInt number, otherwise returns false.
  • asStringInt(value: number|string) => stringInt: Cast the number provided by argument as stringInt, throws an error if the provided number is not an integer.
  • roundToStringInt(value: number) => stringInt: Round the provided number to an integer and then cast it to stringInt.
  • truncateToStringInt(value: number) => stringInt: Truncate the provided number to an integer and then cast it to stringInt.
  • floorToStringInt(value: number) => stringInt: Floor the provided number to an integer and then cast it to stringInt.
  • ceilToStringInt(value: number) => stringInt: Ceil the provided number to an integer and then cast it to stringInt.

Provided double functions

  • isDouble(value: any) => value is double: Returns true if the value is a double precision number, otherwise returns false.
  • asDouble(value: number) => double: Cast the number provided by argument as double.

Provided stringDouble functions

  • isStringDouble(value: any) => value is stringDouble: Returns true if the value is a stringDouble precision number, otherwise returns false.
  • asStringDouble(value: number|string) => double: Cast the number provided by argument as stringDouble, throws an error if the provided number is not a double.

Provided LocalDate functions

  • createLocalDate() => LocalDate: create a new LocalDate with the current date.
  • createLocalDate(date: Date) => LocalDate: create a new LocalDate with the same date provided by argument.
  • createLocalDate(year: number, month: number, date: number) => LocalDate: create a new LocalDate with the year, month and date (day of the month) provided by arguments.
  • isLocalDate(value: any) => value is LocalDate: Returns true if the value is a LocalDate, otherwise returns false

Provided LocalTime functions

  • createLocalTime() => LocalTime: create a new LocalTime with the current time.
  • createLocalTime(date: Date) => LocalTime: create a new LocalTime with the same time provided by argument.
  • createLocalTime(hours: number, minutes?: number, seconds?: number, milliseconds?: number) => LocalTime: create a new LocalTime with the hours, minutes, seconds and milliseconds provided by arguments.
  • isLocalTime(value: any) => value is LocalTime: Returns true if the value is a LocalTime, otherwise returns false

Provided LocalDateTime functions

  • createLocalDateTime() => LocalDateTime: create a new LocalDate with the current date and time.
  • createLocalDateTime(date: Date) => LocalDateTime: create a new LocalDateTime with the same date and time provided by argument.
  • createLocalDateTime(year: number, month: number, date: number, hours?: number, minutes?: number, seconds?: number, milliseconds?: number) => LocalDateTime: create a new LocalDateTime with the year, month, date (day of the month), hours, minutes, seconds and milliseconds provided by arguments.
  • isLocalDate(value: any) => value is LocalDate: Returns true if the value is a LocalDate, otherwise returns false

Provided uuid functions

  • isUuid(value: any) => value is uuid: Returns true if the value is an uuid string, otherwise returns false.
  • asUuid(value: string) => uuid: Cast the string provided by argument as uuid, throws an error if the provided string is not an uuid.

License

MIT