
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
type-inspect
Advanced tools
The TypeInspect module returns information about the data type of a Javascript object. It inspects any supported datatype and returns an object with the type
, which is a typeof call, kind
the real data type and the value
.
import TypeInspect from 'type-inspect'
const inspected = TypeInspect.inspect('foo')
// inspected === {
// type: 'string',
// kind: 'string',
// value: 'foo'
// }
const inspected = TypeInspect.inspect({ bla: 'blubb' })
// inspected === {
// type: 'object',
// kind: 'object',
// value: {
// bla: {
// type: 'string',
// kind: 'string'
// value: 'blubb'
// }
// }
// }
const inspected = TypeInspect.inspect(['one', 2])
// inspected === {
// type: 'object',
// kind: 'array',
// value: [
// { type: 'string', kind: 'string', value: 'one' },
// { type: 'number', kind: 'number', value: 2 }
// ]
// }
Input | Type | Kind | Description |
---|---|---|---|
undefined | undefined | undefined | Javascripts undefined property |
null | object | null | Javascripts null object |
number | number | number | Number object |
NaN | number | nan | NaN object |
string | string | string | String object |
boolean | boolean | boolean | Boolean object |
object | object | object | Object object |
regexp | object | regexp | Reguler expression object |
array | object | array | Array Object |
date | object | date | Date object |
map | object | map | Map object |
set | object | set | Set object |
promise | object | promise | Promise object |
function | function | function | Function Object |
generator | function | generator | Generator function object |
async | function | async | Async function object |
class | function | class | Class object |
The diff method goes recursive through two input values and calculates the difference. It returns an instance of TypeDiff
const left = {
bla: 'Bla',
blub: 'Blubb',
blob: undefined
}
const right = {
bla: 'Bla',
blub: 'Blobb',
blab: null
}
const diff = TypeInspect.diff(left, right)
diff.print()
** obj diffResult**
Holds the diff result.
{
type: 'object',
kind: 'object',
values: [{
type: 'string',
kind: 'string',
value: 'Bla',
key: 'bla',
isDifferent: false
}, {
type: 'string',
kind: 'string',
valueAdded: 'Blubb',
valueRemoved: 'Blobb',
key: 'blub',
isDifferent: true
}, {
type: 'undefined',
typeAdded: 'undefined',
kind: 'undefined',
kindAdded: 'undefined',
value: undefined,
key: 'blob',
keyAdded: 'blob',
isDifferent: true
}, {
type: 'object',
typeRemoved: 'object',
kind: 'null',
kindRemoved: 'null',
valueAdded: undefined,
valueRemoved: null,
key: 'blab',
keyRemoved: 'blab',
isDifferent: true
}],
isDifferent: true
}
diff(any left, any right)
Compares two datatypes and returns a TypeDiff instance. The flag isDifferent
indicates that the node or the node's child has differences. You can check the flag on the root level to make sure the whole trees are identical or not.
print([bool printColors])
Print diff result.
parse([bool printColors])
Parse a diff result and returns value as string.
With version v2.2.0
matcher support was introduced. A matcher allows to match a value by it's data type, it can be placed in the right side of a diff call.
const {Matcher, TypeInspect} = require('type-inspect')
const left = {
name: 'Banana',
isFruit: true
}
const matcher = new Matcher()
const right = {
name: matcher.isString(),
isFruit: matcher.isBoolean()
}
const diff = TypeInspect.diff(left, right)
if (diff.isDifferent === false) {
console.log('Left and right is identical')
}
Name | Description |
---|---|
isArray() | Value is a Array |
isAsync() | Value is a Async function |
isBoolean() | Value is a Boolean |
isClass() | Value is a Class |
isDate() | Value is a Date |
isFunction() | Value is a Function |
isGenerator() | Value is a Generator function |
isMap() | Value is a Map |
isNaN() | Value is NaN |
isNull() | Value is null object |
isNumber() | Value is a Number |
isObject() | Value is an Object |
isPromise() | Value is a Promise |
isRegExp() | Value is a reguler expression |
isSet() | Value is a Set |
isString() | Value is a String |
isUndefined() | Value is undefined |
FAQs
Type Inspector
The npm package type-inspect receives a total of 1,007 weekly downloads. As such, type-inspect popularity was classified as popular.
We found that type-inspect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.