New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.3.0 to 0.5.0

12

lib/Guarder.d.ts

@@ -14,7 +14,7 @@ import { Guard } from './types/Guard';

*/
static null<T = any>(property: T, message?: string, error?: Instantiable<Error>): T;
static null<T = unknown>(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?: Instantiable<Error>): T;
static undefined<T = unknown>(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?: Instantiable<Error>): T;
static empty<T = unknown>(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?: Instantiable<Error>): T;
static falsy<T = unknown>(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?: Instantiable<Error>): T;
static custom<T = unknown>(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: Instantiable<Guard>, property: T, message?: string, error?: Instantiable<Error>): T;
static guard<T = unknown>(guard: Instantiable<Guard>, property: T, message?: string, error?: Instantiable<Error>): T;
/**

@@ -43,0 +43,0 @@ * Get all registered guards

@@ -56,3 +56,3 @@ "use strict";

*/
static inlineCustom(guard, property, message, error) {
static guard(guard, property, message, error) {
const customGuard = new guard();

@@ -59,0 +59,0 @@ return customGuard.guard(property, message, error);

@@ -11,3 +11,6 @@ import { Guard } from '../types/Guard';

*/
guard<T = any>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
guard<T = unknown>(property: T, errorMessage?: string, error?: Instantiable<Error>): T;
/**
* Throw the error with the error message
*/
private failed;

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

@@ -28,6 +28,8 @@ "use strict";

}
/**
* Throw the error with the error message
*/
failed(message, error) {
if (error) {
if (error)
throw new error(message);
}
throw new ArgumentError_1.ArgumentError(message);

@@ -34,0 +36,0 @@ }

@@ -10,5 +10,5 @@ import { Guard } from '../types/Guard';

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

@@ -14,5 +14,4 @@ "use strict";

if (!(!!property)) {
if (error) {
if (error)
throw new error(message);
}
throw new ArgumentError_1.ArgumentError(message);

@@ -19,0 +18,0 @@ }

@@ -10,5 +10,5 @@ import { Guard } from '../types/Guard';

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

@@ -14,5 +14,4 @@ "use strict";

if (property === null) {
if (error) {
if (error)
throw new error(message);
}
throw new ArgumentError_1.ArgumentError(message);

@@ -19,0 +18,0 @@ }

@@ -10,5 +10,5 @@ import { Guard } from '../types/Guard';

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

@@ -14,5 +14,4 @@ "use strict";

if (property === undefined) {
if (error) {
if (error)
throw new error(message);
}
throw new ArgumentError_1.ArgumentError(message);

@@ -19,0 +18,0 @@ }

@@ -9,5 +9,5 @@ import { Instantiable } from './Instantiable';

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

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

@@ -21,11 +21,11 @@ # Guarder

- [Usage](#usage)
- [Null Guard](#nullt--anyproperty-t-message-string-error-classerror-t)
- [Undefined Guard](#undefinedt--anyproperty-t-message-string-error-classerror-t)
- [Empty Guard](#emptyt--anyproperty-t-message-string-error-classerror-t)
- [Falsy Guard](#falsyt--anyproperty-t-message-string-error-classerror-t)
- [Get Registered Guards](#getregisteredguards-string)
- [Unregister Guard](#unregisterguardguardname-string-void)
- [Register Guard](#registerguardguardname-string-guard-classguard-void)
- [Custom Guards](#customt--anyguardname-string-property-t-message-string-error-classerror-t)
- [Inline Custom Guards](#inlinecustomt--anyguard-guard-property-t-message-string-error-classerror-t)
- [Null Guard](#nullproperty-t-message-string-error-instantiable)
- [Undefined Guard](#undefinedproperty-t-message-string-error-instantiable)
- [Empty Guard](#emptyproperty-t-message-string-error-instantiable)
- [Falsy Guard](#falsyproperty-t-message-string-error-instantiable)
- [Get Registered Guards](#getregisteredguards)
- [Unregister Guard](#unregisterguardguardname-string)
- [Register Guard](#registerguardguardname-string-guard-instantiable)
- [Custom Guards](#customguardname-string-property-t-message-string-error-instantiable)
- [Inline Custom Guards](#guardguard-guard-property-t-message-string-error-instantiable)
- [Tests](#tests)

@@ -94,3 +94,3 @@ - [Issues](#issues)

#### null<T = any>(property: T, message?: string, error?: Class<Error>): T
#### .null(property: T, message?: string, error?: Instantiable)

@@ -115,3 +115,3 @@ You can validate that the specified property is not `null` using the `.null` guard and specify the error message and

#### undefined<T = any>(property: T, message?: string, error?: Class<Error>): T
#### .undefined(property: T, message?: string, error?: Instantiable)

@@ -136,3 +136,3 @@ You can validate that the specified property is not `undefined` using the `.undefined` guard and specify the error

#### empty<T = any>(property: T, message?: string, error?: Class<Error>): T
#### .empty(property: T, message?: string, error?: Instantiable)

@@ -164,3 +164,3 @@ You can validate that the specified property is not `empty` using the `.empty` guard and specify the error message and

#### falsy<T = any>(property: T, message?: string, error?: Class<Error>): T
#### .falsy(property: T, message?: string, error?: Instantiable)

@@ -185,3 +185,3 @@ You can guard against values that evaluate to false in type coercion.

#### getRegisteredGuards(): string[]
#### .getRegisteredGuards()

@@ -197,3 +197,3 @@ You can retrieve the list of registered guards to validate the guard functionality available. By default, the `empty`,

#### unregisterGuard(guardName: string): void
#### .unregisterGuard(guardName: string)

@@ -211,3 +211,3 @@ You can unregister a specific guard by name. This will remove the guard from the map and it will no longer be available

#### registerGuard(guardName: string, guard: Class<Guard>): void
#### .registerGuard(guardName: string, guard: Instantiable)

@@ -224,3 +224,3 @@ You can register guards and specify the guard name. This allows you to build custom guards and register them for use.

#### custom<T = any>(guardName: string, property: T, message?: string, error?: Class<Error>): T
#### .custom(guardName: string, property: T, message?: string, error?: Instantiable)

@@ -236,3 +236,3 @@ You can use your custom guard after it is registered with the `custom` functionality. You need to specify which guard

#### inlineCustom<T = any>(guard: Guard, property: T, message?: string, error?: Class<Error>): T
#### .guard(guard: Guard, property: T, message?: string, error?: Instantiable)

@@ -239,0 +239,0 @@ You can specify the guard to use as a once off guard without needing to register it using the `inlineCustom` mechanism.

@@ -97,3 +97,3 @@ import { EmptyGuard } from '../../../lib'

describe('#inlineCustom', () => {
describe('#guard', () => {
const property = 'foobar'

@@ -104,3 +104,3 @@

return Guarder.inlineCustom(TestGuard, property)
return Guarder.guard(TestGuard, property)
.should.deep.equal(property)

@@ -111,3 +111,3 @@ })

try {
Guarder.inlineCustom(TestGuard, property, customMessage, TestError)
Guarder.guard(TestGuard, property, customMessage, TestError)
} catch (error) {

@@ -121,3 +121,3 @@ error.should.be.instanceOf(TestError)

try {
Guarder.inlineCustom(TestGuard, property)
Guarder.guard(TestGuard, property)
} catch (error) {

@@ -124,0 +124,0 @@ error.should.be.instanceOf(ArgumentError)

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

  • 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