ts-object-utils
Advanced tools
Comparing version
@@ -8,3 +8,3 @@ "use strict"; | ||
var ref = obj; | ||
return !(ref || ref === 0); | ||
return !(ref || ref === 0 || ref === false); | ||
}; | ||
@@ -11,0 +11,0 @@ ObjectUtil.isNull = function (obj) { |
{ | ||
"name": "ts-object-utils", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Best type safe way to check null or undefined in typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,8 +0,10 @@ | ||
# ts-null-or-undefined | ||
Best way to check for null or undefined in typescript using a type guard. | ||
# ts-object-utils | ||
Best way to check for null or undefined in typescript using a type guard. Other types also supported. | ||
Can strip out null or undefine or complex types like T | null etc. | ||
`npm install --save ts-object-utils` | ||
To use: | ||
```js | ||
import Type from "ts-null-or-undefined"; | ||
import ObjectUtil from "ts-object-utils"; | ||
@@ -13,5 +15,5 @@ let a: number | null = 0; | ||
if(!Type.isNullOrUndefined(a)){ | ||
if(!ObjectUtil.isNullOrUndefined(a)){ | ||
console.log(a*4); //Works | ||
} | ||
``` |
export class ObjectUtil { | ||
public static isNullOrUndefined<T>(obj: null | undefined | T): obj is null | undefined { | ||
const ref = obj as any; | ||
return !(ref || ref === 0); | ||
return !(ref || ref === 0 || ref === false); | ||
} | ||
@@ -6,0 +6,0 @@ public static isNull(obj: any): obj is null { |
Sorry, the diff of this file is not supported yet
5932
2.1%19
11.76%