Socket
Socket
Sign inDemoInstall

ezito-utils

Package Overview
Dependencies
5
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.2.1

client/get-browers/index.js

2

package.json
{
"name": "ezito-utils",
"version": "1.0.0",
"version": "1.2.1",
"description": "ezito utils help you for faster programming",

@@ -5,0 +5,0 @@ "main": " ",

"use strict";
function dirToRouteMiddleWare ( path = "" , paths = '') {
path = path.replace(/\\/g , '/');
var parseDir = path.split('/');
var validTypeCheck = [
'String' ,
'Number'
];
var regexp = '';
for (var index = 0; index < parseDir.length; index++) {
var routeItem = parseDir[index];
if(/\[\.\.\.(.*?)\]/.test(routeItem)){
routeItem = routeItem.replace(/\[\.\.\.(.*?)\]/, (str,name) => {
return ":" + name + '/*';
});
parseDir [index] = routeItem;
}
if(/\[(.*?)\]/.test(routeItem)){
routeItem = routeItem.replace(/\[(.*?)\]/, (str,name) => {
return ":" + name;
});
parseDir[index] = routeItem;
function dirToRouteMiddleWare ( path , paths = '') {
paths = paths.replace(/\\/g , '/');
let route = path.replace(/\[\.\.\.(.*?)\]/g , function(t){
return t.replace('[...','[').replace(']',']/*');
})
.replace(/\\/g,'/').replace(/\[(.*?)\]/g, function(t){
return ("[" + t.slice(1 , t.length -1 ).replace(/\W/g, function(x){
return ':';
})+"]").replace(/\[/g , ':').replace(/\]/g , '');
});
return route.slice((paths || '').length);
for (var type of validTypeCheck) {
regexp = new RegExp(':' + type + '(' + '(.*?)' + ')' ,'gi');
if(regexp.test(routeItem)){
routeItem = routeItem.replace( regexp , function strReplace(str){
});
}
}
}
};
return parseDir.join('/');
};
module.exports = dirToRouteMiddleWare;

@@ -8,2 +8,6 @@ 'use strict';

const eventEmitter = new event.EventEmitter();
function createEvent(){
return new event.EventEmitter();
}
eventEmitter.addListener;

@@ -21,2 +25,2 @@ eventEmitter.removeListener;

eventEmitter.setMaxListeners;
module.exports = eventEmitter;
module.exports = createEvent;

@@ -16,2 +16,4 @@ 'use strict';

return false;
}
}
module.exports = isPromise;

@@ -10,13 +10,8 @@ 'use strict';

module.exports = function () {
return (
typeof window === "undefined"
&&
typeof document === "undefined"
&&
typeof process !== "undefined"
&&
typeof global !== "undefined"
&&
typeof localStorage === "undefined"
)
var isWindow = typeof window === "object" && "[object Window]" === Object.prototype.toString.call(window);
var isDocument = typeof document === "object" && "[object HTMLDocument]" === Object.prototype.toString.call(document);
var isNative = typeof navigator === "object" && '[object Navigator]' === Object.prototype.toString.call(navigator);
var isGloabl = typeof global === "object";
var isClient = isWindow && isDocument && isNative ;
return isClient === false && isGloabl;
}

@@ -14,5 +14,4 @@ 'use strict';

