Qgoda
view release on metacpan or search on metacpan
lib/Qgoda/Command/Javascript.pm view on Meta::CPAN
You have to pass a filename containing JavaScript code as an argument
or prove the code on standard input.
Note that Duktape is B<not> NodeJS! Not all constructs accepted by NodeJS
are accepted by Duktape!
Qgoda, however, implements a module resolver so that you can use constructs
like:
const _ = require('lodash');
The module is resolved in the same way that NodeJS would resolve it.
See the option I<--global> below for more information.
=head1 OPTIONS
=over 4
=item I<-i, --input=FILENAME>
lib/Qgoda/JavaScript/config.js view on Meta::CPAN
* filename: The filename for the YAML input.
* local_input: The local YAML input.
* local_filename: The filename for the local YAML input.
*
* Output variables:
*
* config: The configuration with the default values from the schema
* merged in.
*/
const Ajv = require('ajv');
const yaml = require('js-yaml');
const _ = require('lodash');
// FIXME! Once https://github.com/gonzus/JavaScript-Duktape-XS/issues/13
// has been fixed, rather throw errors in case of failure.
delete __perl__.output.errors;
const ajv = new Ajv({useDefaults: true, coerceTypes: 'array'});
var validate;
try {
validate = ajv.compile(schema);
t/javascript-environment.t view on Meta::CPAN
baz => { type => 'boolean' }
},
required => [qw(foo bar)]
};
# Inject the YAML source into the VM.
$env->vm->set('input', $input);
$env->vm->set('schema', $schema);
my $data = $env->run(<<'EOF');
const yaml = require('js-yaml');
const Ajv = require('ajv');
var unserialized = yaml.safeLoad(input),
config = yaml.safeLoad(input),
ajv = new Ajv({useDefaults: true, coerceTypes: 'array'}),
validate = ajv.compile(schema),
valid = validate(config);
EOF
my $expected = {
foo => '1',
( run in 0.498 second using v1.01-cache-2.11-cpan-05444aca049 )