Socket
Socket
Sign inDemoInstall

@mmit/validate

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mmit/validate - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

lib/validate/validate.d.ts

@@ -32,3 +32,3 @@ declare type Message = () => string;

*/
export declare function notNull<T>(expression: T, message?: Message): T;
export declare function notNull<T>(expression: T, message?: Message): NonNullable<T>;
/**

@@ -35,0 +35,0 @@ * Validate that the specified argument is neither null

{
"name": "@mmit/validate",
"author": "Mike Mitterer",
"version": "0.2.2",
"version": "0.2.3",
"description": "Object validation for/in TS",

@@ -6,0 +6,0 @@ "keywords": [

@@ -14,2 +14,3 @@ # Validate

import * as validate from '@mmit/validate';
validate.isHex('1234567890abcdef');

@@ -22,2 +23,16 @@

validate.isHex('1234567890abcdefg', () => 'My custom message');
type MyName = string | undefined;
const sayMyName = (name: MyName): MyName => name;
// This would lead to: "Type 'string | undefined' is not assignable
// to type 'string'
// const checkedName = (name: MyName): string => sayMyName(name);
// Checked version strips out "undefined"
const checkedName = (name: MyName): string => validate.notNull(sayMyName(name));
expect(checkedName("Mike")).toBe("Mike");
expect(() => checkedName(undefined)).toThrow(ArgumentError);
```

@@ -24,0 +39,0 @@

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

import { loggerFactory } from "../main/config/ConfigLog4j";
import lambi from '../site/images/lambi.png';
import { loggerFactory } from './config/ConfigLog4j';

@@ -4,0 +4,0 @@ const query = (selector: string): HTMLElement => document.querySelector(selector) as HTMLElement;

// Styles für die gesamte Web-App
import '../site/styles/main.scss';
import { loggerFactory } from "../main/config/ConfigLog4j";
import { main } from "./app";
import { main } from './app';
import { loggerFactory } from './config/ConfigLog4j';

@@ -21,18 +21,16 @@ function everythingIsReady() {

if (typeof window !== 'undefined') {
// Mehr: https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
const domIsReadyState = setInterval(() => {
if (/interactive/.test(document.readyState)) {
clearInterval(domIsReadyState);
domIsReady(); // this is the function that gets called when everything is loaded
}
}, 10);
// Mehr: https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
const domIsReadyState = setInterval(() => {
if (/interactive/.test(document.readyState)) {
clearInterval(domIsReadyState);
domIsReady(); // this is the function that gets called when everything is loaded
}
}, 10);
const everythingLoadedState = setInterval(() => {
if (/loaded|complete/.test(document.readyState)) {
clearInterval(everythingLoadedState);
everythingIsReady(); // this is the function that gets called when everything is loaded
}
}, 10);
const everythingLoadedState = setInterval(() => {
if (/loaded|complete/.test(document.readyState)) {
clearInterval(everythingLoadedState);
everythingIsReady(); // this is the function that gets called when everything is loaded
}
}, 10);
}

@@ -55,7 +55,11 @@ import ArgumentError from '../exception/ArgumentError';

*/
export function notNull<T>(expression: T, message: Message = DEFAULT_IS_NULL_MESSAGE): T {
export function notNull<T>(
expression: T,
message: Message = DEFAULT_IS_NULL_MESSAGE,
): NonNullable<T> {
if (expression === null || expression === undefined) {
throw new ArgumentError(message());
}
return expression;
return expression as NonNullable<T>;
}

@@ -62,0 +66,0 @@

@@ -7,2 +7,4 @@ // import { loggerFactory } from '../../main/config/ConfigLog4j';

type MyName = string | undefined;
describe('validate.spec.ts', () => {

@@ -30,2 +32,7 @@ // const logger = loggerFactory.getLogger('test.validate.spec.ts');

const sayMyName = (name: MyName): MyName => name;
const checkedName = (name: MyName): string => validate.notNull(sayMyName(name));
expect(checkedName('Mike')).toBe('Mike');
// tslint:disable-next-line

@@ -36,2 +43,4 @@ expect(() => validate.notNull(null)).toThrow(ArgumentError);

expect(() => validate.notNull(null)).toThrow(error.DEFAULT_IS_NULL_MESSAGE());
expect(() => checkedName(undefined)).toThrow(ArgumentError);
});

@@ -38,0 +47,0 @@

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