Support me for future versions:
JSComet is a easy way of creating apps with OO class like ES6/TypeScript/Babel features with truly private vars and functions, type validations, function overloads, all in runtime and can create libraries like browserify and reference this in projects. JSComet has an easy to use MVC platform with excellent performance for your web projects please check the benchmarks.
Types and Return Types checked in runtime
Truly private functions
Can be used ahead-of-time (and i recommend it!)
Can be used directly in the browser
Fast build
Fast for use as runtime on smaller frontend projects or used as generated library in bigger projects
Easy to install, create, build and run
Nice way to organize and reference js libraries
How install:
npm install jscomet -g
How use:
Project types available: app, console, library, web. (Desktop coming soon)
For documentation and more details click here
For examples click here
Command line:
version show JSComet version
clean clean all projects
clean %PROJECT_NAME% clean a project
build %PROJECT_NAME% build a project
create solution create a empty solution file
create %PROJECT_TYPE% %PROJECT_NAME% create a project
Default Options:
create app MyProject
create console MyProject
create web MyProject
create library MyProject
remove %PROJECT_NAME% remove a project
run %PROJECT_NAME% run a project
publish %PROJECT_NAME% %OUT_DIRECTORY% publish a project to folder
reference add %PROJECT_NAME% %REFERENCE_PROJECT_NAME% add project reference
reference remove %PROJECT_NAME% %REFERENCE_PROJECT_NAME% remove project reference
add %FILE_TEMPLATE% %PROJECT_NAME% %FILE_PATH% add a file
Default Options:
add html MyProject myHTMLFile
add xml MyProject myXMLFile
add js MyProject myJSFile
add css MyProject myCSSFile
add class MyProject models\myModelClass
add class MyProject models\myModelClass extended myModelBase
add class MyProject models\myModelClass singleton
A new version with more features and MVVM comming soon.
click here
For documentation and more detailsclick here
For examplesTranspiler Features
main.js
; //Modules can be used as namespacevar sampleClient = SampleModuleClient; //is possible use String Template, in this case for encodeURIComponent each parametervar sampleTemplateFunction = url `/client/?email=`;
./js/SampleMdule.js:
module SampleModule //you can use import and export //https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Statements/export var UserType = Default : 0 Guest : 1 Admin : 2 Premium : 3 ; //typed fields are generated as properties get/set, and can be private, public, static, private static e public static //if you just want a easy way to create a property you can use any as type name : string; surname : string; email : string; password : string; type : int = UserTypeDefault; /* int is a special validator for number types: bit : min: 0 max: 1 sbyte : min: -128 max: 127 byte : min: 0 max: 255 short : min: -32768 max: 32767 ushort : min: 0 max: 65535 int : min: -2147483648 max: 2147483647 uint : min: 0 max: 4294967295 long : min: -9007199254740991 max: 9007199254740991 ulong : min: 0 max: 9007199254740991 this types cant be NaN, null or undefined for floats: float: min: -3.402823E+38 max: -3.402823E+38 double: min: -1.7976931348623157e+308 max: 1.7976931348623157e+308 this types cant be NaN, null or undefined you can use more than one type, for example for int nullable you can use: age: int | null; For string, number, boolean, object, function e symbol, CANT be undefined and only boolean CANT be null Typed Array shortcuts: sbyte[]: Int8Array byte[]: Uint8Array short[]: Int16Array ushort[]: Uint16Array int[]: Int32Array uint[]: Uint32Array float[]: Float32Array double[]: Float64Array Any type can be declared with Type[] but will be generated as a native Array type Samples: var a = new sbyte[]; var a = new sbyte[](10); var a = new sbyte[]([1, 2, 3, 4]); types: int[]; Other validators: any: accept any value char: only string with length equals 1 CANT be null or undefined void: force only undefined values can be used for validate returns undefined: like void only accept undefined (can be used for optionals params like : string | undefined) null: only accept null (can be used for create nullable values like: int | null) */ { thisname = name; thisemail = email; thispassword = password; thissurname = surname; } get : string return ` `; { return `;;;;`; } ; private id : int = 0; { supernull null null null; } //You can create overloads create function/constructor but overloads are differentiated only by the number of parameters and types are not considered { superusername usersurname useremail userpassword; //super realiza chamadas do construtor da classe herdada } { thisuser; //you can use this() for call constructor thisid = id; } public get : int return thisid; { //super.fieldOrFunction can access functions and fields of inherited class return `;`; } private static : string return 'xyxxyxyx'; public static : User /*FAKE QUERY*/ return id 'Michael' 'Silva' 'michael.silva@gmail.com' Client; public static { /*FAKE QUERY*/ var list = 10; for var i = 0; i < 10; i++ var user = Client; useremail = email || useremail; list; return list; } /* Overloads are differentiated only by the number of parameters and types are not considered */ public static { /*FAKE QUERY*/ var list = 10; for var i = 0; i < 10; i++ var user = Client; username = name || username; usersurname = surname || usersurname; list; return list; } /*Is possible use "..." before a parameter name for create a REST parameter */ { var result = pieces0; for var i = 0; i < substitutionslength; ++i result += + piecesi + 1; return result;};
Sub Classes:
//public private //private public //public
ApacheBench MVC Test
A little benchmark using ApacheBench for simple performance test JSComet and Sails.
Command:
ab -k -l -p payload.json -T application/json -n 100000 -c 500 http://localhost:8080/
payload.json
"data": "{'job_id':'c4bb6d130003','container_id':'ab7b85dcac72','status':'Success: process exited with code 0.'}"
Configurations:
Intel Core i7-6700HQ @ 2.60GHz
16 GB RAM
Windows 10 Pro - 64 bits
Performance Results:
- ##### JSComet (default) - 7537.64 requests per sec
- ##### JSComet without cluster - 2233.26 requests per sec (3.37 times slower)
- ##### Sails (default) - 1374.82 requests per sec (5.48 times slower)
- ##### Sails with cluster - 3887.82 requests per sec (1.94 times slower)
JSComet in default configuration use cluster and is 5.48 times faster than Sails in default configuration.
Code:
JSComet:
; public { var data = thisbody; return this; };
Sails:
moduleexports = /** * CommentController.index() */ { var data = reqbody; return res; };
Full Default Settings Results:
JSComet
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost Completed 10000 requestsCompleted 20000 requestsCompleted 30000 requestsCompleted 40000 requestsCompleted 50000 requestsCompleted 60000 requestsCompleted 70000 requestsCompleted 80000 requestsCompleted 90000 requestsCompleted 100000 requestsFinished 100000 requests Server Software:Server Hostname: localhostServer Port: 8080 Document Path: /home/Document Length: Variable Concurrency Level: 500Time taken
Sails
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost Completed 10000 requestsCompleted 20000 requestsCompleted 30000 requestsCompleted 40000 requestsCompleted 50000 requestsCompleted 60000 requestsCompleted 70000 requestsCompleted 80000 requestsCompleted 90000 requestsCompleted 100000 requestsFinished 100000 requests Server Software:Server Hostname: localhostServer Port: 1337 Document Path: /home/Document Length: Variable Concurrency Level: 500Time taken
click here)
Decorators (for more informationJSComet support decorators to help consume Rest API, cache, log, validation and more features. To use this features you need to install jscomet.decorators package in your project src folder.
npm install jscomet.decorators
@abstract
Abstract decorators do not allow this class to be instanced only inherited, when applied in a function or property throw a exception if not overrided. Can be used in classes, functions and properties.
;@abstract name: string = "ciro"; @abstract surname: string; @abstract { }
@sealed
Sealed decorators do not allow this class to be inherited any more. Can be only in classes.
; @sealed name: string = "ciro";
@deprecated(message: string, options: object)
Deprecated decorators can be used to throw a exception or log a warning, options parameter is optional
; //throw a exception: This function will be removed in future versions. DON'T USE THIS! @ { } //log a warning: This function will be removed in future versions. @deprecated { } //log a warning: This function will be removed in future versions. See http://mysite.com/deprecated/test3 for more details. @ { }//sealed decorators do not allow this class to be inherited any more @sealed name: string = "ciro";
@memoryCache(duration: int)
Create a cache in memory using a static object, you can use in class functions and this decorators support async functions.
; //this will create a result cache using function arguments as key for X milliseconds @ { } //You can use in functions that returns a Promise or async functions @ async { return await DALUser; }
@httpRequest(url: string, options: object)
HttpRequest decorator is a helper to consume Rest API`s. If a function use this decorator the function will return a Promise and hers body only will be called if the request is NOT successfully. Parameter url contains a url format to execute a http request:
; @ { } // {search: "value"} @ { //the function body only is called if a http error as throw console; //return default value return {}; } @ { }
The @setting:MySettingName format can be used to add a value in url for not keep the base url hard coded.
; httpRequest; @ { }
Parameter options is optional and can contains the struct bellow:
method: "get" //method can be get, post, head, put, update, delete etc (get as default) responseType: "text" //responseType can be text or json (text as default) contentType: "json" //contentType can be text or json (json as default) //can be passed headers ({} as default) headers: "MyHeaderName": "MyHeaderValue" "MyHeaderName2": "{0}" //use arguments index 0 as value "MyHeaderName3": "{headerParam}" //use property headerParam of arguments passed
@httpGet(url: string, options: object)
Just a shortcut for httpRequest with default method as get.
@httpPost(url: string, options: object)
Just a shortcut for httpRequest with default method as post.