Javascript easy string manipulation, file access, ascii conversions, statistics, json, and more ..
by @sha0coder
require('protos.js');
var users = [];
users.load('users.txt');
if (!users.has('Peter')) {
users.push('Peter')
users.save('users.txt')
}
if ('Peter'.in(users)) {
'Peter is here'.log();
'some error'.err();
'John'.appendFile('users.txt')
}
var str = 'test';
str.log();
str.save('file.txt');
str.save('file.txt', function() {
'async saved!'.log();
});
var str = ''.load('data.txt');
'myfolder'.mkdir();
> ['a','b','c','d'].cut(1,3);
[ 'b', 'c' ]
> ['a','b','c','d'].cut(0,-1);
[ 'a', 'b', 'c', 'd' ]
> ['a','b','c','d'].cut(1,-1);
[ 'b', 'c', 'd' ]
> ['a','b','c','d'].cut(-2);
'c'
> 'hello'.cut(0)
'h'
> 'hello'.cut(-1)
'o'
> 'hello'.cut(0,-1)
'hello'
> 'hello'.cut(-5,-1)
'hello'
> 'hello'.cut(-2,-1)
'lo'
'I have {0} years old'.fmt(age).log();
> 'hello'.cut(0,4).log();
'hell'
> '3'.toInt();
3
> 'a'.toInt().isNum();
false
> 'john'.capitalize()
'John'
var struct = {}.load('file.json');
struct.save('file.json');
struct.save('file.json', function() {
'saved'.log();
});
struct.dir()
'hello'.compare('hell')
'hello'.compare('hello')
'hello'.compare('abcd')
var hash = 'hello'.fuzzyHash();
objects.call('method',[params]);
> ['cats','dogs','birds'].choice()
'dogs'
> [3, 1, 2, 3].unique()
[ 3, 1, 2 ]
> [1,2,3,4].common([5,6,1,2]);
[ 1, 2 ]
> [1,2,3,4].notIn([9,3,5,1,2]);
[ 4 ]
> [1,2,3].has(4)
false
> [ 'hola', 'cara', 'cola' ].grep('la');
[ 'hola', 'cola' ]
> [ 'hola', 'cara', 'cola' ].vgrep('la');
[ 'cara' ]
> var n = [1,2,3,4,5];
> n.smap(function(n) { return n*2; });
[ 2, 4, 6, 8, 10 ]
'ls'.exec(function(stdout,stderr) {
stdout.log();
stderr.err();
});
> [1,3,2].max()
3
> [1,3,2].min()
1
> [1,3,2].average()
2
> var n = [];
> n.fillNums(1,10);
> n.cut(0,1)
[ 1 ]
> n.cut(-3,-1)
[ 9, 10 ]
> var n = 0/0;
> n.isNum();
false
> var a = {b:1};
> a.dir();
{ b: 1 }
> var a = [1,2,3];
> a.dir();
[ 1, 2, 3 ]
> (0x41).chr();
'A'
> 'a'.chr()
97
> 'HELLO'.chr();
[ 72, 69, 76, 76, 79 ]
> [72,69,76,76,79].chr()
'HELLO'
['dog','cat','bird'].each(function(i,pet) {
pet.log();
});
x.isNumber();
x.isObject();
x.isArray();
x.isString();
x.isBoolean();
(cmd == 'install').call(doInstall);
(1 == 2).call(ghostbusters);
true.call(function() {
'always here'.log();
});
false.call(ghostbusters)
'help'.in(process.args).call(doHelp);
> function sayHello() { 'hello'.log(); }
> sayHello.sched(1000)
hello
hello
hello
hello
...
String.prototype.exec = function(cb)
String.prototype.strip = function()
String.prototype.fuzzyHash = function()
String.prototype.log = function()
String.prototype.err = function()
String.prototype.compare = function(str)
String.prototype.capitalize = function()
String.prototype.fmt = function()
String.prototype.load = function(filename, cb)
String.prototype.save = function(filename,cb)
String.prototype.mkdir = function()
String.prototype.appendFile = function(filename)
String.prototype.toInt = function()
String.prototype.in = function(arr)
String.prototype.contains = function(str)
String.prototype.cut = function(b,e)
String.prototype.chr = function()
String.prototype.isNumeric = function()
String.prototype.isBoolean = function()
String.prototype.isArray = function()
String.prototype.isString = function()
String.prototype.isObject = function()
String.prototype.isDate = function()
Array.prototype.dir = function()
Array.prototype.log = function()
Array.prototype.choice = function()
Array.prototype.removeId = function(id)
Array.prototype.grep = function(kw)
Array.prototype.vgrep = function(kw)
Array.prototype.hasSimilar = function(str, min_ratio)
Array.prototype.unique = function()
Array.prototype.load = function(filename)
Array.prototype.save = function(filename)
Array.prototype.clear = function()
Array.prototype.sched = function(millis, cb)
Array.prototype.max = function()
Array.prototype.min = function()
Array.prototype.average = function()
Array.prototype.smap = function(fn)
Array.prototype.has = function(item)
Array.prototype.cut = function(b,e)
Array.prototype.call = function(params)
Array.prototype.fillNums = function(b,e)
Array.prototype.chr = function()
Array.prototype.each = function(cb)
Array.prototype.common = function(arr)
Array.prototype.notIn = function(arr)
Array.prototype.isNumeric = function()
Array.prototype.isBoolean = function()
Array.prototype.isArray = function()
Array.prototype.isString = function()
Array.prototype.isObject = function()
Array.prototype.isDate = function()
Number.prototype.isNaN = function()
Number.prototype.isNum = function()
Number.prototype.log = function()
Number.prototype.chr = function()
Number.prototype.isNumber = function()
Number.prototype.isBoolean = function()
Number.prototype.isArray = function()
Number.prototype.isString = function()
Number.prototype.isObject = function()
Number.prototype.isDate = function()
Object.prototype.load = function(filename)
Object.prototype.save = function(filename, cb)
Object.prototype.dir = function()
Object.prototype.isNumeric = function()
Object.prototype.isBoolean = function()
Object.prototype.isArray = function()
Object.prototype.isString = function()
Object.prototype.isObject = function()
Object.prototype.isDate = function()
Date.prototype.isNumeric = function()
Date.prototype.isBoolean = function()
Date.prototype.isArray = function()
Date.prototype.isString = function()
Date.prototype.isObject = function()
Date.prototype.isDate = function()
Boolean.prototype.call = function(cb)
Boolean.prototype.isNumeric = function()
Boolean.prototype.isBoolean = function()
Boolean.prototype.isArray = function()
Boolean.prototype.isString = function()
Boolean.prototype.isObject = function()
Boolean.prototype.isDate = function()