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

ts-runtime-typecheck

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-runtime-typecheck - npm Package Compare versions

Comparing version 2.4.2 to 2.5.0

cjs/Definition.type.d.ts

1

cjs/index.d.ts

@@ -22,2 +22,3 @@ export * from './type-cast/as-json';

export { invariant } from './invariant';
export { inspectType } from './inspectType';
export type { Index, Indexable } from './Index.type';

@@ -24,0 +25,0 @@ export type { Primitive } from './Primitive.type';

@@ -26,2 +26,3 @@ 'use strict';

var invariant = require('./invariant.js');
var inspectType = require('./inspectType.js');

@@ -138,2 +139,3 @@

exports.invariant = invariant.invariant;
exports.inspectType = inspectType.inspectType;
//# sourceMappingURL=index.js.map

3

cjs/type-cast/as-primitive.js

@@ -5,2 +5,3 @@ 'use strict';

var inspectType = require('../inspectType.js');
var isPrimitive = require('../type-check/is-primitive.js');

@@ -25,3 +26,3 @@ var typeCast = require('./type-cast.js');

}
throw new Error(`Unable to cast ${typeof obj} to NonNullable<unknown>`);
throw new Error(`Unable to cast ${inspectType.inspectType(obj)} to NonNullable<unknown>`);
}

@@ -28,0 +29,0 @@ const asOptString = typeCast.optTypeCast(isPrimitive.isString);

@@ -6,2 +6,3 @@ 'use strict';

var isPrimitive = require('../type-check/is-primitive.js');
var inspectType = require('../inspectType.js');

@@ -17,3 +18,3 @@ function optTypeCast(isType) {

}
throw new Error(`Unable to cast ${typeof obj} to Optional<${(_a = isType.TYPE_NAME) !== null && _a !== void 0 ? _a : 'unknown'}>`);
throw new Error(`Unable to cast ${inspectType.inspectType(obj)} to Optional<${(_a = isType.TYPE_NAME) !== null && _a !== void 0 ? _a : 'unknown'}>`);
};

@@ -30,3 +31,3 @@ }

}
throw new Error(`Unable to cast ${typeof obj} to ${(_a = isType.TYPE_NAME) !== null && _a !== void 0 ? _a : 'unknown'}`);
throw new Error(`Unable to cast ${inspectType.inspectType(obj)} to ${(_a = isType.TYPE_NAME) !== null && _a !== void 0 ? _a : 'unknown'}`);
};

@@ -33,0 +34,0 @@ }

@@ -5,2 +5,3 @@ 'use strict';

var inspectType = require('../inspectType.js');
var isPrimitive = require('../type-check/is-primitive.js');

@@ -15,3 +16,3 @@

}
throw new Error(`Unable to cast ${typeof obj} to String`);
throw new Error(`Unable to cast ${inspectType.inspectType(obj)} to String`);
}

@@ -23,3 +24,3 @@ function makeNumber(obj) {

if (isPrimitive.isString(obj)) {
const value = parseFloat(obj);
const value = +obj;
if (!isNaN(value)) {

@@ -32,3 +33,3 @@ return value;

}
throw new Error(`Unable to cast ${typeof obj} to Number`);
throw new Error(`Unable to cast ${inspectType.inspectType(obj)} to Number`);
}

@@ -50,3 +51,3 @@ function makeBoolean(obj) {

}
throw new Error(`Unable to cast ${typeof obj} to Boolean`);
throw new Error(`Unable to cast ${inspectType.inspectType(obj)} to Boolean`);
}

@@ -53,0 +54,0 @@

@@ -22,2 +22,3 @@ export * from './type-cast/as-json';

export { invariant } from './invariant';
export { inspectType } from './inspectType';
export type { Index, Indexable } from './Index.type';

@@ -24,0 +25,0 @@ export type { Primitive } from './Primitive.type';

{
"name": "ts-runtime-typecheck",
"version": "2.4.2",
"version": "2.5.0",
"description": "A collection of common types for TypeScript along with dynamic type cast methods.",

@@ -20,12 +20,12 @@ "main": "cjs/index.js",

"devDependencies": {
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"eslint": "^8.2.0",
"jest": "^27.3.1",
"rollup": "^2.59.0",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4"
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"eslint": "^8.6.0",
"jest": "^27.4.5",
"rollup": "^2.63.0",
"rollup-plugin-typescript2": "^0.31.1",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
}
}

@@ -42,3 +42,5 @@ # ts-runtime-typecheck

- [Reference: Type Assert](#reference-type-assert)
- [Reference: Helper functions](#reference-helper-functions)
- [Reference: Types](#reference-types)
- [Changelog](#changelog)

@@ -56,2 +58,4 @@ - [v1.0.0](#v100)

- [v2.3.0](#230)
- [v2.4.0](#240)
- [v2.5.0](#250)

@@ -901,2 +905,29 @@ ## Type Casts

- ### inspectType
Inspects the type of a given value and returns a description of it as a string. Useful for constructing debug messages from unknown values. Instances of classes are described using the name of their class. Abstract objects are traversed recursively so that their elements can be described as well. Recursion uses a depth limit to prevent overlarge descriptions. Once the limit has been reached abstract objects will be described as `Dictionary`.
An optional second argument can be passed to modify the default behaviour. For example you can change the `maxDepth` limit from it's default of `3`; a value of `0` would prevent recursion whereas `Infinity` would remove the limit.
Arrays currently do not feature recursive type description, but this might be introduced in future.
Internally this is used to describe values in type error messages.
```typescript
import { inspectType } from 'ts-runtime-typecheck';
class Example {}
inspectType('hello world'); // string
inspectType(null) // null
inspectType([]) // Array
inspectType(new Example) // Example
inspectType({}) // {}
inspectType({
foo: 'hello',
bar: 'world'
}) // { foo: string, bar: string }
inspectType({ foo: 'bar' }, { maxDepth: 0 }); // Dictionary
```
### Reference: Types

@@ -1051,1 +1082,7 @@

- Documentation: Correct some typos in the `isStruct`/`asStruct` examples
### 2.5.0
- Add: `inspectType` function to describe the type of a value
- Fix: `makeNumber` no longer returns a number strings prefixed with a number
- Change: Type error messages now use the more descriptive `inspectType` instead of `typeof` for erroneous values

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

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