
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A very small library to create type guards for your project, it can be used either for typescript or javascript.
To install the guardex library, run the following command in the console.
npm install guardex --save-dev
Note: All of the examples in this document uses
ECMAsyntax to import or export code from the library, but this supportsCommonJSsyntax as well.// ECMA Syntax import is from "guardex"; // CommonJS Syntax const is = require("guardex");If you are using
ESMwithTypeScriptconsider reading the following information links:
These are the functions from the is exported object that can be used as type guards.
| function | guards to |
|---|---|
| undefined | undefined |
| null | null |
| trivial | null, undefined |
| value | {} |
| object | {} or T |
| json | {} or T |
| rgb | { red: number, green: number, blue: number } |
| function | Function |
| symbol | Symbol |
| string | string |
| number | number, bigint |
| zero | 0 |
| positive | number, bigint, not 0 |
| negative | number, bigint, not 0 |
| between | number, bigint |
| inside | number, bigint |
| smaller | number, bigint |
| smallerOrEqual | number, bigint |
| bigger | number, bigint |
| biggerOrEqual | number, bigint |
| array | Array (Exotic object) |
| true | true |
| truthy | Other than false, 0, "", null, undefined |
| false | false |
| falsy | false, 0, "", null, undefined |
| boolean | boolean |
| true | true |
| false | false |
| primitive | Function, Symbol, string, number, bigint, boolean |
| promise | Promise, Custom Promise (Read Promises) |
Checks if some value is undefined..
Checks if some value is null..
Checks if some value is null or undefined..
Checks if some value is not null or undefined..
Checks if some value is a function.
Checks if some value is a string.
Checks if some value is a number.
Checks if some value is a number and zero.
Checks if some value is a number and is positive.
Note Includes
0as positive value
Checks if some value is a number and is negative.
Note Not includes
0as negative value
Checks if is a number and if it is between the upper bound and lower bound.
Checks if is a number and if it is between the upper bound and lower bound or is one of those values.
Checks if is a number and if it is before the bound.
Checks if is a number and if it is before the bound or is equal/
Checks if is a number and if it is beyond the bound.
Checks if is a number and if it is beyond the bound or is equal.
Checks if some value is a boolean.
Checks if some value is a boolean and is true.
Checks if some value is truthy.
Note Any other value than
false,0,"",null,undefinedis considered truthy.
Checks if some value is a boolean and is false.
Checks if some value is falsy.
Note Any value of
false,0,"",null,undefinedis considered falsy.
Checks if some value is a JavaScript primitive.
Checks a value is a valid array.
Note Only works for the exotic object
Array.
Checks if some value is not a primitive.
Note If using
typescriptthe genericTworks only as a type guard and not as an instance checker, for more information go to https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
Checks if the value descends from the protoype of the {} object and is not a primitive value.
Note If using
typescriptthe genericTworks only as a type guard and not as an instance checker, for more information go to https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
Checks if the passed value is a valid instance of the parent.
Checks if an object is a valid RGB where the passed object should contain the red, green, blue properties where each one should be a number from 0 to 255.
Checks if the string starts with the character # and if after that is followed by 6 characters where each: is a value from A to F (casing is ignored) or any number from 0 to 9.
// This is a valid RGB string
const tangerine = "#e1442A";
Promises were while ago a feature only accessible with polyfills. This was somehing new that helped a lot to run in syntactic sugar way callbacks.
Currently is a fully supported feature in every modern browser or any modern JavaScript interpreter with the standarization of ES6 (https://caniuse.com/?search=es6) with even its own syntactic sugar as the async/await of JavaScript.
Because of this, when the global Promise class is found the only comparison that will be done is that is a non trivial value and the instanceof operator.
In case this function runs in an obsolete environment (i.e. Internet Explorer) that ussually uses polyfill libraries, the method will check:
then, catch and finally function are availableprotoype chain of a Promise prototype functionSymbol.toStringTag equals to "[object Promise]"The custom Promise may look like the following example:
// Parent function
function Promise() {}
// All of the three standard methods
Promise.then = function () {};
Promise.catch = function (error) {};
Promise.finally = function () {};
// The symbol tag to be represented as a promise
Promise[Symbol.toStringTag] = "Promise";
// The prototype and constructor assignation
Promise.prototype = Promise;
Promise.constructor = Promise;
FAQs
The guardian library for your types.
We found that guardex 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

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.