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

ts-boxed

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-boxed

Like Scheme boxes but for TypeScript

latest
Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

ts-boxed

Like Scheme's boxes but for TypeScript.

unbox(box(myObj)) === myObj

Why

Why do you need this? You probably don't. If you've ever wanted JS to have pointers to pointers or out parameters, boxes can help.

Installing

npm i ts-boxed

Basic Usage

Boxes are mutable references to a single value.

import { box, unbox, setBox$ } from 'ts-boxed';

// Unboxing gets the original value (reference equality)...
const myObj = {};
unbox(box(myObj)) === myObj;

// without mutating the box.
const myBox = box('contents');
unbox(myBox) === 'contents';
unbox(myBox) === 'contents'; // still true

// Like Scheme, the setter has scary punctuation (too bad `set-box!` isn't a valid JS identifier).
setBox$(myBox, '2');
unbox(myBox) === '2';
setBox$(myBox, '3');
unbox(myBox) === '3';

Types

isBox is a runtime check but also provides type information to TypeScript.

  function f(maybeBox: unknown) {
    if (isBox(maybeBox)) {
      // maybeBox now has type `Box<unknown>`
      unbox(maybeBox);
    } else {
      // @ts-ignore maybeBox still has type `unknown`
      unbox(maybeBox);
    }
  }

Keywords

TypeScript

FAQs

Package last updated on 10 Oct 2020

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