Skip to content

Commit d0979ec

Browse files
author
Marcio Ferreira Moreno
committed
Initial commit
1 parent c5b734c commit d0979ec

19 files changed

+2095
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock.json
2+
.DS_Store

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Ninja-Util
2+
3+
This library has a set of helper classes and functions that are shared by our application following common patterns that we use on them. We mostly use `MVC`, `SOLID` and `Observer Pattern`.
4+
5+
6+
## Callback
7+
8+
Wraps a callback to be executed, check if it is a valid function and execute without exceptions.
9+
10+
```js
11+
const {Callback} = require("ninja-util");
12+
Callback.invoke(aCallback);
13+
```
14+
15+
## Express Wrapper
16+
17+
Wraps the http methods from the express and automatically set the response based on the callback invoked by the application
18+
19+
Examples:
20+
```
21+
22+
const { ExpressWrapper } = require ('ninja-util');
23+
24+
```
25+
26+
## Heap
27+
28+
> TODO
29+
30+
## Logger
31+
32+
Useful to logs the application to make easier to turn on and turn off logs.
33+
34+
`TODO: document`
35+
## Memory
36+
37+
38+
```js
39+
const Memory = require("ninja-util/memory");
40+
```
41+
42+
#### checkMemory([log])
43+
> NOTE: Node only
44+
45+
Logs the memory from the node application
46+
47+
Example:
48+
```js
49+
memory.checkMemory("now")
50+
```
51+
52+
Posibble Output:
53+
```
54+
now 5.5186767578125
55+
```
56+
57+
#### compreensiveBytes(bytesCount)
58+
59+
Example
60+
```js
61+
console.log(memory.compreensiveBytes(42))
62+
console.log(memory.compreensiveBytes(42000))
63+
console.log(memory.compreensiveBytes(42000000))
64+
```
65+
66+
Output:
67+
```
68+
42b
69+
41.02kb
70+
40.05mb
71+
```
72+
73+
#### getCurrentMemory([asNumber])
74+
75+
Returns the current footprint from the node application. If `asNumber` is set true, it will return in a number as bytes. Otherwise, it will convert using the `compreensiveBytes`, default is false.
76+
77+
Example:
78+
```
79+
memory.getCurrentMemory()
80+
memory.getCurrentMemory(true)
81+
```
82+
83+
Possible Output:
84+
85+
```
86+
5.84mb
87+
6244264
88+
```
89+
90+
## Observer
91+
92+
> TODO
93+
94+
## Promisify
95+
96+
> TODO
97+
98+
## SyncClient
99+
100+
> TODO
101+
102+
## SyncServer
103+
104+
> TODO
105+
106+
## Timer
107+
108+
> TODO

callback.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2016-present, IBM Research.
3+
* Licensed under The MIT License [see LICENSE for details]
4+
*/
5+
6+
"use strict";
7+
8+
function invokeCallback (callback, ...args)
9+
{
10+
if (callback && typeof (callback) === 'function')
11+
callback (...args);
12+
}
13+
14+
exports.invoke = invokeCallback;

0 commit comments

Comments
 (0)