New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-opaque-units

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-opaque-units

TypeScript opaque measurement

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ts-opaque-units

minified minified + gzip tree-shaking support coverage

Small TypeScript opaque measurement library

Install

yarn add ts-opaque-units typescript@^4.0.0

Opaque types

For now, only time units are available:

  • Milliseconds
  • Seconds
  • Minutes
  • Hours
  • Days
  • Weeks
  • Months
  • Years
  • Decades
  • Centuries
  • Millenniums

You are not allowed to assign variables of different types, so you are safe ✅

let hours = 1 as Hours;
let twoHours = 2 as Hours;
let minutes = 1 as Minutes;
let twoMinutes = 2 as Minutes;

/* Cannot assign different types */

// @ts-expect-error
hours = minutes;
// @ts-expect-error
minutes = hours;

/** Can assign the same types */

// ✅
minutes = twoMinutes;
hours = twoHours;

Convert

To transform one type to another safely, use a function convert:

import { convert, Minutes, Years } from "ts-opaque-units";

const minutesInHour = 60 as Minutes;
const secondsInHour = convert(minutesInHour, "minutes", "seconds");

const year = 1 as Years;
const secondsInYear = convert(year, "years", "seconds");

Keywords

FAQs

Package last updated on 26 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc