Perlito5
view release on metacpan or search on metacpan
lib/Perlito5/JavaScript2/CORE.pm view on Meta::CPAN
var isNode = typeof require != "undefined";
EOT
# sleep()
. <<'EOT'
if (isNode) {
try {
var sleep = require("sleep");
CORE.sleep = function(List__) {
var n = p5num(List__[0]) || 1;
sleep.usleep(n * 1000000); // sleep for n seconds (1 second is 1000000 microseconds)
return n;
}
}
catch (err) {
CORE.sleep = function(List__) {
CORE.die("sleep() function failed. Maybe you need 'npm install sleep'?\n" + err);
}
lib/Perlito5/JavaScript2/CORE.pm view on Meta::CPAN
}
}
EOT
# crypt()
. <<'EOT'
if (isNode) {
try {
var crypt = require("crypt3");
CORE.crypt = function(List__) {
var text = p5str(List__[0]);
var salt = p5str(List__[1]);
while(salt.length < 2) {
salt += "A";
}
return crypt(text, salt);
}
}
catch (err) {
lib/Perlito5/JavaScript2/IO.pm view on Meta::CPAN
// Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.
//
// This program is free software; you can redistribute it and/or modify it
// under the same terms as Perl itself.
//
// See http://www.perl.com/perl/misc/Artistic.html
var isNode = typeof require != "undefined";
if (isNode) {
var fs = require("fs");
p5typeglob_set("Perlito5::IO", "print", function (filehandle, List__, p5want) {
try {
var v = filehandle;
var pkg;
if (CORE.ref([v])) {
// looks like a filehandle
pkg = v;
}
else {
lib/Perlito5/JavaScript3/IO.pm view on Meta::CPAN
// Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.
//
// This program is free software; you can redistribute it and/or modify it
// under the same terms as Perl itself.
//
// See http://www.perl.com/perl/misc/Artistic.html
var isNode = typeof require != "undefined";
if (isNode) {
var fs = require("fs");
p5atime = function(s) {
s = p5str(s);
try {
var stat = fs.statSync(s); return stat["atime"];
}
catch(err) {
return '';
}
};
lib/Perlito5/JavaScript3/Runtime.pm view on Meta::CPAN
p5a_to_h = function(a) {
var res = {};
for (i = 0; i < a.length; i+=2) {
res[p5str(a[i])] = a[i+1];
}
return res;
};
if (isNode) {
var fs = require("fs");
}
p5context = function(List__, p5want) {
if (p5want) {
return p5list_to_a.apply(null, List__);
}
// scalar: return the last value
var o = List__;
while (o instanceof Array) {
o = o.length
lib/Perlito5X/JavaScript/MIME/Base64.pm view on Meta::CPAN
package MIME::Base64;
use strict;
# See: https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_.232_.E2.80.93_rewriting_atob()_and_btoa()_using_TypedArrays_and_UTF-8
JS::inline(q!
var btoa = require('btoa');
var atob = require('atob');
!);
# encode_base64( $bytes )
# encode_base64( $bytes, $eol );
# Encode data by calling the encode_base64() function. The first argument is the byte string to encode.
# The second argument is the line-ending sequence to use. It is optional and defaults to "\n". The
# returned encoded string is broken into lines of no more than 76 characters each and it will end with
# $eol unless it is empty. Pass an empty string as second argument if you do not want the encoded string
# to be broken into lines.
#
( run in 0.636 second using v1.01-cache-2.11-cpan-0d8aa00de5b )