Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function parseDateTime(dateTime: string | number | DateTime) {
if (typeof dateTime === 'number' || typeof dateTime === 'string') {
return new Date(dateTime);
}
const expression = dateTimeExpr(dateTime, true) as string;
const code = codegen({ globalvar: 'window' })(parse(expression)).code as string;
// Technically the "code" here is safe to eval(),
// but we will use more conservative approach and manually parse at the moment.
const isUtc = code.startsWith('Date.UTC');
const dateParts = code
.replace(/^(Date[.]UTC|new[ ]Date)\(/, '')
.replace(/\)$/, '')
.split(',')
.map((chunk: string) => Number(chunk.trim())) as [
number, // year
number, // month
number, // date
number, // hours
number, // minutes
number, // seconds
number, // milliseconds
export function toPredicateFunction(filters: ShelfFilter[]) {
const expr = '(' +
filters.map(f => {
return fieldFilterExpression(f, false); // Do not use inrange as it is not included in the main Vega Expression
}).join(')&&(') +
')';
const ast = vegaExpression.parse(expr);
const codegen = vegaExpression.codegen({
whitelist: ['datum'],
globalvar: 'global'
});
const value = codegen(ast);
return new Function('datum', `return ${value.code};`) as (d: object) => boolean;
}
for (var name in functionContext) { fn[name] = thisPrefix + name; }
return fn;
}
// Export code generator and parameters
export var codegenParams = {
blacklist: ['_'],
whitelist: ['datum', 'event', 'item'],
fieldvar: 'datum',
globalvar: function(id) { return '_[' + stringValue('$' + id) + ']'; },
functions: buildFunctions,
constants: constants,
visitors: astVisitors
};
export var codeGenerator = codegen(codegenParams);
// register Vega-Lite selection functions
expressionFunction('vlSelectionTest', selectionTest, selectionVisitor);
expressionFunction('vlSelectionResolve', selectionResolve, selectionVisitor);
// Export code generator and parameters
export const codegenParams = {
blacklist: ['_'],
whitelist: ['datum', 'event', 'item'],
fieldvar: 'datum',
globalvar: function(id) { return '_[' + stringValue(SignalPrefix + id) + ']'; },
functions: buildFunctions,
constants: constants,
visitors: astVisitors
};
export var codeGenerator = codegen(codegenParams);