New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@sthir/number

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sthir/number

Functions and types to work with numbers

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

@sthir/number

npm Babel Macro

Function and types to work with numbers. Currently only includes e and E to facilitate @sthir/predicate's & comparator usage, but will include more functions and types in future.

☝🏻 Note: It requires typescript version 4.8 and higher

e

An eDSL to write numeric-expressions that evaluate compile-time to produce more complete and narrow types.

import * as N from "@sthir/number"

let a: 0b01 = 0b01
let b: 0b10 = 0b10

let c: 0b11 = a | b
// doesn't compile: Type 'number' is not assignable to type '3'.

let d: 0b11 = N.e(`${a} | ${b}`)
// compiles

You can also use the macro version in @sthir/number/macro that uses babel-plugin-macro to transform N.e(\${a} | ${b}`)intoa | b` for zero runtime overhead.

Supported operators are &, |, <<. We can have more operators but currently only these have a compelling use-case for using bitflag predicates with @sthir/predicate. If you have compelling use-cases for other operators feel free to open an issue.

E

Type-level version of e

import * as N from "@sthir/number"

type A = 0b01
type B = 0b10
type C = A | B
// C is `0b01 | 0b10` because `|` is union not bitwise or

type D = N.E<`${A} | ${B}`>
// D is `0b11`

FAQs

Package last updated on 22 Jul 2022

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