0.9.11 • Published 9 years ago

secure-json-logic v0.9.11

Weekly downloads
3
License
BSD-2-Clause
Repository
github
Last release
9 years ago

secure-json-logic

Use logic-objects from uncertain sources and run them locally without breaking the own system This module is optimized for performance-issues.

Installation

npm install secure-json-logic --save

npm page

Visit npm-page

github

Visit github-page

example usage

Example usage is in the example.js - file

usage

SecureJSONLogic = require('secure-json-logic');

var allowedVars = [
    'u.protocol',
    'u.slashes',
    'u.hostname',
    'u.host',
    'u.hostSpit',
    'u.port',
    'u.hash',
    'u.search',
    'u.query',
    'u.pathname',
    'u.path',
    'u.href',
    'u.hostnameSplit',
    'u.hostnameSplit.length'
];

var testLogicObject = {
    fkt: '&&',
    params: [
        {
            fkt: '==',
            params: [
                {
                    type: 'number',
                    name: 3
                },
                {
                    type: 'var',
                    name: 'u.hostnameSplit.length'
                }
            ]
        },
        {
            fkt: '==',
            params: [
                {
                    type: 'string',
                    name: 'www.amazon.com'
                },
                {
                    type: 'var',
                    name: 'u.hostname'
                }
            ]
        },
        {
            "fkt": '||',
            params: [
                {
                    "fkt": 'startswith',
                    params: [

                        {
                            type: 'var',
                            name: 'u.hostname'
                        },
                        {
                            type: 'string',
                            name: 'www.'
                        }
                    ]
                },
                {
                    "fkt": 'endswith',
                    params: [
                        {
                            type: 'var',
                            name: 'u.hostname'
                        },
                        {
                            type: 'string',
                            name: '.com'
                        }
                    ]
                }
            ]
        }
    ]
};

var testInput = {
    u: {
        hostname: 'www.amazon.com',
        hostnameSplit: [
            'www',
            'amazon',
            'com'
        ]
    }
};


console.log('## running example ##');

console.time("renderTime");
var f = SecureJSONLogic(testLogicObject, allowedVars);
console.timeEnd("renderTime");

console.log('### generated function: ###');
console.log(f.toString());
console.log('#############################');

console.log('### result for testInput: ###');
console.log(f(testInput) + '   <- this should be true');
console.log('#############################');

var c=5000000;
console.log('### time measurement ( running '+c+' times) ###');
console.time("exectime");
while(c>0){
    f(testInput);
    c--;
}
console.timeEnd("exectime");
console.log('#################################################');
0.9.11

9 years ago

0.9.10

10 years ago

0.9.9

10 years ago

0.9.8

10 years ago

0.9.7

10 years ago

0.9.6

10 years ago

0.9.5

10 years ago

0.9.4

10 years ago

0.9.3

10 years ago

0.9.1

10 years ago