Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "grandjs", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A backend framework for solid web apps based on node.js", | ||
@@ -35,2 +35,2 @@ "main": "Grand.js", | ||
} | ||
} | ||
} |
185
README.MD
@@ -1,3 +0,2 @@ | ||
# GRAND JS | ||
# Grandjs | ||
A backend framework for solid web apps based on node.js | ||
@@ -8,3 +7,2 @@ | ||
* Grandjs is built for solid and extended web apps | ||
![GitHub contributors](https://img.shields.io/github/contributors/tareksalem/grandjs.svg?style=flat-square) | ||
@@ -14,3 +12,3 @@ ![npm](https://img.shields.io/npm/v/grandjs.svg) | ||
![npm](https://img.shields.io/npm/dt/grandjs.svg?color=green&style=popout) | ||
### Prerequisites | ||
## Prerequisites | ||
@@ -27,3 +25,2 @@ 1- you need to install node.js on your system | ||
* Grandjs is built for solid and extended web apps | ||
```javascript | ||
@@ -72,3 +69,2 @@ //require HTTP module | ||
``` | ||
**content** | ||
@@ -80,2 +76,4 @@ - [Installing](#installing) | ||
- [extend Router class](#extend-router-class) | ||
- [define get routers](#define-get-routers) | ||
- [define get routers](#define-post-routers) | ||
- [Access on request and response objects](#access-on-request-and-response-objects) | ||
@@ -120,3 +118,3 @@ - [Request object](#request-object) | ||
## Getting Started | ||
#### Server configuration | ||
### Server configuration | ||
to start with Grandjs just install it and call it in your file as the following | ||
@@ -176,7 +174,6 @@ ```javascript | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Router | ||
* Grandjs Routing system is built upon object oriented programming, so Router is a class inside Grandjs you extend it and add routes to it as you wanna | ||
<br> | ||
@@ -222,5 +219,7 @@ **to work with router class you need to extend it or instatiate it directly and every class implies a group of routes have a specific basename** | ||
<hr style="border:.5px solid black;height:0"> | ||
###Define get routers | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Define get routers | ||
**Example** | ||
```javascript | ||
@@ -247,5 +246,8 @@ class HomeRouter extends Grandjs.Router{ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
###Define post routers | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Define post routers | ||
**Example** | ||
```javascript | ||
@@ -273,4 +275,6 @@ class HomeRouter extends Grandjs.Router{ | ||
###instantiate router class | ||
### instantiate router class | ||
**Example** | ||
```javascript | ||
@@ -301,2 +305,3 @@ class HomeRouter extends Grandjs.Router{ | ||
when you instantiate the class you should define the options parameter as an object includes two properties | ||
| property | type |descriptions | | ||
@@ -308,2 +313,3 @@ |----------|:-------------:|-----: | | ||
**Example** | ||
```javascript | ||
@@ -314,3 +320,3 @@ const homeRoters = new HomeRouter({ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Access on request and response objects | ||
@@ -321,3 +327,5 @@ | ||
1- req & res objects are properties inside the class | ||
**Example** | ||
```javascript | ||
@@ -351,3 +359,5 @@ class HomeRouter extends Grandjs.Router{ | ||
2- request & response are accessable as parameters inside handler function | ||
**Example** | ||
```javascript | ||
@@ -365,4 +375,6 @@ homePage() { | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
####Specify a separated folder for static files for this group of routes | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### Specify a separated folder for static files for this group of routes | ||
```javascript | ||
@@ -375,4 +387,6 @@ const homeRoters = new HomeRouter({ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
####Router add route | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### Router add route | ||
This function enables you to add routers to the class from outside it | ||
@@ -382,3 +396,4 @@ ```javascript | ||
``` | ||
this function takes one (required) parameter as an object has the following properties: | ||
this function takes one (required) parameter as an object has the following properties | ||
|Property | type | description | | ||
@@ -392,2 +407,3 @@ |---|---|---| | ||
**Example** | ||
```javascript | ||
@@ -414,4 +430,6 @@ const adminRoute = new Grandjs.Router({ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
###Router class errorPage | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Router class errorPage | ||
you can specify a custom error page for every class you instantiate it to control on error links in a group of routes | ||
@@ -421,3 +439,5 @@ to do that you need to define "errorPage" method to the class | ||
1- define it inside the class | ||
**Example** | ||
```javascript | ||
@@ -433,3 +453,3 @@ class HomeRouter extends Grandjs.Router{ | ||
handler: () => { | ||
this.res.end("hello home page); | ||
this.res.end("hello home page"); | ||
} | ||
@@ -443,3 +463,3 @@ } | ||
handler: () => { | ||
this.res.end("hello about page); | ||
this.res.end("hello about page"); | ||
} | ||
@@ -455,3 +475,5 @@ } | ||
2-Define error page from outside the class | ||
**Example** | ||
```javascript | ||
@@ -482,4 +504,6 @@ const homeRouter = new Grandjs.Router({ | ||
*not that if you didn't define error page for the router class it automatically call error page which you specified in setConfig function | ||
<hr style="border:.5px solid black;height:0"> | ||
###Router url define params | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Router url define params | ||
you can add params to the url of the router to make dynamic routes like the following: | ||
@@ -490,3 +514,5 @@ ```javascript | ||
to access on the parameters inside the url using [request.params property](#request-params) | ||
**Example** | ||
```javascript | ||
@@ -504,5 +530,5 @@ const homePage = new Grandjs.Router({ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
####Request Object | ||
#### Request Object | ||
this is an object you can access on it inside the handler of the route | ||
@@ -528,3 +554,5 @@ and the object contains the all information about the request which is coming | ||
if there is no params so it returns an empty object | ||
**Example** | ||
```javascript | ||
@@ -565,7 +593,10 @@ const homePage = new Grandjs.Router({ | ||
<hr style="border:.5px solid black;height:0"> | ||
####Handle post request | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### Handle post request | ||
Grandjs handls all types of post requests and sumited data and returns them as an object called ``req.data`` this object contains all the submitted data and you can access on it inside the handler function if the method of router is post | ||
**Example** | ||
```javascript | ||
@@ -582,4 +613,6 @@ postAdminPage() { | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
####Response Object | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### Response Object | ||
this is an object you can access on it inside the handler of the route | ||
@@ -595,3 +628,4 @@ This object contains all methods that you need to send a response or content to the coming request | ||
``` | ||
takes one parameter as an object, this object should contains the following properties: | ||
takes one parameter as an object, this object should contains the following properties | ||
| property | type | description | | ||
@@ -604,3 +638,5 @@ |---|---|---| | ||
| data | object (optional) | object contains the data you want to render inside the handlbars files | ||
**Example** | ||
```javascript | ||
@@ -643,2 +679,3 @@ homePageRouter() { | ||
this function takes on parameter | ||
|parameter | type | description | | ||
@@ -649,3 +686,5 @@ |---|---|---| | ||
this function uses promise to return a ``catch`` function if the file isn't exist | ||
**Example** | ||
```javascript | ||
@@ -657,3 +696,3 @@ res.sendFile("/views/pages/home.html").catch((err) => { | ||
####``res.json`` function | ||
#### ``res.json`` function | ||
this function sends json data, it accepts one parameter this parameter should be an object and Grandjs stringify this object automatically | ||
@@ -663,5 +702,6 @@ ```javascript | ||
``` | ||
####``res.redirect`` function | ||
#### ``res.redirect`` function | ||
This function is used to make redirect to another link | ||
It accepts one parameter | ||
|parameter | type | description | | ||
@@ -675,3 +715,3 @@ |---|---|---| | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
@@ -690,3 +730,5 @@ #### MiddleWares | ||
| next | function | is a function you can execute it to continue to the final handler of the router | | ||
**Example** | ||
```javascript | ||
@@ -719,3 +761,3 @@ //middle ware | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Validation | ||
@@ -726,10 +768,10 @@ Grandjs includes awesome validation system to validate inputs and remove strip tags and check the correct email | ||
2- as a property inside request object inside handlers | ||
#### ``validation.strip_html_tags`` function | ||
#### ``validation.striphtmltags`` function | ||
this function removes weird characters from the string to insure that there is no harmful characters inside the string | ||
```javascript | ||
let str = "<h1>hello world</h1>" | ||
let str = "h1hello worldh1" | ||
Grandjs.helpers.validation.strip_html_tags(str) // output hello world | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
@@ -746,2 +788,3 @@ #### ``validation.checkEmail`` function | ||
| cb | function (optional) | this is a callback function you can call it and includes one parameter either be true or false | | ||
This function you can call it async with a callback function or sync without callback | ||
@@ -764,3 +807,3 @@ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``validation.notEmpty`` function | ||
@@ -770,3 +813,4 @@ | ||
it accepts two parameters: | ||
it accepts two parameters | ||
| parameter | type | description | | ||
@@ -776,2 +820,3 @@ |---|---|---| | ||
| cb | function (optional) | this is a callback function you can call it and includes one parameter either be true or false | | ||
This function you can call it async with a callback function or sync without callback | ||
@@ -794,3 +839,3 @@ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``validation.checkContainsNumber`` function | ||
@@ -800,3 +845,4 @@ | ||
it accepts three parameters: | ||
it accepts three parameters | ||
| parameter | type | description | | ||
@@ -807,2 +853,3 @@ |---|---|---| | ||
| cb | function (optional) | this is a callback function you can call it and includes one parameter either be true or false | | ||
This function you can call it async with a callback function or sync without callback | ||
@@ -826,3 +873,3 @@ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``validation.checkIsNumber`` function | ||
@@ -833,3 +880,4 @@ | ||
it accepts two parameters: | ||
it accepts two parameters | ||
| parameter | type | description | | ||
@@ -839,2 +887,3 @@ |---|---|---| | ||
| cb | function (optional) | this is a callback function you can call it and includes one parameter either be true or false | | ||
This function you can call it async with a callback function or sync without callback | ||
@@ -859,9 +908,9 @@ | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
###Cryption | ||
### Cryption | ||
Grandjs gives you functionalities to crypt important info and cipher them and decrypt the | ||
cryption functions are inside helpers inside grandjs library | ||
This helper uses the ``ENCRYPTION_KEY`` that you specify in ``setConfig`` function. | ||
####enCrypt | ||
#### enCrypt | ||
```javascript | ||
@@ -871,2 +920,3 @@ Grandjs.helpers.enCrypt(text); | ||
This function takes one parameter which referes to the string you wanna encrypt or cipher it | ||
|parameter | type | description | | ||
@@ -881,4 +931,5 @@ |---|---|---| | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
####deCrypt | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### deCrypt | ||
```javascript | ||
@@ -888,2 +939,3 @@ Grandjs.helpers.deCrypt(text); | ||
This function takes one parameter which referes to the string you wanna decrypt or decipher it | ||
|parameter | type | description | | ||
@@ -898,6 +950,6 @@ |---|---|---| | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
###Session | ||
### Session | ||
Grandjs represents to you a session module which you can use it in login processes and setting cookies for logged in users | ||
@@ -927,2 +979,3 @@ | ||
``setCooki`` is an object, you specify inside it an object called ``expires`` this object has two properties | ||
|property | type | description | | ||
@@ -935,5 +988,6 @@ |---|---|---| | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``session.set`` function | ||
This is a function you call it when you want to set a session, this function takes three parameters: | ||
This is a function you call it when you want to set a session, this function takes three parameters | ||
| parameter | type | description | | ||
@@ -977,3 +1031,3 @@ |---|---|---| | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### `session.getSession` function | ||
@@ -987,3 +1041,3 @@ This function gets the session of the user based on the name of the session that you specified in ``session.set`` function | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``session.updateSession`` function | ||
@@ -995,3 +1049,3 @@ This function is very similar to ``session.set`` function and it takes the same parameters but this function you use it to updating an already exist session | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
@@ -1006,3 +1060,3 @@ #### ``session.breakSession`` function | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
### Auth module | ||
@@ -1020,3 +1074,4 @@ This module is a built in module in Grandjs, it is used to make authentication inside the system to allow user login and logout securely. | ||
This function takes three parameters: | ||
This function takes three parameters | ||
| parameter | type | description | | ||
@@ -1031,3 +1086,3 @@ |---|---|---| | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
@@ -1042,3 +1097,3 @@ #### ``auth.checkAuth`` function | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``auth.Auth`` function | ||
@@ -1067,3 +1122,3 @@ This function is optional to use, the of it is if you are doing a heavy checks before require ``auth.login`` function so Grandjs represents to you this function which enables you to make some processing and returns a callback function after that has ``done`` parameter, it's value is: ``true`` or ``false`` | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
#### ``auth.logout`` function | ||
@@ -1077,3 +1132,3 @@ This function depends on ``session.breakSession`` function, it logouts the user and destroys the session | ||
``` | ||
<hr style="border:.5px solid black;height:0"> | ||
<!-- <hr style="border:.5px solid black;height:0"> --> | ||
@@ -1085,3 +1140,5 @@ ### Flash Messages | ||
flash is accessable inside any router handler | ||
**Example** | ||
```javascript | ||
@@ -1088,0 +1145,0 @@ // post router |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75148
1121