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

typescanner

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescanner - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

6

package.json
{
"name": "typescanner",
"version": "0.2.0",
"version": "0.2.1",
"description": "A simple library for implementing type guards in TypeScript.",

@@ -10,2 +10,6 @@ "author": "yona3",

},
"keywords": [
"typescript",
"type-guard"
],
"bugs": {

@@ -12,0 +16,0 @@ "url": "https://github.com/yona3/typescanner/issues"

41

README.md

@@ -95,6 +95,9 @@ # typescanner

list(["a", "b", "c"]); // "a" | "b" | "c"
// Pass a constructor as argument
instanceOf(Error)
```
### scanner
`scanner` is a function for implementing type guard for Objects. It returns a `Condition` of the type defined in Type Aliase by setting a field to the value of each property.
`scanner` is a function to implement type guard for objects. It returns a "type guard function" of the type defined by Type Aliase by setting a field to the value of each property.
```ts

@@ -111,4 +114,9 @@ type Foo = {

i: string | number;
j: number;
};
// You can extend fields by defining your own type guard functions.
const even = (value: unknown): value is number =>
isNumber(value) && value % 2 === 0;
const isFoo = scanner<Foo>({

@@ -124,2 +132,3 @@ a: string,

i: union<string | number>(string, number),
j: even, // Custom field
});

@@ -135,2 +144,3 @@

g: "a",
j: 2,
} as unknown;

@@ -155,5 +165,8 @@

### primitive
### other
Basic type guard functions with function names beginning with "is".
```ts
// primitive
isString("a")

@@ -174,7 +187,5 @@

isBigint(BigInt(1))
```
### isArray
// isArray
```ts
isArray(["a", "b"], isString) // string[]

@@ -185,15 +196,11 @@

isArray(["a", null, undefined], isString, isNull, isUndefined) // (string | null | undefined)[]
```
### isOptional
// isOptional
```ts
isOptional("a", isString) // true
isOptional(undefined, isString) // true
```
### isList
// isList
```ts
const Lang = {

@@ -207,3 +214,13 @@ ja: "ja",

isList("ja", langList)
isList("ja", langList) // true
// isInstanceOf
try {
...
} catch (error) {
if (isInstanceOf(error, Error)) {
error.message // OK
}
}
```

@@ -210,0 +227,0 @@

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