else if (typeof chrome !== 'undefined' || typeof process !== 'undefined'){
for (let index = 0; index < 2; index++) {
error.stack = error.stack.replace(/\n[^\n]*/, '') ;
error.stack = error.stack.replace(/\n[^\n]*/, '');
}

@@ -19,0 +18,0 @@

"use strict";
function includeKeys ( object = null | Object , keys = null | Array | String , callback = null | Function ){
/**
* @param {Object} object
* @param { Array | String } keys
* @param { undefined | null | function} callback
* @returns
*/
function includeKeys ( object = Object , keys = Array | String , callback = undefined | null | Function ){
let result = [];
// check type for keys accept Array list of key or string key

@@ -11,18 +17,14 @@ if(!(keys instanceof Array ) && !(typeof keys === 'string')) throw { ErrorType : "param type erorr" , message : "keys nust instanceof Array!" };

});
let result = keys.map(function(key){
if( key.indexOf('/') > -1 ){
return includeKeys( object , key.split('/'));
}
if( object.hasOwnProperty(key) === true ){
object = object[key];
return object;
for (const checkKeys of keys) {
if(checkKeys.indexOf('/') > -1){
result.push(includeKeys(object , checkKeys.split('/')));
}
return 0;
});
if(result.length === keys.length){
if( Object.toString(callback) === '[object Function]' || typeof callback === 'function')
return callback.call( this , result.pop())
return result.pop();
}
result.push(Object.hasOwnProperty.call(object , checkKeys))
}
result = result.filter ( is => is === true);
if(result.length === keys.length) return true;
return false;
}

@@ -29,0 +31,0 @@

@@ -1,31 +0,134 @@

/**
*
*/
module.exports = function( index = null ){
const getBrowers = require('ezito-utils/client/get-browers');
var haveCaptureStackTrace = 'captureStackTrace' in Error;
function FireFoxStackParser(error , hasName){
function CallSite({ functionName , lineNumber , fileName , charStart }){
this.getFunctionName = function(){
return functionName;
}
this.getLine = function(){
return lineNumber;
}
this.getFileName = function(){
return fileName
}
this.charStart = function(){
return charStart
}
};
var stack = error.stack.split('\n');
var functionName = '';
var fristFunctionNameSlice = '';
var fileName = '';
var lineNumber = 0;
var charStart = 0;
for (let index = 0; index < stack.length; index++) {
fristFunctionNameSlice = stack[index].split('@')[0].replace(/\\/,'/').split('/');
if(fristFunctionNameSlice.at(-1) === '<'){
functionName = fristFunctionNameSlice[ fristFunctionNameSlice.length - 2];
}
else {
functionName = fristFunctionNameSlice[ fristFunctionNameSlice.length - 1];
if(!functionName && stack.indexOf('@') > -1){
functionName = '<anymous>'
}
}
if(stack[index]){
lineNumber = stack[index].split('@').at(1).replace(/\\/,'/').split('/').at(-1).split(':')[1];
charStart = stack[index].split('@').at(1).replace(/\\/,'/').split('/').at(-1).split(':')[2];
fileName = stack[index].split('@').at(1).replace(/\\/,'/').split('/') ;
fileName.shift();
fileName.shift();
}
stack[index] = new CallSite({ functionName , lineNumber , fileName , charStart });
}
error.stack = stack;
};
function V8StackParser (error){
function CallSite({ functionName , lineNumber , fileName , charStart }){
this.getFunctionName = function(){
return functionName;
}
this.getLine = function(){
return lineNumber;
}
this.getFileName = function(){
return fileName
}
this.charStart = function(){
return charStart
}
};
stack = error.stack;
var message = error.message;
var stackList = stack.split('\n');
var newStack = [];
var fileName = '';
var functionName = '';
var charStart = 0;
var lineNumber = '';
for (let index = 0; index < stackList.length; index++) {
stackList[index] = stackList[index].trim();
if(stackList[index].slice(0,'Error'.length) === 'Error' && index === 0){
if(message && message === stackList[index].slice('Error :'.length)){
/// message
}
}
else {
functionName = stackList[index].match(/at(.*?)\(/).at(1).trim();
charStart = Number(
stackList[index].match(/\((.*?)\)/).at(1).slice(
stackList[index].match(/\((.*?)\)/).at(1).trim().lastIndexOf(':') + 1,
)
);
lineNumber = stackList[index].match(/\((.*?)\)/).at(1).slice(
0 ,
stackList[index].match(/\((.*?)\)/).at(1).trim().lastIndexOf(':')
);
lineNumber = Number(lineNumber.slice(lineNumber.lastIndexOf(':') + 1));
fileName = stackList[index].match(/\((.*?)\)/).at(1).trim();
fileName = fileName.slice(0 , fileName.lastIndexOf(lineNumber + ':' + charStart) -1);
newStack.push(new CallSite({ functionName , line , fileName , charStart }));
}
}
error.stack = newStack;
}
function errorConfig(){
if(!haveCaptureStackTrace && !('captureStackTrace' in Error)){
Object.defineProperty(Error,"captureStackTrace",{
value : function (error , constructor ){
var constructorBody = typeof constructor === "function" ? Function.prototype.toString.call(constructor) : false;
var hasName = 'function name () {'.match(/function\s+(.*?)\(/).length > 1 ? 'function name () {'.match(/function\s+(.*?)\(/).at(1).trim() : false;
var isFireFox = getBrowers().fireFox;
if( error instanceof Error){
if(isFireFox) return FireFoxStackParser(error , hasName);
return V8StackParser(error, hasName);
}
}
});
}
}
function stackTrace (index){
errorConfig();
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
var stack = {};
try {
Error.captureStackTrace(err, arguments.callee );
stack = err.stack;
Error.prepareStackTrace = orig;
stack;
} catch (error) {
stack = (new Error).stack;
Error.prepareStackTrace = orig;
}
if( stack instanceof Array){
stack.shift();
}
else {
return stack.split('\n');
}
var error = new Error;
var stack = {};
Error.captureStackTrace(error , stackTrace);
stack = error.stack;
Error.prepareStackTrace = orig;
return {
list : stack ,
stack ,
error ,
getThis(){

@@ -47,3 +150,3 @@ if( typeof index === "number" )

} ,
getFunction( ){
getFunction(){
if( typeof index === "number" )

@@ -54,3 +157,3 @@ return stack[index].getFunction();

return item.getFunction();
})
});
} ,

@@ -139,2 +242,4 @@ getFunctionName( ){

}
};
}
module.exports = stackTrace

@@ -13,2 +13,3 @@ 'use strict';

const isSymbol = require('ezito-utils/public/is/symbol');
var isPromise = require('ezito-utils/public/is/promise');

@@ -21,2 +22,5 @@

};
EzitoTypes.promise = function (object){
return isPromise(object);
}
EzitoTypes.function = function functionCheck(param){

@@ -23,0 +27,0 @@ return isFunction(param);

'use strict';
require('./../dotenv')();
require('ezito-utils/server/dotenv')();
const http = require('http');
const https = require('https');
const fs = require('fs');
const resolve = require('ezito-utils/server/fs/resolve');
function createHttpsServer(app = {} , { key , crt }){
var privateKey = fs.readFileSync(resolve(key), 'utf8');
var certificate = fs.readFileSync(resolve(crt), 'utf8');
const resolve = require('ezito-utils/server/fs/resolve');
/**
*
* @param {*} app
* @param {*} param1
* @returns
*/
function createHttpsServer(app = Object , option = { key : '' , crt : ''}){
var privateKey = fs.readFileSync(resolve(option.key), 'utf8');
var certificate = fs.readFileSync(resolve(option.crt), 'utf8');
var credentials = { key: privateKey, cert: certificate };
server = https.createServer( credentials ,app );
app.listen = function(port , cb){
return server.listen(port || process.env.PORT , cb);
};
return app;
var server = https.createServer( credentials , app );
app.listen = server.listen.bind(server);
return server;
}
function createHttpServer(app = {}){
server = http.createServer(app);
app.listen = function(port , cb){
return server.listen(port || process.env.PORT , db);
}
return app;
/**
*
* @param {HttpServerObject} app
* @returns {http.createServer}
*/
function createHttpServer(app = Object){
var server = http.createServer(app);
app.listen = server.listen.bind(server);
return server;
}

@@ -25,0 +32,0 @@ module.exports = {

@@ -23,3 +23,3 @@ const path = require('path');

file_path = toPosixPath(file_path);
var traceCallerNumber = getTrace(1).getFileName() === __filename ? 2 : 1;
var traceCallerNumber = getTrace(1).getFileName() === __filename ? 2 : 1;
const caller_path = toPosixPath(path.dirname(getTrace(traceCallerNumber).getFileName()));

@@ -26,0 +26,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc