-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
35 lines (35 loc) · 3.01 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
"name": "with",
"version": "3.0.1",
"description": "Compile time `with` for strict mode JavaScript",
"main": "index.js",
"scripts": {
"test": "mocha -R spec"
},
"repository": {
"type": "git",
"url": "https://github.com/ForbesLindesay/with.git"
},
"author": {
"name": "ForbesLindesay"
},
"license": "MIT",
"dependencies": {
"uglify-js": "~2.4.12"
},
"devDependencies": {
"mocha": "~1.12.0"
},
"readme": "# with\r\n\r\nCompile time `with` for strict mode JavaScript\r\n\r\n[![build status](https://secure.travis-ci.org/ForbesLindesay/with.png)](http://travis-ci.org/ForbesLindesay/with)\r\n[![Dependency Status](https://img.shields.io/gemnasium/ForbesLindesay/with.svg)](https://gemnasium.com/ForbesLindesay/with)\r\n[![NPM version](https://img.shields.io/npm/v/with.svg)](http://badge.fury.io/js/with)\r\n\r\n## Installation\r\n\r\n $ npm install with\r\n\r\n## Usage\r\n\r\n```js\r\nvar addWith = require('with')\r\n\r\naddWith('obj', 'console.log(a)')\r\n// => ';(function (console, a) {\r\n// console.log(a)\r\n// }(\"console\" in obj ? obj.console :\r\n// typeof console!==\"undefined\" ? console : undefined,\r\n// \"a\" in obj ? obj.a :\r\n// typeof a !== \"undefined\" ? a : undefined));'\r\n\r\naddWith('obj', 'console.log(a)', ['console'])\r\n// => ';(function (console, a) {\r\n// console.log(a)\r\n// }(\"a\" in obj ? obj.a :\r\n// typeof a !== \"undefined\" ? a : undefined));'\r\n```\r\n\r\n## API\r\n\r\n### addWith(obj, src[, exclude])\r\n\r\nThe idea is that this is roughly equivallent to:\r\n\r\n```js\r\nwith (obj) {\r\n src\r\n}\r\n```\r\n\r\nThere are a few differences though. For starters, assignments to variables will always remain contained within the with block.\r\n\r\ne.g.\r\n\r\n```js\r\nvar foo = 'foo'\r\nwith ({}) {\r\n foo = 'bar'\r\n}\r\nassert(foo === 'bar')// => This fails for compile time with but passes for native with\r\n\r\nvar obj = {foo: 'foo'}\r\nwith ({}) {\r\n foo = 'bar'\r\n}\r\nassert(obj.foo === 'bar')// => This fails for compile time with but passes for native with\r\n```\r\n\r\nIt also makes everything be declared, so you can always do:\r\n\r\n```js\r\nif (foo === undefined)\r\n```\r\n\r\ninstead of\r\n\r\n```js\r\nif (typeof foo === 'undefined')\r\n```\r\n\r\nThis is not the case if foo is in `exclude`. If a variable is excluded, we ignore it entirely. This is useful if you know a variable will be global as it can lead to efficiency improvements.\r\n\r\nIt is also safe to use in strict mode (unlike `with`) and it minifies properly (`with` disables virtually all minification).\r\n\r\n## License\r\n\r\n MIT",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/ForbesLindesay/with/issues"
},
"homepage": "https://github.com/ForbesLindesay/with",
"_id": "with@3.0.1",
"dist": {
"shasum": "a85596be32bcf4666a9f0227f8eec02e08ab41db"
},
"_from": "with@~3.0.0",
"_resolved": "https://registry.npmjs.org/with/-/with-3.0.1.tgz"
}