Socket
Book a DemoInstallSign in
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

to
0.3.0

lib/types/Instantiable.d.ts

16

lib/Guarder.d.ts

@@ -1,3 +0,3 @@

import { Class } from './types/Class';
import { Guard } from './types/Guard';
import { Instantiable } from './types/Instantiable';
/**

@@ -14,7 +14,7 @@ * Guarder provides various guards which can be used for quick validation of data

*/
static null<T = any>(property: T, message?: string, error?: Class<Error>): T;
static null<T = any>(property: T, message?: string, error?: Instantiable<Error>): T;
/**
* Returns the property if the property is not undefined. Throws an error if the property is undefined.
*/
static undefined<T = any>(property: T, message?: string, error?: Class<Error>): T;
static undefined<T = any>(property: T, message?: string, error?: Instantiable<Error>): T;
/**

@@ -24,7 +24,7 @@ * Returns the property if the property is not an empty string, object, array, undefined or null. Throws an error if

*/
static empty<T = any>(property: T, message?: string, error?: Class<Error>): T;
static empty<T = any>(property: T, message?: string, error?: Instantiable<Error>): T;
/**
* Returns the property if the property does not evaluate to false in a type coercion
*/
static falsy<T = any>(property: T, message?: string, error?: Class<Error>): T;
static falsy<T = any>(property: T, message?: string, error?: Instantiable<Error>): T;
/**

@@ -34,3 +34,3 @@ * Returns the property if the property passes the custom guards validation logic and will throw an Argument Error or

*/
static custom<T = any>(guardName: string, property: T, message?: string, error?: Class<Error>): T;
static custom<T = any>(guardName: string, property: T, message?: string, error?: Instantiable<Error>): T;
/**

@@ -40,3 +40,3 @@ * Returns the property if the property passes the custom guards validation logic and will throw an Argument Error or

*/
static inlineCustom<T = any>(guard: Class<Guard>, property: T, message?: string, error?: Class<Error>): T;
static inlineCustom<T = any>(guard: Instantiable<Guard>, property: T, message?: string, error?: Instantiable<Error>): T;
/**

@@ -53,5 +53,5 @@ * Get all registered guards

*/
static registerGuard(guardName: string, guard: Class<Guard>): void;
static registerGuard(guardName: string, guard: Instantiable<Guard>): void;
}
export { Guarder };
//# sourceMappingURL=Guarder.d.ts.map

@@ -1,3 +0,3 @@

import { Class } from '../types/Class';
import { Guard } from '../types/Guard';
import { Instantiable } from '../types/Instantiable';
/**

@@ -11,3 +11,3 @@ * Empty Guard ensures that the property is not null or undefined. A string should contain at least one character, an

*/
guard<T = any>(property: T, errorMessage?: string, error?: Class<Error>): T;
guard<T = any>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
private failed;

@@ -14,0 +14,0 @@ }

@@ -1,3 +0,3 @@

import { Class } from '../types/Class';
import { Guard } from '../types/Guard';
import { Instantiable } from '../types/Instantiable';
/**

@@ -10,5 +10,5 @@ * Falsy Guard ensures that the property does not evaluate to false in a type coercion

*/
guard<T = any>(property: T, errorMessage?: string, error?: Class<Error>): T;
guard<T = any>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
}
export { FalsyGuard };
//# sourceMappingURL=FalsyGuard.d.ts.map

@@ -1,3 +0,3 @@

import { Class } from '../types/Class';
import { Guard } from '../types/Guard';
import { Instantiable } from '../types/Instantiable';
/**

@@ -10,5 +10,5 @@ * Null Guard ensures that the property is not null

*/
guard<T = any>(property: T, errorMessage?: string, error?: Class<Error>): T;
guard<T = any>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
}
export { NullGuard };
//# sourceMappingURL=NullGuard.d.ts.map

@@ -1,3 +0,3 @@

import { Class } from '../types/Class';
import { Guard } from '../types/Guard';
import { Instantiable } from '../types/Instantiable';
/**

@@ -10,5 +10,5 @@ * Undefined Guard ensures that the property is not undefined

*/
guard<T = any>(property: T, errorMessage?: string, error?: Class<Error>): T;
guard<T = any>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
}
export { UndefinedGuard };
//# sourceMappingURL=UndefinedGuard.d.ts.map
import { Guarder } from './Guarder';
import { Class } from './types/Class';
import { Guard } from './types/Guard';

@@ -7,6 +6,7 @@ import { NullGuard } from './guards/NullGuard';

import { FalsyGuard } from './guards/FalsyGuard';
import { Instantiable } from './types/Instantiable';
import { ArgumentError } from './errors/ArgumentError';
import { UndefinedGuard } from './guards/UndefinedGuard';
import { GuardNotFoundError } from './errors/GuardNotFoundError';
export { UndefinedGuard, NullGuard, EmptyGuard, FalsyGuard, GuardNotFoundError, ArgumentError, Class, Guard, Guarder };
export { Guard, Guarder, NullGuard, EmptyGuard, FalsyGuard, Instantiable, ArgumentError, UndefinedGuard, GuardNotFoundError, };
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

import { Class } from './Class';
import { Instantiable } from './Instantiable';
/**

@@ -9,5 +9,5 @@ * Guards represent specific validation mechanisms

*/
guard<T = any>(property: T, errorMessage?: string, error?: Class<Error>): T;
guard<T = any>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
}
export { Guard };
//# sourceMappingURL=Guard.d.ts.map
{
"name": "guarder",
"version": "0.2.0",
"version": "0.3.0",
"description": "Guarder provides simple validation logic to reduce clutter with inline guard statements",

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

@@ -17,2 +17,5 @@ # Guarder

- [Installation](#installation)
- [Guides](#guides)
- [Default Guards](#default-guards)
- [Examples](#examples)
- [Usage](#usage)

@@ -51,2 +54,40 @@ - [Null Guard](#nullt--anyproperty-t-message-string-error-classerror-t)

## Guides
Guides are basic information about the package for easier use. This section aims to satisfy FAQs.
#### Default Guards
The default configured guards are the following:
- [NullGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/NullGuard.ts)
_Undefined Guard ensures that the property is not null_
- [UndefinedGuard](https://github.com/ToeFungi/guarder/blob/master/src/guards/UndefinedGuard.ts)
_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_
- [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.
#### Examples
Considering this is a convenience package, the following example highlights reducing line count.
```typescript
// This is
if (property === undefined || property === null) {
throw new Error('Property cannot be null')
}
// Replace by this
Guard.null(property)
// Or this
Guard.null(property, 'Custom Error Message')
// Or this
Guard.null(property, 'Custom Error Message', CustomError)
```
## Usage

@@ -53,0 +94,0 @@

@@ -1,7 +0,5 @@

import { Class } from '../../src/types/Class'
import { Guard } from '../../src/types/Guard'
import { ArgumentError } from '../../src/errors/ArgumentError'
import { Guard, Instantiable, ArgumentError } from '../../src'
class TestGuard implements Guard {
public guard<T = string>(property: T, errorMessage?: string, error?: Class<Error>): T {
public guard<T = string>(property: T, errorMessage?: string, error?: Instantiable<Error>): T {
const message = errorMessage ?? 'Property not allowed to be "foobar"'

@@ -8,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

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.