Template Upload

This commit is contained in:
SOUTHERNCO\x2mjbyrn
2017-05-17 13:45:25 -04:00
parent 415b9c25f3
commit 7efe7605b8
11476 changed files with 2170865 additions and 34 deletions

1
node_modules/generate-function/.npmignore generated vendored Normal file
View File

@ -0,0 +1 @@
node_modules

3
node_modules/generate-function/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"

72
node_modules/generate-function/README.md generated vendored Normal file
View File

@ -0,0 +1,72 @@
# generate-function
Module that helps you write generated functions in Node
```
npm install generate-function
```
[![build status](http://img.shields.io/travis/mafintosh/generate-function.svg?style=flat)](http://travis-ci.org/mafintosh/generate-function)
## Disclamer
Writing code that generates code is hard.
You should only use this if you really, really, really need this for performance reasons (like schema validators / parsers etc).
## Usage
``` js
var genfun = require('generate-function')
var addNumber = function(val) {
var fn = genfun()
('function add(n) {')
('return n + %d', val) // supports format strings to insert values
('}')
return fn.toFunction() // will compile the function
}
var add2 = addNumber(2)
console.log('1+2=', add2(1))
console.log(add2.toString()) // prints the generated function
```
If you need to close over variables in your generated function pass them to `toFunction(scope)`
``` js
var multiply = function(a, b) {
return a * b
}
var addAndMultiplyNumber = function(val) {
var fn = genfun()
('function(n) {')
('if (typeof n !== "number") {') // ending a line with { will indent the source
('throw new Error("argument should be a number")')
('}')
('var result = multiply(%d, n+%d)', val, val)
('return result')
('}')
// use fn.toString() if you want to see the generated source
return fn.toFunction({
multiply: multiply
})
}
var addAndMultiply2 = addAndMultiplyNumber(2)
console.log('(3 + 2) * 2 =', addAndMultiply2(3))
```
## Related
See [generate-object-property](https://github.com/mafintosh/generate-object-property) if you need to safely generate code that
can be used to reference an object property
## License
MIT

27
node_modules/generate-function/example.js generated vendored Normal file
View File

@ -0,0 +1,27 @@
var genfun = require('./')
var multiply = function(a, b) {
return a * b
}
var addAndMultiplyNumber = function(val) {
var fn = genfun()
('function(n) {')
('if (typeof n !== "number") {') // ending a line with { will indent the source
('throw new Error("argument should be a number")')
('}')
('var result = multiply(%d, n+%d)', val, val)
('return result')
('}')
// use fn.toString() if you want to see the generated source
return fn.toFunction({
multiply: multiply
})
}
var addAndMultiply2 = addAndMultiplyNumber(2)
console.log(addAndMultiply2.toString())
console.log('(3 + 2) * 2 =', addAndMultiply2(3))

61
node_modules/generate-function/index.js generated vendored Normal file
View File

@ -0,0 +1,61 @@
var util = require('util')
var INDENT_START = /[\{\[]/
var INDENT_END = /[\}\]]/
module.exports = function() {
var lines = []
var indent = 0
var push = function(str) {
var spaces = ''
while (spaces.length < indent*2) spaces += ' '
lines.push(spaces+str)
}
var line = function(fmt) {
if (!fmt) return line
if (INDENT_END.test(fmt.trim()[0]) && INDENT_START.test(fmt[fmt.length-1])) {
indent--
push(util.format.apply(util, arguments))
indent++
return line
}
if (INDENT_START.test(fmt[fmt.length-1])) {
push(util.format.apply(util, arguments))
indent++
return line
}
if (INDENT_END.test(fmt.trim()[0])) {
indent--
push(util.format.apply(util, arguments))
return line
}
push(util.format.apply(util, arguments))
return line
}
line.toString = function() {
return lines.join('\n')
}
line.toFunction = function(scope) {
var src = 'return ('+line.toString()+')'
var keys = Object.keys(scope || {}).map(function(key) {
return key
})
var vals = keys.map(function(key) {
return scope[key]
})
return Function.apply(null, keys.concat(src)).apply(null, vals)
}
if (arguments.length) line.apply(null, arguments)
return line
}

78
node_modules/generate-function/package.json generated vendored Normal file
View File

@ -0,0 +1,78 @@
{
"_args": [
[
"generate-function@^2.0.0",
"C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\is-my-json-valid"
]
],
"_from": "generate-function@>=2.0.0-0 <3.0.0-0",
"_id": "generate-function@2.0.0",
"_inCache": true,
"_location": "/generate-function",
"_npmUser": {
"email": "mathiasbuus@gmail.com",
"name": "mafintosh"
},
"_npmVersion": "1.4.23",
"_phantomChildren": {},
"_requested": {
"name": "generate-function",
"raw": "generate-function@^2.0.0",
"rawSpec": "^2.0.0",
"scope": null,
"spec": ">=2.0.0-0 <3.0.0-0",
"type": "range"
},
"_requiredBy": [
"/is-my-json-valid"
],
"_resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz",
"_shasum": "6858fe7c0969b7d4e9093337647ac79f60dfbe74",
"_shrinkwrap": null,
"_spec": "generate-function@^2.0.0",
"_where": "C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\is-my-json-valid",
"author": {
"name": "Mathias Buus"
},
"bugs": {
"url": "https://github.com/mafintosh/generate-function/issues"
},
"dependencies": {},
"description": "Module that helps you write generated functions in Node",
"devDependencies": {
"tape": "^2.13.4"
},
"directories": {},
"dist": {
"shasum": "6858fe7c0969b7d4e9093337647ac79f60dfbe74",
"tarball": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz"
},
"gitHead": "3d5fc8de5859be95f58e3af9bfb5f663edd95149",
"homepage": "https://github.com/mafintosh/generate-function",
"installable": true,
"keywords": [
"code",
"function",
"generate",
"generation",
"performance"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "mafintosh",
"email": "mathiasbuus@gmail.com"
}
],
"name": "generate-function",
"optionalDependencies": {},
"repository": {
"type": "git",
"url": "https://github.com/mafintosh/generate-function"
},
"scripts": {
"test": "tape test.js"
},
"version": "2.0.0"
}

33
node_modules/generate-function/test.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
var tape = require('tape')
var genfun = require('./')
tape('generate add function', function(t) {
var fn = genfun()
('function add(n) {')
('return n + %d', 42)
('}')
t.same(fn.toString(), 'function add(n) {\n return n + 42\n}', 'code is indented')
t.same(fn.toFunction()(10), 52, 'function works')
t.end()
})
tape('generate function + closed variables', function(t) {
var fn = genfun()
('function add(n) {')
('return n + %d + number', 42)
('}')
var notGood = fn.toFunction()
var good = fn.toFunction({number:10})
try {
notGood(10)
t.ok(false, 'function should not work')
} catch (err) {
t.same(err.message, 'number is not defined', 'throws reference error')
}
t.same(good(11), 63, 'function with closed var works')
t.end()
})