You've already forked wakapi-readme-stats
Bar graph added.
This commit is contained in:
27
node_modules/vega-expression/LICENSE
generated
vendored
Normal file
27
node_modules/vega-expression/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2015-2018, University of Washington Interactive Data Lab
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
146
node_modules/vega-expression/README.md
generated
vendored
Normal file
146
node_modules/vega-expression/README.md
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
# vega-expression
|
||||
|
||||
[Vega](https://github.com/vega/vega) expression parser and code generator.
|
||||
|
||||
Parses a limited subset of JavaScript expressions into an abstract syntax tree, and provides code generation utilities for generating `eval`'able output code. The parser recognizes basic JavaScript expressions, but does not allow assignment operators, `new` expressions, or control flow statements (`for`, `while`, `switch`, etc). The configurable code generator further limits the set of allowable function invocations and variable names. The goal is to provide simple, expressive, and security-conscious expression evaluation.
|
||||
|
||||
See the [Vega expression language documentation](https://vega.github.io/vega/docs/expressions/) for more details about supported JavaScript expressions, and see below for the constants and functions provided by this package. All other functions are provided by the [vega-functions](https://github.com/vega/vega/blob/master/packages/vega-functions/) package.
|
||||
|
||||
## API Reference
|
||||
|
||||
<a name="parse" href="#parse">#</a>
|
||||
<b>parse</b>(<i>expression</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-expression/src/parser.js "Source")
|
||||
|
||||
Parse the JavaScript *expression* string and return the resulting abstract syntax tree in the [ESTree format](https://github.com/estree/estree). The parser is a stripped-down version of the [Esprima](http://esprima.org/) parser.
|
||||
|
||||
<a name="codegen" href="#codegen">#</a>
|
||||
<b>codegen</b>(<i>options</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-expression/src/codegen.js "Source")
|
||||
|
||||
Create a new output code generator configured according to the provided options. The resulting generator function accepts a parsed AST as input and returns `eval`'able JavaScript code as output. The output is an object hash with the properties `code` (the generated code as a string), `fields` (a hash of all properties referenced within the _fieldvar_ scope), and `globals` (a hash of all properties referenced outside a provided whitelist).
|
||||
|
||||
The supported _options_ include:
|
||||
|
||||
- *constants*: A hash of allowed top-level constant values. This object maps from constant names to constant values. The constant values are strings that will be injected as-is into generated code. If this option is not specified, the [constants](#constants) object is used by default.
|
||||
|
||||
- *functions*: A function that is given an AST visitor instance as input and returns an object of allowed functions. The resulting object maps from
|
||||
function names to function values. The values may either be strings (which will be injected as-is into generated code and subsequently appended with arguments) or functions (which take an array of argument AST nodes as input and return generated code to inject). If this option is not specified, the [functions](#functions) method is used by default.
|
||||
|
||||
- *blacklist*: An array of variable names that may **not** be referenced within the expression scope. These may correspond to disallowed global variables.
|
||||
|
||||
- *whitelist*: An array of variable names that may be referenced within the expression scope. These typically correspond to function parameter names for the expression. Variable names not included in the white list will be collected as global variables (see *globalvar* below).
|
||||
|
||||
- *fieldvar*: The name of the primary data input argument within the generated expression function. For example, in the function `function(d) { return d.x * d.y; }`, the variable `d` serves as the field variable, and `x` and `y` are it's accessed properties. All properties accessed under the scope of _fieldvar_ will be tracked by the code generator and returned as part of the output. This is necessary to perform dependency tracking of referenced data fields.
|
||||
|
||||
- *globalvar*: (Required) The name of the variable upon which to lookup global variables. This variable name will be included in the generated code as the scope for any global variable references. Alternatively, this property can be a function that maps from variable names in the source input to generated code to write to the output.
|
||||
|
||||
<a name="constants" href="#constants">#</a>
|
||||
<b>constants</b>(<i>codegen</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-expression/src/constants.js "Source")
|
||||
|
||||
An object defining default constant values for the Vega expression language. The object maps from constant identifiers to JavaScript code to defining the constant value (for example, `'PI'` maps to `'Math.PI`').
|
||||
|
||||
<a name="functions" href="#functions">#</a>
|
||||
<b>functions</b>(<i>codegen</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-expression/src/functions.js "Source")
|
||||
|
||||
Given a *codegen* instance (generated by the [codegen](#codegen) method) as input, returns an object defining all valid function names for use within an expression. The resulting object maps from function names to function values. The values may either be strings (which will be injected as-is into generated code and subsequently appended with arguments) or functions (which take an array of argument AST nodes as input and return generated code to inject).
|
||||
|
||||
<a name="ASTNode" href="#ASTNode">#</a>
|
||||
<b>ASTNode</b>(<i>type</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-expression/src/ast.js "Source")
|
||||
|
||||
Constructor for a node in an expression abstract syntax tree (AST). Accepts a *type* string as input, which then become the `type` property of the resulting node. AST nodes also support a `visit` method which takes a visitor function as input in order to traverse the AST for static analysis.
|
||||
|
||||
## Provided Constants and Functions
|
||||
|
||||
This package provides the following constants and functions:
|
||||
|
||||
**Constants**
|
||||
|
||||
- [`NaN`](https://vega.github.io/vega/docs/expressions/#NaN)
|
||||
- [`E`](https://vega.github.io/vega/docs/expressions/#E)
|
||||
- [`LN2`](https://vega.github.io/vega/docs/expressions/#LN2)
|
||||
- [`LN10`](https://vega.github.io/vega/docs/expressions/#LN10)
|
||||
- [`LOG2E`](https://vega.github.io/vega/docs/expressions/#LOG2E)
|
||||
- [`LOG10E`](https://vega.github.io/vega/docs/expressions/#LOG10E)
|
||||
- [`PI`](https://vega.github.io/vega/docs/expressions/#PI)
|
||||
- [`SQRT1_2`](https://vega.github.io/vega/docs/expressions/#SQRT1_2)
|
||||
- [`SQRT2`](https://vega.github.io/vega/docs/expressions/#SQRT2)
|
||||
- [`MIN_VALUE`](https://vega.github.io/vega/docs/expressions/#MIN_VALUE)
|
||||
- [`MAX_VALUE`](https://vega.github.io/vega/docs/expressions/#MAX_VALUE)
|
||||
|
||||
**Math Functions**
|
||||
|
||||
- [`isNaN`](https://vega.github.io/vega/docs/expressions/#isNaN)
|
||||
- [`isFinite`](https://vega.github.io/vega/docs/expressions/#isFinite)
|
||||
- [`abs`](https://vega.github.io/vega/docs/expressions/#abs)
|
||||
- [`acos`](https://vega.github.io/vega/docs/expressions/#acos)
|
||||
- [`asin`](https://vega.github.io/vega/docs/expressions/#asin)
|
||||
- [`atan`](https://vega.github.io/vega/docs/expressions/#atan)
|
||||
- [`atan2`](https://vega.github.io/vega/docs/expressions/#atan2)
|
||||
- [`ceil`](https://vega.github.io/vega/docs/expressions/#ceil)
|
||||
- [`cos`](https://vega.github.io/vega/docs/expressions/#cos)
|
||||
- [`exp`](https://vega.github.io/vega/docs/expressions/#exp)
|
||||
- [`floor`](https://vega.github.io/vega/docs/expressions/#floor)
|
||||
- [`log`](https://vega.github.io/vega/docs/expressions/#log)
|
||||
- [`max`](https://vega.github.io/vega/docs/expressions/#max)
|
||||
- [`min`](https://vega.github.io/vega/docs/expressions/#min)
|
||||
- [`pow`](https://vega.github.io/vega/docs/expressions/#pow)
|
||||
- [`random`](https://vega.github.io/vega/docs/expressions/#random)
|
||||
- [`round`](https://vega.github.io/vega/docs/expressions/#round)
|
||||
- [`sin`](https://vega.github.io/vega/docs/expressions/#sin)
|
||||
- [`sqrt`](https://vega.github.io/vega/docs/expressions/#sqrt)
|
||||
- [`tan`](https://vega.github.io/vega/docs/expressions/#tan)
|
||||
- [`clamp`](https://vega.github.io/vega/docs/expressions/#clamp)
|
||||
|
||||
**Date/Time Functions**
|
||||
|
||||
- [`now`](https://vega.github.io/vega/docs/expressions/#now)
|
||||
- [`utc`](https://vega.github.io/vega/docs/expressions/#utc)
|
||||
- [`datetime`](https://vega.github.io/vega/docs/expressions/#datetime)
|
||||
- [`date`](https://vega.github.io/vega/docs/expressions/#date)
|
||||
- [`day`](https://vega.github.io/vega/docs/expressions/#day)
|
||||
- [`year`](https://vega.github.io/vega/docs/expressions/#year)
|
||||
- [`month`](https://vega.github.io/vega/docs/expressions/#month)
|
||||
- [`hours`](https://vega.github.io/vega/docs/expressions/#hours)
|
||||
- [`minutes`](https://vega.github.io/vega/docs/expressions/#minutes)
|
||||
- [`seconds`](https://vega.github.io/vega/docs/expressions/#seconds)
|
||||
- [`milliseconds`](https://vega.github.io/vega/docs/expressions/#milliseconds)
|
||||
- [`time`](https://vega.github.io/vega/docs/expressions/#time)
|
||||
- [`timezoneoffset`](https://vega.github.io/vega/docs/expressions/#timezoneoffset)
|
||||
- [`utcdate`](https://vega.github.io/vega/docs/expressions/#utcdate)
|
||||
- [`utcday`](https://vega.github.io/vega/docs/expressions/#utcday)
|
||||
- [`utcyear`](https://vega.github.io/vega/docs/expressions/#utcyear)
|
||||
- [`utcmonth`](https://vega.github.io/vega/docs/expressions/#utcmonth)
|
||||
- [`utchours`](https://vega.github.io/vega/docs/expressions/#utchours)
|
||||
- [`utcminutes`](https://vega.github.io/vega/docs/expressions/#utcminutes)
|
||||
- [`utcseconds`](https://vega.github.io/vega/docs/expressions/#utcseconds)
|
||||
- [`utcmilliseconds`](https://vega.github.io/vega/docs/expressions/#utcmilliseconds)
|
||||
|
||||
**Sequence (Array or String) Functions**
|
||||
|
||||
- [`length`](https://vega.github.io/vega/docs/expressions/#length)
|
||||
- [`join`](https://vega.github.io/vega/docs/expressions/#join)
|
||||
- [`indexof`](https://vega.github.io/vega/docs/expressions/#indexof)
|
||||
- [`lastindexof`](https://vega.github.io/vega/docs/expressions/#lastindexof)
|
||||
- [`reverse`](https://vega.github.io/vega/docs/expressions/#reverse)
|
||||
- [`slice`](https://vega.github.io/vega/docs/expressions/#slice)
|
||||
|
||||
**String Functions**
|
||||
|
||||
- [`parseFloat`](https://vega.github.io/vega/docs/expressions/#parseFloat)
|
||||
- [`parseInt`](https://vega.github.io/vega/docs/expressions/#parseInt)
|
||||
- [`upper`](https://vega.github.io/vega/docs/expressions/#upper)
|
||||
- [`lower`](https://vega.github.io/vega/docs/expressions/#lower)
|
||||
- [`replace`](https://vega.github.io/vega/docs/expressions/#replace)
|
||||
- [`split`](https://vega.github.io/vega/docs/expressions/#split)
|
||||
- [`substring`](https://vega.github.io/vega/docs/expressions/#substring)
|
||||
- [`trim`](https://vega.github.io/vega/docs/expressions/#trim)
|
||||
|
||||
**RegExp Functions**
|
||||
|
||||
- [`regexp`](https://vega.github.io/vega/docs/expressions/#regexp)
|
||||
- [`test`](https://vega.github.io/vega/docs/expressions/#test)
|
||||
|
||||
1837
node_modules/vega-expression/build/vega-expression.js
generated
vendored
Normal file
1837
node_modules/vega-expression/build/vega-expression.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/vega-expression/build/vega-expression.min.js
generated
vendored
Normal file
1
node_modules/vega-expression/build/vega-expression.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
21
node_modules/vega-expression/index.d.ts
generated
vendored
Normal file
21
node_modules/vega-expression/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// TODO: add missing types
|
||||
|
||||
export function parse(expression: string): any;
|
||||
|
||||
export function codegen(params: {
|
||||
constants?: object;
|
||||
functions?: { [fn: string]: Function };
|
||||
blacklist?: string[];
|
||||
whitelist?: string[];
|
||||
fieldvar?: string;
|
||||
globalvar: string;
|
||||
}): (
|
||||
ast: any
|
||||
) => {
|
||||
/** The generated code as a string. */
|
||||
code: string;
|
||||
/** A hash of all properties referenced within the fieldvar scope. */
|
||||
fields: string[];
|
||||
/** A hash of all properties referenced outside a provided whitelist */
|
||||
globals: string[];
|
||||
};
|
||||
20
node_modules/vega-expression/index.js
generated
vendored
Normal file
20
node_modules/vega-expression/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
export {
|
||||
RawCode,
|
||||
Literal,
|
||||
Property,
|
||||
Identifier,
|
||||
ArrayExpression,
|
||||
BinaryExpression,
|
||||
CallExpression,
|
||||
ConditionalExpression,
|
||||
LogicalExpression,
|
||||
MemberExpression,
|
||||
ObjectExpression,
|
||||
UnaryExpression,
|
||||
default as ASTNode
|
||||
} from './src/ast';
|
||||
|
||||
export { default as parse} from './src/parser';
|
||||
export { default as codegen } from './src/codegen';
|
||||
export { default as functions } from './src/functions';
|
||||
export { default as constants } from './src/constants';
|
||||
69
node_modules/vega-expression/package.json
generated
vendored
Normal file
69
node_modules/vega-expression/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "vega-expression@~2.6.5",
|
||||
"_id": "vega-expression@2.6.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-3hJts0gKomu3ePXYeIb+VAw7yNKoHJ6VqSKsHHFPyoEGNdwmlgI5d9IBblelPCiMCHK4sMt7h1OTWB33cfxZGA==",
|
||||
"_location": "/vega-expression",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "vega-expression@~2.6.5",
|
||||
"name": "vega-expression",
|
||||
"escapedName": "vega-expression",
|
||||
"rawSpec": "~2.6.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~2.6.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vega",
|
||||
"/vega-functions",
|
||||
"/vega-lite",
|
||||
"/vega-selections"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/vega-expression/-/vega-expression-2.6.5.tgz",
|
||||
"_shasum": "7bda7524b9223cbbf9034071695c7c2a9bd81971",
|
||||
"_spec": "vega-expression@~2.6.5",
|
||||
"_where": "/home/prabhatdev/Documents/opensource/gitHubStats/waka-readme-stats/node_modules/vega",
|
||||
"author": {
|
||||
"name": "Jeffrey Heer",
|
||||
"url": "http://idl.cs.washington.edu"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vega/vega/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"vega-util": "^1.14.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Vega expression parser and code generator.",
|
||||
"gitHead": "48c85218f2202242171aa569f2dca0f53cf2b51f",
|
||||
"homepage": "https://github.com/vega/vega#readme",
|
||||
"keywords": [
|
||||
"vega",
|
||||
"expression",
|
||||
"parser",
|
||||
"codegen"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "build/vega-expression.js",
|
||||
"module": "index",
|
||||
"name": "vega-expression",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vega/vega.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn rollup",
|
||||
"postbuild": "terser build/vega-expression.js -c -m -o build/vega-expression.min.js",
|
||||
"postpublish": "git push && git push --tags",
|
||||
"prebuild": "rimraf build && mkdir build",
|
||||
"prepublishOnly": "yarn test && yarn build",
|
||||
"pretest": "yarn prebuild && yarn rollup",
|
||||
"rollup": "rollup -f umd -g vega-util:vega -n vega -o build/vega-expression.js -- index.js",
|
||||
"test": "tape 'test/**/*-test.js'"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"version": "2.6.5"
|
||||
}
|
||||
56
node_modules/vega-expression/src/ast.js
generated
vendored
Normal file
56
node_modules/vega-expression/src/ast.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
export var RawCode = 'RawCode';
|
||||
export var Literal = 'Literal';
|
||||
export var Property = 'Property';
|
||||
export var Identifier = 'Identifier';
|
||||
|
||||
export var ArrayExpression = 'ArrayExpression';
|
||||
export var BinaryExpression = 'BinaryExpression';
|
||||
export var CallExpression = 'CallExpression';
|
||||
export var ConditionalExpression = 'ConditionalExpression';
|
||||
export var LogicalExpression = 'LogicalExpression';
|
||||
export var MemberExpression = 'MemberExpression';
|
||||
export var ObjectExpression = 'ObjectExpression';
|
||||
export var UnaryExpression = 'UnaryExpression';
|
||||
|
||||
export default function ASTNode(type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
ASTNode.prototype.visit = function(visitor) {
|
||||
var node = this, c, i, n;
|
||||
|
||||
if (visitor(node)) return 1;
|
||||
|
||||
for (c=children(node), i=0, n=c.length; i<n; ++i) {
|
||||
if (c[i].visit(visitor)) return 1;
|
||||
}
|
||||
};
|
||||
|
||||
function children(node) {
|
||||
switch (node.type) {
|
||||
case ArrayExpression:
|
||||
return node.elements;
|
||||
case BinaryExpression:
|
||||
case LogicalExpression:
|
||||
return [node.left, node.right];
|
||||
case CallExpression:
|
||||
var args = node.arguments.slice();
|
||||
args.unshift(node.callee);
|
||||
return args;
|
||||
case ConditionalExpression:
|
||||
return [node.test, node.consequent, node.alternate];
|
||||
case MemberExpression:
|
||||
return [node.object, node.property];
|
||||
case ObjectExpression:
|
||||
return node.properties;
|
||||
case Property:
|
||||
return [node.key, node.value];
|
||||
case UnaryExpression:
|
||||
return [node.argument];
|
||||
case Identifier:
|
||||
case Literal:
|
||||
case RawCode:
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
134
node_modules/vega-expression/src/codegen.js
generated
vendored
Normal file
134
node_modules/vega-expression/src/codegen.js
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
import Constants from './constants';
|
||||
import Functions from './functions';
|
||||
import {error, hasOwnProperty, isFunction, isString, toSet} from 'vega-util';
|
||||
|
||||
function stripQuotes(s) {
|
||||
var n = s && s.length - 1;
|
||||
return n && (
|
||||
(s[0]==='"' && s[n]==='"') ||
|
||||
(s[0]==='\'' && s[n]==='\'')
|
||||
) ? s.slice(1, -1) : s;
|
||||
}
|
||||
|
||||
export default function(opt) {
|
||||
opt = opt || {};
|
||||
|
||||
var whitelist = opt.whitelist ? toSet(opt.whitelist) : {},
|
||||
blacklist = opt.blacklist ? toSet(opt.blacklist) : {},
|
||||
constants = opt.constants || Constants,
|
||||
functions = (opt.functions || Functions)(visit),
|
||||
globalvar = opt.globalvar,
|
||||
fieldvar = opt.fieldvar,
|
||||
globals = {},
|
||||
fields = {},
|
||||
memberDepth = 0;
|
||||
|
||||
var outputGlobal = isFunction(globalvar)
|
||||
? globalvar
|
||||
: function (id) { return globalvar + '["' + id + '"]'; };
|
||||
|
||||
function visit(ast) {
|
||||
if (isString(ast)) return ast;
|
||||
var generator = Generators[ast.type];
|
||||
if (generator == null) error('Unsupported type: ' + ast.type);
|
||||
return generator(ast);
|
||||
}
|
||||
|
||||
var Generators = {
|
||||
Literal: function(n) {
|
||||
return n.raw;
|
||||
},
|
||||
|
||||
Identifier: function(n) {
|
||||
var id = n.name;
|
||||
if (memberDepth > 0) {
|
||||
return id;
|
||||
} else if (hasOwnProperty(blacklist, id)) {
|
||||
return error('Illegal identifier: ' + id);
|
||||
} else if (hasOwnProperty(constants, id)) {
|
||||
return constants[id];
|
||||
} else if (hasOwnProperty(whitelist, id)) {
|
||||
return id;
|
||||
} else {
|
||||
globals[id] = 1;
|
||||
return outputGlobal(id);
|
||||
}
|
||||
},
|
||||
|
||||
MemberExpression: function(n) {
|
||||
var d = !n.computed;
|
||||
var o = visit(n.object);
|
||||
if (d) memberDepth += 1;
|
||||
var p = visit(n.property);
|
||||
if (o === fieldvar) {
|
||||
// strip quotes to sanitize field name (#1653)
|
||||
fields[stripQuotes(p)] = 1;
|
||||
}
|
||||
if (d) memberDepth -= 1;
|
||||
return o + (d ? '.'+p : '['+p+']');
|
||||
},
|
||||
|
||||
CallExpression: function(n) {
|
||||
if (n.callee.type !== 'Identifier') {
|
||||
error('Illegal callee type: ' + n.callee.type);
|
||||
}
|
||||
var callee = n.callee.name;
|
||||
var args = n.arguments;
|
||||
var fn = hasOwnProperty(functions, callee) && functions[callee];
|
||||
if (!fn) error('Unrecognized function: ' + callee);
|
||||
return isFunction(fn)
|
||||
? fn(args)
|
||||
: fn + '(' + args.map(visit).join(',') + ')';
|
||||
},
|
||||
|
||||
ArrayExpression: function(n) {
|
||||
return '[' + n.elements.map(visit).join(',') + ']';
|
||||
},
|
||||
|
||||
BinaryExpression: function(n) {
|
||||
return '(' + visit(n.left) + n.operator + visit(n.right) + ')';
|
||||
},
|
||||
|
||||
UnaryExpression: function(n) {
|
||||
return '(' + n.operator + visit(n.argument) + ')';
|
||||
},
|
||||
|
||||
ConditionalExpression: function(n) {
|
||||
return '(' + visit(n.test) +
|
||||
'?' + visit(n.consequent) +
|
||||
':' + visit(n.alternate) +
|
||||
')';
|
||||
},
|
||||
|
||||
LogicalExpression: function(n) {
|
||||
return '(' + visit(n.left) + n.operator + visit(n.right) + ')';
|
||||
},
|
||||
|
||||
ObjectExpression: function(n) {
|
||||
return '{' + n.properties.map(visit).join(',') + '}';
|
||||
},
|
||||
|
||||
Property: function(n) {
|
||||
memberDepth += 1;
|
||||
var k = visit(n.key);
|
||||
memberDepth -= 1;
|
||||
return k + ':' + visit(n.value);
|
||||
}
|
||||
};
|
||||
|
||||
function codegen(ast) {
|
||||
var result = {
|
||||
code: visit(ast),
|
||||
globals: Object.keys(globals),
|
||||
fields: Object.keys(fields)
|
||||
};
|
||||
globals = {};
|
||||
fields = {};
|
||||
return result;
|
||||
}
|
||||
|
||||
codegen.functions = functions;
|
||||
codegen.constants = constants;
|
||||
|
||||
return codegen;
|
||||
}
|
||||
13
node_modules/vega-expression/src/constants.js
generated
vendored
Normal file
13
node_modules/vega-expression/src/constants.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export default {
|
||||
NaN: 'NaN',
|
||||
E: 'Math.E',
|
||||
LN2: 'Math.LN2',
|
||||
LN10: 'Math.LN10',
|
||||
LOG2E: 'Math.LOG2E',
|
||||
LOG10E: 'Math.LOG10E',
|
||||
PI: 'Math.PI',
|
||||
SQRT1_2: 'Math.SQRT1_2',
|
||||
SQRT2: 'Math.SQRT2',
|
||||
MIN_VALUE: 'Number.MIN_VALUE',
|
||||
MAX_VALUE: 'Number.MAX_VALUE'
|
||||
};
|
||||
112
node_modules/vega-expression/src/functions.js
generated
vendored
Normal file
112
node_modules/vega-expression/src/functions.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
import {error} from 'vega-util';
|
||||
|
||||
export default function(codegen) {
|
||||
|
||||
function fncall(name, args, cast, type) {
|
||||
var obj = codegen(args[0]);
|
||||
if (cast) {
|
||||
obj = cast + '(' + obj + ')';
|
||||
if (cast.lastIndexOf('new ', 0) === 0) obj = '(' + obj + ')';
|
||||
}
|
||||
return obj + '.' + name + (type < 0 ? '' : type === 0 ?
|
||||
'()' :
|
||||
'(' + args.slice(1).map(codegen).join(',') + ')');
|
||||
}
|
||||
|
||||
function fn(name, cast, type) {
|
||||
return function(args) {
|
||||
return fncall(name, args, cast, type);
|
||||
};
|
||||
}
|
||||
|
||||
var DATE = 'new Date',
|
||||
STRING = 'String',
|
||||
REGEXP = 'RegExp';
|
||||
|
||||
return {
|
||||
// MATH functions
|
||||
isNaN: 'Number.isNaN',
|
||||
isFinite: 'Number.isFinite',
|
||||
abs: 'Math.abs',
|
||||
acos: 'Math.acos',
|
||||
asin: 'Math.asin',
|
||||
atan: 'Math.atan',
|
||||
atan2: 'Math.atan2',
|
||||
ceil: 'Math.ceil',
|
||||
cos: 'Math.cos',
|
||||
exp: 'Math.exp',
|
||||
floor: 'Math.floor',
|
||||
log: 'Math.log',
|
||||
max: 'Math.max',
|
||||
min: 'Math.min',
|
||||
pow: 'Math.pow',
|
||||
random: 'Math.random',
|
||||
round: 'Math.round',
|
||||
sin: 'Math.sin',
|
||||
sqrt: 'Math.sqrt',
|
||||
tan: 'Math.tan',
|
||||
|
||||
clamp: function(args) {
|
||||
if (args.length < 3) error('Missing arguments to clamp function.');
|
||||
if (args.length > 3) error('Too many arguments to clamp function.');
|
||||
var a = args.map(codegen);
|
||||
return 'Math.max('+a[1]+', Math.min('+a[2]+','+a[0]+'))';
|
||||
},
|
||||
|
||||
// DATE functions
|
||||
now: 'Date.now',
|
||||
utc: 'Date.UTC',
|
||||
datetime: DATE,
|
||||
date: fn('getDate', DATE, 0),
|
||||
day: fn('getDay', DATE, 0),
|
||||
year: fn('getFullYear', DATE, 0),
|
||||
month: fn('getMonth', DATE, 0),
|
||||
hours: fn('getHours', DATE, 0),
|
||||
minutes: fn('getMinutes', DATE, 0),
|
||||
seconds: fn('getSeconds', DATE, 0),
|
||||
milliseconds: fn('getMilliseconds', DATE, 0),
|
||||
time: fn('getTime', DATE, 0),
|
||||
timezoneoffset: fn('getTimezoneOffset', DATE, 0),
|
||||
utcdate: fn('getUTCDate', DATE, 0),
|
||||
utcday: fn('getUTCDay', DATE, 0),
|
||||
utcyear: fn('getUTCFullYear', DATE, 0),
|
||||
utcmonth: fn('getUTCMonth', DATE, 0),
|
||||
utchours: fn('getUTCHours', DATE, 0),
|
||||
utcminutes: fn('getUTCMinutes', DATE, 0),
|
||||
utcseconds: fn('getUTCSeconds', DATE, 0),
|
||||
utcmilliseconds: fn('getUTCMilliseconds', DATE, 0),
|
||||
|
||||
// sequence functions
|
||||
length: fn('length', null, -1),
|
||||
join: fn('join', null),
|
||||
indexof: fn('indexOf', null),
|
||||
lastindexof: fn('lastIndexOf', null),
|
||||
slice: fn('slice', null),
|
||||
|
||||
reverse: function(args) {
|
||||
return '('+codegen(args[0])+').slice().reverse()';
|
||||
},
|
||||
|
||||
// STRING functions
|
||||
parseFloat: 'parseFloat',
|
||||
parseInt: 'parseInt',
|
||||
upper: fn('toUpperCase', STRING, 0),
|
||||
lower: fn('toLowerCase', STRING, 0),
|
||||
substring: fn('substring', STRING),
|
||||
split: fn('split', STRING),
|
||||
replace: fn('replace', STRING),
|
||||
trim: fn('trim', STRING, 0),
|
||||
|
||||
// REGEXP functions
|
||||
regexp: REGEXP,
|
||||
test: fn('test', REGEXP),
|
||||
|
||||
// Control Flow functions
|
||||
if: function(args) {
|
||||
if (args.length < 3) error('Missing arguments to if function.');
|
||||
if (args.length > 3) error('Too many arguments to if function.');
|
||||
var a = args.map(codegen);
|
||||
return '('+a[0]+'?'+a[1]+':'+a[2]+')';
|
||||
}
|
||||
};
|
||||
}
|
||||
1500
node_modules/vega-expression/src/parser.js
generated
vendored
Normal file
1500
node_modules/vega-expression/src/parser.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user