
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
kangaroo-expression
Advanced tools
Secure expression evaluator with AST-based execution - A fast, safe, and powerful JavaScript-like expression language
A secure JavaScript-like expression evaluator that uses AST-based execution instead of eval() for maximum security.
Note: This library is in active development and has not reached version 1.0 yet. The API is functional but may change. We recommend pinning to specific versions in production environments.
eval() or Function() constructor{{expression}} syntax in stringsnpm install kangaroo-expression
import { createEvaluator, registerGlobalType } from 'kangaroo-expression';
const evaluator = createEvaluator();
// Simple expressions
const result = evaluator.evaluate('Math.round(item.price * 1.2)', {
item: { price: 10.99 }
});
console.log(result); // { success: true, value: 13 }
// Array operations with callbacks
const filtered = evaluator.evaluate('items.filter(x => x.active)', {
items: [{ active: true }, { active: false }]
});
// Template expressions
const template = evaluator.evaluate('Hello {{item.name.toUpperCase()}}!', {
item: { name: 'world' }
});
// Type registry for intelligent object serialization
registerGlobalType('Product', {
schema: {
type: 'object',
properties: {
id: { type: 'string' },
name: { type: 'string' },
price: { type: 'number' }
},
required: ['id', 'name']
},
serialization: 'object' // Returns object directly
});
const product = { id: 'p123', name: 'Laptop', price: 999.99 };
const serialized = evaluator.getSerializedValue(product);
console.log(serialized); // Returns the actual object, not a string
import { evaluate, validate, isTemplate, registerGlobalType } from 'kangaroo-expression';
// Quick evaluation
const result = evaluate('expression', context, options);
// Validation
const validation = validate('expression');
// Template detection
console.log(isTemplate('Hello {{name}}!')); // true
// Type registry with different serialization strategies
registerGlobalType('Product', {
schema: { /* schema definition */ },
serialization: 'object' // Returns object directly
});
registerGlobalType('UserProfile', {
schema: { /* schema definition */ },
serialization: 'json' // Returns JSON string
});
registerGlobalType('ApiResponse', {
schema: { /* schema definition */ },
serialization: 'string' // Returns string representation
});
String Functions: toLowerCase, toUpperCase, trim, split, replace, substring, includes, startsWith, endsWith
Array Functions: length, join, slice, first, last, reverse, filter, map, find, some, every, reduce
Math Functions: Math.round, Math.floor, Math.ceil, Math.abs, Math.max, Math.min, Math.pow, Math.sqrt, Math.random
Date Functions: Date.now, Date.parse, Date.today, Date.addDays, Date.diffDays
Object Functions: Object.keys, Object.values, Object.entries
JSON Functions: JSON.parse, JSON.stringify
Utility Functions: isEmpty, hasField, $if, $and, $or, $not
Kangaroo includes a type registry that enables object serialization based on JSON Schema validation.
'object': Returns the object directly without conversion'json': Converts to JSON string (escaped for template embedding)'string': Converts to string representationimport { createEvaluator, registerGlobalType } from 'kangaroo-expression';
// Register a type for direct object access
registerGlobalType('Product', {
schema: {
type: 'object',
properties: {
id: { type: 'string' },
name: { type: 'string' },
price: { type: 'number' },
category: { type: 'string' }
},
required: ['id', 'name', 'price']
},
serialization: 'object'
});
const evaluator = createEvaluator();
const product = {
id: 'prod_123',
name: 'Wireless Headphones',
price: 199.99,
category: 'Electronics'
};
// Get direct object access
const directObject = evaluator.getSerializedValue(product);
console.log(directObject === product); // true - same object reference
// Templates automatically convert to JSON for embedding
const template = evaluator.evaluate('Product: {{item}}', { item: product });
// Result: 'Product: {"id":"prod_123","name":"Wireless Headphones",...}'
The type registry uses JSON Schema validation with performance optimizations:
import { Kangaroo, createEvaluator, evaluate } from 'kangaroo';
// Create evaluator instance
const evaluator = new Kangaroo({
maxComplexity: 50,
timeout: 5000,
strictMode: true
});
// Quick evaluation
const result = evaluate('expression', context, options);
// Validation
const validation = evaluator.validate('expression');
const context = {
item: { name: 'John', age: 30 },
inputs: { userInput: 'hello' },
outputs: { processedData: [1, 2, 3] }
};
// Array operations with arrow functions
evaluator.evaluate('numbers.map(x => x * 2)', { numbers: [1, 2, 3] });
evaluator.evaluate('users.filter(u => u.age > 18)', { users: [...] });
evaluator.evaluate('items.reduce((sum, item) => sum + item.value, 0)', { items: [...] });
Kangaroo is designed with security as a primary concern:
eval(), Function(), or similar dynamic execution methodsPre-1.0: The library is functional and tested, but the API may change before the 1.0 release. We recommend pinning to specific versions in production environments.
Full TypeScript definitions are included:
import { ExpressionContext, EvaluationResult, SafeFunction } from 'kangaroo';
const context: ExpressionContext = { item: { value: 42 } };
const result: EvaluationResult = evaluator.evaluate('item.value', context);
Apache 2.0 License - see LICENSE file for details.
Issues and pull requests are welcome. Please ensure all tests pass and follow the existing code style.
FAQs
Secure expression evaluator with AST-based execution - A fast, safe, and powerful JavaScript-like expression language
We found that kangaroo-expression demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.