
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@hdoc/js-utils
Advanced tools
Different utils for javascript
npm install --save-dev @hdoc/js-utils
Provides sum and average functions for array of numbers
const { sum, avg } = require('@hdoc/js-utils');
const numbers = [1, 2, 3];
// logs 6
console.log(sum(numbers));
// logs 3
console.log(avg(numbers));
Provides functions and validations for arrays
const {
arrayOfNumbers,
arrayOfStrings,
randomElement,
sort,
} = require('@hdoc/js-utils');
const numbers = [1, 2, 3];
const strings = ['string', 'word', 'random'];
// logs true
console.log(arrayOfNumbers(numbers));
console.log(arrayOfStrings(strings));
// logs false
console.log(arrayOfNumbers('string', { name: 'object' }, [null]));
console.log(arrayOfStrings(1, [], null));
// logs a random element of array numbers
console.log(randomElement(numbers));
// logs numbers and strings in ascendent order
console.log(sort(numbers));
console.log(sort(strings));
console.log(sort(numbers, 1));
console.log(sort(strings, 1));
// logs numbers and strings in descendent order
console.log(sort(numbers, -1));
console.log(sort(strings, -1));
// logs numbers and strings in random order
console.log(sort(numbers, 'r'));
console.log(sort(strings, 'r'));
Note: randomElement() and sort() returns a new array.
Provides a solver for cuadratic equations of the form: ax2 + bx + c = 0. Where a, b and c are the coefficients of the equation.
const { equation } = require('@hdoc/js-utils');
const coefficients = {
coeA: 2,
coeB: 1,
coeC: 0,
};
// logs { root1: 0, root2: -0.5 }
console.log(equation.cuadratic(coefficients));
Browser utils are only available as ESModules. You need to download them from utils/browser folder.
Note: I recommend to place the utils files in utils folders
Provides simplified function names for dom accesing.
Having the next html file ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example</title>
<script src="js/main.js" type="module" defer></script>
</head>
<body>
<main>
<p id="text1" class="text">Texto 1</p>
<p id="text2" class="text">Texto 2</p>
<p id="text3" class="text">Texto 3</p>
<p id="text4" class="text">Texto 4</p>
<p id="text5" class="text">Texto 5</p>
</main>
</body>
</html>
You need to import in main.js ...
import { qs, qsa, gid } from './utils/dom.js';
// logs main tag
console.log(qs('main'));
// logs NodeList of elements with class 'text' as an array
console.log(qsa('.text'));
// logs element with id text1
console.log(gid('text1'));
Provides functions to handle forms.
Having the next html file ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example</title>
<script src="js/main.js" type="module" defer></script>
</head>
<body>
<form id="my-form">
<input type="text" name="usr_name" required />
<input type="email" name="usr_email" required />
<input type="submit" value="Send" />
</form>
</body>
</html>
You need to import in main.js ...
import { gid } from './utils/dom.js';
import { formInputs } from './utils/form.js';
gid('my-form').addEventListener('submit', (e) => {
e.preventDefault();
const data = formInputs(e.target);
// logs { usr_name: usr_name_value, usr_email: usr_email_value}
console.log(data);
});
Note: formInputs() returns an object with data of each input that have name attribute.
FAQs
Different utils for javascript
We found that @hdoc/js-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.