Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

guarder

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

guarder - npm Package Compare versions

Comparing version 0.5.0 to 0.9.0

lib/guards/NegativeGuard.d.ts

4

lib/guards/EmptyGuard.d.ts

@@ -12,8 +12,4 @@ import { Guard } from '../types/Guard';

guard<T = unknown>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
/**
* Throw the error with the error message
*/
private failed;
}
export { EmptyGuard };
//# sourceMappingURL=EmptyGuard.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Guarder_1 = require("../Guarder");
const ArgumentError_1 = require("../errors/ArgumentError");

@@ -14,7 +15,4 @@ /**

const message = errorMessage !== null && errorMessage !== void 0 ? errorMessage : 'Property not allowed to be empty';
const isNull = property === null;
const isUndefined = property === undefined;
if (isNull || isUndefined) {
return this.failed(message, error);
}
Guarder_1.Guarder.null(property, message, error);
Guarder_1.Guarder.undefined(property, message, error);
const isEmptyString = typeof property === 'string' ? property === '' : false;

@@ -25,16 +23,10 @@ const isArrayEmpty = Array.isArray(property) ? property.length === 0 : false;

if (isEmptyString || isArrayEmpty || isObjectEmpty) {
return this.failed(message, error);
if (error)
throw new error(message);
throw new ArgumentError_1.ArgumentError(message);
}
return property;
}
/**
* Throw the error with the error message
*/
failed(message, error) {
if (error)
throw new error(message);
throw new ArgumentError_1.ArgumentError(message);
}
}
exports.EmptyGuard = EmptyGuard;
//# sourceMappingURL=EmptyGuard.js.map
import { Guarder } from './Guarder';
import { Guard } from './types/Guard';
import { NullGuard } from './guards/NullGuard';
import { ZeroGuard } from './guards/ZeroGuard';
import { EmptyGuard } from './guards/EmptyGuard';
import { FalsyGuard } from './guards/FalsyGuard';
import { NumberGuard } from './guards/NumberGuard';
import { Instantiable } from './types/Instantiable';
import { ArgumentError } from './errors/ArgumentError';
import { NegativeGuard } from './guards/NegativeGuard';
import { UndefinedGuard } from './guards/UndefinedGuard';
import { WhitespaceGuard } from './guards/WhitespaceGuard';
import { GuardNotFoundError } from './errors/GuardNotFoundError';
export { Guard, Guarder, NullGuard, EmptyGuard, FalsyGuard, Instantiable, ArgumentError, UndefinedGuard, GuardNotFoundError, };
export { Guard, Guarder, NullGuard, ZeroGuard, EmptyGuard, FalsyGuard, NumberGuard, Instantiable, ArgumentError, NegativeGuard, UndefinedGuard, WhitespaceGuard, GuardNotFoundError };
//# sourceMappingURL=index.d.ts.map

@@ -7,2 +7,4 @@ "use strict";

exports.NullGuard = NullGuard_1.NullGuard;
const ZeroGuard_1 = require("./guards/ZeroGuard");
exports.ZeroGuard = ZeroGuard_1.ZeroGuard;
const EmptyGuard_1 = require("./guards/EmptyGuard");

@@ -12,8 +14,14 @@ exports.EmptyGuard = EmptyGuard_1.EmptyGuard;

exports.FalsyGuard = FalsyGuard_1.FalsyGuard;
const NumberGuard_1 = require("./guards/NumberGuard");
exports.NumberGuard = NumberGuard_1.NumberGuard;
const ArgumentError_1 = require("./errors/ArgumentError");
exports.ArgumentError = ArgumentError_1.ArgumentError;
const NegativeGuard_1 = require("./guards/NegativeGuard");
exports.NegativeGuard = NegativeGuard_1.NegativeGuard;
const UndefinedGuard_1 = require("./guards/UndefinedGuard");
exports.UndefinedGuard = UndefinedGuard_1.UndefinedGuard;
const WhitespaceGuard_1 = require("./guards/WhitespaceGuard");
exports.WhitespaceGuard = WhitespaceGuard_1.WhitespaceGuard;
const GuardNotFoundError_1 = require("./errors/GuardNotFoundError");
exports.GuardNotFoundError = GuardNotFoundError_1.GuardNotFoundError;
//# sourceMappingURL=index.js.map
{
"name": "guarder",
"version": "0.5.0",
"version": "0.9.0",
"description": "Guarder provides simple validation logic to reduce clutter with inline guard statements",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -19,2 +19,3 @@ # Guarder

- [Default Guards](#default-guards)
- [Official Guards](#official-guards)
- [Examples](#examples)

@@ -62,2 +63,7 @@ - [Usage](#usage)

- [EmptyGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/EmptyGuard.ts)
_Empty Guard ensures that the property is not null or undefined. A string should contain at least one character, an
array should contain at least one item, an object should contain at least one key_
- [FalsyGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/FalsyGuard.ts)
_Falsy Guard ensures that the property does not evaluate to false in a type coercion_
- [NullGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/NullGuard.ts)

@@ -67,9 +73,26 @@ _Undefined Guard ensures that the property is not null_

_Undefined Guard ensures that the property is not undefined_
- [FalsyGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/FalsyGuard.ts)
_Falsy Guard ensures that the property does not evaluate to false in a type coercion_
As a general rule of thumb, default configured guards will always be available by name within the `Guarder` class.
#### Official Guards
The full list of packaged official guards include:
- [EmptyGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/EmptyGuard.ts)
_Empty Guard ensures that the property is not null or undefined. A string should contain at least one character, an
array should contain at least one item, an object should contain at least one key_
As a general rule of thumb, default configured guards will always be available by name within the `Guarder` class.
- [FalsyGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/FalsyGuard.ts)
_Falsy Guard ensures that the property does not evaluate to false in a type coercion_
- [NegativeGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/NegativeGuard.ts)
_Negative Guard validates a property is not a negative number_
- [NullGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/NullGuard.ts)
_Undefined Guard ensures that the property is not null_
- [NumberGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/NumberGuard.ts)
_Number Guard validates that the property is a number_
- [UndefinedGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/UndefinedGuard.ts)
_Undefined Guard ensures that the property is not undefined_
- [WhitespaceGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/WhitespaceGuard.ts)
_Whitespace Guard validates that the string does not contain only whitespace_
- [ZeroGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/ZeroGuard.ts)
_Zero Guard validates that the property is not zero_

@@ -76,0 +99,0 @@ #### Examples

import { TestError } from '../../../mocks/TestError'
import { ArgumentError, NullGuard } from '../../../../src'
describe('#NullGuard', () => {
describe('NullGuard', () => {
const customMessage = 'Testing custom error message'

@@ -6,0 +6,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc