Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
add test, fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jed committed Sep 27, 2011
1 parent 001ef2e commit a9981a9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
41 changes: 40 additions & 1 deletion README.md
Expand Up @@ -31,11 +31,50 @@ this.document.body.appendChild(this.document.createElement('script'))
and turn it into code like this:

```javascript
this[fk][rz][cr](this[fk][b0]('script'))
this[fk][eq][cr](this[fk][e5]('script'))
```

This is most effective when used with something like [@aivopaas](http://twitter.com/aivopaas)'s [jscrush](http://www.iteral.com/jscrush/).

Example
-------

(Note that that this is a contrived example that actually increates code size. Since Namedrop adds more than 100 bytes of overhead, it works best on DOM-heavy code of several hundred bytes or more.)

### before.js

```javascript
this.document.body.appendChild(this.document.createElement('script'))
```

### test.js

```javascript
fs = require("fs")
namedrop = require("namedrop")

before = fs.readFileSync("./before.js", "utf8")
namedrop = require("namedrop")

refs = [
"this",
"this.document",
"this.document.documentElement"
]

namedrop(before, refs, function(err, code) {
if (err) throw err

else fs.writeFileSync("./after.js", code)
})
```

### after.js

```javascript
with(n=function(a,b,c,d){for(b in a){for(c=a=0;d=b.charCodeAt(c++);a%=934)a+=c*d;n[(a+360).toString(36)]=b}}){n(this);n(this[fk]);n(this[fk][o3]);this[fk][eq][cr](this[fk][e5]('script'))}
```

Copyright
---------

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -29,7 +29,7 @@ if (typeof phantom === "undefined") {
.replace(RegExp("\\." + n[key] + "\\b", "g"), "[" + key + "]")
.replace(RegExp("'" + n[key] + "'" , "g"), "'" + key + "'")

code = "n=function(a,b,c,d){for(b in a){for(c=a=0;d=b.charCodeAt(c++);a%=934)a+=c*d;n[(a+360).toString(36)]=b}});" + code
code = "with(n=function(a,b,c,d){for(b in a){for(c=a=0;d=b.charCodeAt(c++);a%=934)a+=c*d;n[(a+360).toString(36)]=b}}){" + code +"}"

cb(null, code)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Jed Schmidt <tr@nslator.jp> (http://jed.is)",
"name": "namedrop",
"description": "Minification for DOM-heavy code",
"version": "0.0.0",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "git://github.com/jed/namedrop.git"
Expand Down
1 change: 1 addition & 0 deletions test/after.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/before.js
@@ -0,0 +1 @@
this.document.body.appendChild(this.document.createElement('script'))
17 changes: 17 additions & 0 deletions test/test.js
@@ -0,0 +1,17 @@
fs = require("fs")
namedrop = require("namedrop")

before = fs.readFileSync("./before.js", "utf8")
namedrop = require("namedrop")

refs = [
"this",
"this.document",
"this.document.documentElement"
]

namedrop(before, refs, function(err, code) {
if (err) throw err

else fs.writeFileSync("./after.js", code)
})

0 comments on commit a9981a9

Please sign in to comment.