Gathering detailed insights and metrics for util-ex
Gathering detailed insights and metrics for util-ex
Gathering detailed insights and metrics for util-ex
Gathering detailed insights and metrics for util-ex
moment-ex-tool
moment's extended tool library does not change moment's original logic, it just subtly calls moment.
@abhishekgapsorg/st-util
This library needs following params from config to operate: > papertrail >>host - ex: "logs2.papertrailapp.com" <br/> >>port - ex: "xxxxx" <br/> >>program - ex: "jobs-util" <br/>
@teamteanpm2024/ex-quidem-est
security holding package
@teamteanpm2024/tempora-ex-explicabo
security holding package
Browser-friendly enhanced util fully compatible with standard node.js util
npm install util-ex
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (97.44%)
CoffeeScript (2.56%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
166 Commits
2 Watchers
2 Branches
1 Contributors
Updated on May 07, 2024
Latest Version
2.3.0
Package Id
util-ex@2.3.0
Unpacked Size
246.68 kB
Size
47.22 kB
File Count
200
NPM Version
10.8.2
Node Version
20.18.3
Published on
Jun 16, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Enhanced utils
This package modifies and enhances the standard util
from node.js
Full API Documents is here: Docs
▸ inject(aOrgFunc
, aBeforeExec
, aAfterExec
): Function
Wraps a function and executes code before and/or after the wrapped function.
Throws
If aAfterExec is not a function and an error occurs while executing the wrapped function.
Example
1import { inject as injectFunc } from 'util-ex' 2 3// Wrapping a function with injectFunc 4const originalFunc = (a, b) => a + b; 5const beforeFunc = (a, b) => console.log(`Before execution: a = ${a}, b = ${b}`); 6const afterFunc = (result) => console.log(`After execution: result = ${result}`); 7const wrappedFunc = injectFunc(originalFunc, beforeFunc, afterFunc); 8const result = wrappedFunc(1, 2); // Logs "Before execution: a = 1, b = 2" and "After execution: result = 3"
Example
1// Wrapping a function with injectFunc and modifying arguments and return value 2const Arguments = injectFunc.Arguments 3const originalFunc = (a, b) => a + b; 4const beforeFunc = (a, b) => { 5 console.log(`Before execution: a = ${a}, b = ${b}`); 6 return new Arguments([a * 2, b * 3]); 7}; 8const afterFunc = (result, isDenied) => { 9 console.log(`After execution: result = ${result}, isDenied = ${isDenied}`); 10 return result * 2; 11}; 12const wrappedFunc = injectFunc(originalFunc, beforeFunc, afterFunc); 13const result = wrappedFunc(1, 2); // Logs "Before execution: a = 1, b = 2", "After execution: result = 6, isDenied = false" 14console.log(result); // Output: 12
Example
1// Wrapping a function with injectFunc and not executing the original function 2const originalFunc = (a, b) => a + b; 3const beforeFunc = (a, b) => { 4 console.log(`Before execution: a = ${a}, b = ${b}`); 5 return "Not executing original function"; 6}; 7const afterFunc = (result, isDenied) => { 8 console.log(`After execution: result = ${result}, isDenied = ${isDenied}`); 9 return "Modified return value"; 10}; 11const wrappedFunc = injectFunc(originalFunc, beforeFunc, afterFunc); 12const result = wrappedFunc(1, 2); // Logs "Before execution: a = 1, b = 2", "After execution: result = Modified return value, isDenied = true" 13console.log(result); // Output: "Modified return value"
Example
1// Wrapping a function with injectFunc and getting the original function's error 2const originalFunc = () => { 3 throw new Error("Original function error"); 4}; 5const beforeFunc = () => { 6 console.log("Before execution"); 7}; 8const afterFunc = (result, isDenied) => { 9 console.log(`After execution: result = ${result}, isDenied = ${isDenied}`); 10}; 11const wrappedFunc = injectFunc(originalFunc, beforeFunc, afterFunc); 12wrappedFunc(); // Logs "Before execution", "After execution: result = [Error: Original function error], isDenied = false"
Name | Type | Description |
---|---|---|
aOrgFunc | Function | The function to be wrapped. |
aBeforeExec | Function | A function to be executed before the wrapped function aOrgFunc . |
aAfterExec | Function | A function to be executed after the wrapped function aOrgFunc . |
Function
A new function that wraps the original function.
BeforeExec:
If aBeforeExec
is a function, it will be called with the same context and arguments as the wrapped function.
Arguments
object, the wrapped function will be called with the modified arguments.undefined
, the wrapped function will not be called and this value will be returned as result instead.AfterExec:
If aAfterExec
is a function, it will be called with the same context, arguments with additional the result of the aOrgFunc
and isDenied flag.
aOrgFunc
throws an error, the result
parameter will be an Error
object.aAfterExec
returns a value, it will be used as the final result of the wrapped function.isDenied
parameter is true, it means aOrgFunc
was not called during execution of the wrapped function.▸ injectMethod(aObject
, aMethodName
, aNewMethod
): boolean
Injects method into an object. optionally preserving access to the original method via "super
" and original instance via "self
".
Note:
this.super()
to call the original method, this.super()
is already bound with original instance.this[aMethodName]
is also the original method, but not bound yet.this.self
is the original instance!Example
1import { injectMethod } from 'util-ex' 2 3var obj = { 4 method1: function() { 5 console.log('Hello'); 6 } 7}; 8 9var newMethod = function() { 10 this.super(); 11 console.log('World'); 12}; 13 14injectMethod(obj, 'method1', newMethod); 15 16obj.method1(); // Output: Hello\nWorld
Name | Type | Description |
---|---|---|
aObject | any | the target object to inject |
aMethodName | string | the target method to inject |
aNewMethod | Function | the new method to be injected into the aObject. |
boolean
whether the injection is successful.
newFunction(name, arguments, body[, scope[, values]])
newFunction(functionString[, scope[, values]])
Creates a new function with the given name, arguments, body, scope and values.
1import { newFunction } from 'util-ex'
2
3var fn = newFunction('yourFuncName', ['arg1', 'arg2'], 'return log(arg1+arg2);', {log:console.log})
4newFunction('function yourFuncName(){}')
5newFunction('function yourFuncName(arg1, arg2){return log(arg1+arg2);}', {log:console.log})
6newFunction('function yourFuncName(arg1, arg2){return log(arg1+arg2);}', ['log'], [console.log])
7
8//fn.toString() is :
9/*
10 "function yourFuncName(arg1, arg2) {
11 return log(arg1+arg2);
12 }"
13*/
defineProperty(object, key, value[, aOptions])
Define a property on the object. move to inherits-ex package.
1const defineProperty = require('util-ex/lib/defineProperty') 2 3let propValue = '' 4const obj = {} 5 6defineProperty(obj, 'prop', 'simpleValue') 7defineProperty(obj, 'prop', undefined, { 8 get() {return propValue} 9 set(value) {propValue = value} 10})
No vulnerabilities found.
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More