# localify

> Run code in the scope of an object.

Latest version **1.0.1** (published 2015-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install localify
pnpm add localify
yarn add localify
bun add localify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-04-15 |
| First published | 2015-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | synchronous |
| Maintainers | synchronous |
| Keywords | localify, contextify, local, scope, context |

## Links

- npm: https://www.npmjs.com/package/localify
- Repository: https://github.com/edge/localify
- Issues: https://github.com/edge/localify/issues
- npm.io page: https://npm.io/package/localify

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-04-15
- 1.0.0 — 2015-04-15
- 0.1.3 — 2015-03-07
- 0.1.2 — 2015-03-07
- 0.1.0 — 2015-03-07

## README

# localify

Localify allows you to run arbitrary code with the shallow properties of the object copied into the scope. It can be thought of as a `with` statement that copies the object. It runs very similarly to node's vm module, but works for the browser. This solution is much more efficient than vm-browserify's iframe method.

## VM

Node
```js
var VM = require('localify');
```

Common
```js
var obj = {
	a: 5,
	b: 's',
	c: true,
	d: null,
	e: undefined,
	f: function() {
		console.log(4);
		return 4;
	},
	g: [{
		a: 7,
		b: 8
	}, 6, 7]
};

var vm = new VM(obj);
```

These all do the same thing:
```js
console.log(vm('a'), vm('b'), vm('c'), vm('d'), vm('e'), vm('f()'), vm('g'));

vm('console.log(a, b, c, d, e, f(), g)');

vm(function() {
	console.log(a, b, c, d, e, f(), g);
});

// 4
// 5 's' true null undefined 4 [ { a: 7, b: 8 }, 6, 7 ]
// 4
// 5 's' true null undefined 4 [ { a: 7, b: 8 }, 6, 7 ]
// 4
// 5 's' true null undefined 4 [ { a: 7, b: 8 }, 6, 7 ]
```

## Legacy

This is the legacy version with the previous functionality, which also provides a serialize function, similar to JSON.stringify, but also parses functions.

```js
var local = VM.legacy;
```

## Context

```js
eval(local.context(obj));

console.log(a, b, c, d, e, f(), g);

// 4
// 5 's' true null undefined 4 [ { a: 7, b: 8 }, 6, 7 ]
```

## Serialize

```js
console.log(local.serialize(obj));

//{a:5,b:"s",c:true,d:null,e:undefined,f:function () {
//		console.log(4);
//		return 4;
//	},g:[{a:7,b:8,},6,7,],}
```

---
_Source: https://npm.io/package/localify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
