1.1.2 • Published 2 years ago

with-with v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

with with

A simple way to use the JavaScript with statement in strict mode!

This is not a sandbox do not use it as a sandbox do not try to make it a sandbox. We will try this and fail so you don't have to.

Installation

Node/Bun

pnpm install with-with

Deno

import withWith from "https://deno.land/x/with/mod.ts";

QuickJS

Cry.

Usage

let accessible = false;
const returnValue = withWith(
	{ hello: "there" },
	({ hello }) => {
		// You can get types via destructuring like `() => ({ hello, etc }) =>`.

		// Logs `there`.
		console.log("hello", hello);

		// Variables from the parent scope are still accessible and can be mutated.
		accessible = true;

		// You can return as well and it will get passed back to the upper scope.
		return hello;
	},
	// This lifter enables your with wrapped function to be able to access all variables from the parent scope.
	{ lifter: (k) => eval(k) }
);
console.log(returnValue, accessible);

Binding

withWith(
	{ hello: "there" },
	function () {
		console.log(this);
	},
	// No variables from the parent scope are accessed, so there's no need for a lifter.
	{ binding: { on: "this" } }
);
1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago