Socket
Socket
Sign inDemoInstall

@sindresorhus/is

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sindresorhus/is - npm Package Compare versions

Comparing version 6.1.0 to 6.2.0

6

dist/index.d.ts

@@ -9,3 +9,3 @@ /// <reference types="node" resolution-mode="require"/>

export type TypeName = ObjectTypeName | PrimitiveTypeName;
declare const assertionTypeDescriptions: readonly ["positive number", "negative number", "Class", "string with a number", "null or undefined", "Iterable", "AsyncIterable", "native Promise", "EnumCase", "string with a URL", "truthy", "falsy", "primitive", "integer", "plain object", "TypedArray", "array-like", "tuple-like", "Node.js Stream", "infinite number", "empty array", "non-empty array", "empty string", "empty string or whitespace", "non-empty string", "non-empty string and not whitespace", "empty object", "non-empty object", "empty set", "non-empty set", "empty map", "non-empty map", "PropertyKey", "even integer", "odd integer", "T", "in range", "predicate returns truthy for any value", "predicate returns truthy for all values", "valid length", "whitespace string", "Function", "Generator", "AsyncGenerator", "GeneratorFunction", "AsyncGeneratorFunction", "AsyncFunction", "Observable", "Array", "Buffer", "Blob", "Object", "RegExp", "Date", "Error", "Map", "Set", "WeakMap", "WeakSet", "WeakRef", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Promise", "URL", "FormData", "URLSearchParams", "HTMLElement", "NaN", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "null", "undefined", "string", "number", "bigint", "boolean", "symbol"];
declare const assertionTypeDescriptions: readonly ["positive number", "negative number", "Class", "string with a number", "null or undefined", "Iterable", "AsyncIterable", "native Promise", "EnumCase", "string with a URL", "truthy", "falsy", "primitive", "integer", "plain object", "TypedArray", "array-like", "tuple-like", "Node.js Stream", "infinite number", "empty array", "non-empty array", "empty string", "empty string or whitespace", "non-empty string", "non-empty string and not whitespace", "empty object", "non-empty object", "empty set", "non-empty set", "empty map", "non-empty map", "PropertyKey", "even integer", "odd integer", "T", "in range", "predicate returns truthy for any value", "predicate returns truthy for all values", "valid Date", "valid length", "whitespace string", "Function", "Generator", "AsyncGenerator", "GeneratorFunction", "AsyncGeneratorFunction", "AsyncFunction", "Observable", "Array", "Buffer", "Blob", "Object", "RegExp", "Date", "Error", "Map", "Set", "WeakMap", "WeakSet", "WeakRef", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Promise", "URL", "FormData", "URLSearchParams", "HTMLElement", "NaN", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "null", "undefined", "string", "number", "bigint", "boolean", "symbol"];
export type AssertionTypeDescription = typeof assertionTypeDescriptions[number];

@@ -107,2 +107,3 @@ declare function detect(value: unknown): TypeName;

urlString: typeof isUrlString;
validDate: typeof isValidDate;
validLength: typeof isValidLength;

@@ -200,2 +201,3 @@ weakMap: typeof isWeakMap;

export declare function isUrlString(value: unknown): value is string;
export declare function isValidDate(value: unknown): value is Date;
export declare function isValidLength(value: unknown): value is number;

@@ -296,2 +298,3 @@ export declare function isWeakMap<Key extends object = object, Value = unknown>(value: unknown): value is WeakMap<Key, Value>;

urlSearchParams: (value: unknown) => asserts value is URLSearchParams;
validDate: (value: unknown) => asserts value is Date;
validLength: (value: unknown) => asserts value is number;

@@ -391,2 +394,3 @@ whitespaceString: (value: unknown) => asserts value is string;

export declare function assertUrlString(value: unknown): asserts value is string;
export declare function assertValidDate(value: unknown): asserts value is Date;
export declare function assertValidLength(value: unknown): asserts value is number;

@@ -393,0 +397,0 @@ export declare function assertWeakMap<Key extends object = object, Value = unknown>(value: unknown): asserts value is WeakMap<Key, Value>;

@@ -103,2 +103,3 @@ const typedArrayTypeNames = [

'predicate returns truthy for all values',
'valid Date',
'valid length',

@@ -262,2 +263,3 @@ 'whitespace string',

urlString: isUrlString,
validDate: isValidDate,
validLength: isValidLength,

@@ -600,2 +602,5 @@ weakMap: isWeakMap,

}
export function isValidDate(value) {
return isDate(value) && !isNan(Number(value));
}
export function isValidLength(value) {

@@ -731,2 +736,3 @@ return isSafeInteger(value) && value >= 0;

urlString: assertUrlString,
validDate: assertValidDate,
validLength: assertValidLength,

@@ -823,2 +829,3 @@ weakMap: assertWeakMap,

isUrlString: 'string with a URL',
isValidDate: 'valid Date',
isValidLength: 'valid length',

@@ -1271,2 +1278,7 @@ isWeakMap: 'WeakMap',

}
export function assertValidDate(value) {
if (!isValidDate(value)) {
throw new TypeError(typeErrorMessage('valid Date', value));
}
}
export function assertValidLength(value) {

@@ -1273,0 +1285,0 @@ if (!isValidLength(value)) {

4

package.json
{
"name": "@sindresorhus/is",
"version": "6.1.0",
"version": "6.2.0",
"description": "Type check values",

@@ -16,2 +16,3 @@ "license": "MIT",

"types": "./dist/index.d.ts",
"sideEffects": false,
"engines": {

@@ -68,3 +69,2 @@ "node": ">=16"

},
"sideEffects": false,
"ava": {

@@ -71,0 +71,0 @@ "extensions": {

@@ -453,7 +453,7 @@ # is

#### .positiveNumber(value)
##### .positiveNumber(value)
Check if `value` is a number and is more than 0.
#### .negativeNumber(value)
##### .negativeNumber(value)

@@ -578,2 +578,32 @@ Check if `value` is a number and is less than 0.

##### .validDate(value)
Returns `true` if the value is a valid date.
All [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) objects have an internal timestamp value which is the number of milliseconds since the [Unix epoch](https://developer.mozilla.org/en-US/docs/Glossary/Unix_time). When a new `Date` is constructed with bad inputs, no error is thrown. Instead, a new `Date` object is returned. But the internal timestamp value is set to `NaN`, which is an `'Invalid Date'`. Bad inputs can be an non-parsable date string, a non-numeric value or a number that is outside of the expected range for a date value.
```js
const valid = new Date('2000-01-01');
is.date(valid);
//=> true
valid.getTime();
//=> 946684800000
valid.toUTCString();
//=> 'Sat, 01 Jan 2000 00:00:00 GMT'
is.validDate(valid);
//=> true
const invalid = new Date('Not a parsable date string');
is.date(invalid);
//=> true
invalid.getTime();
//=> NaN
invalid.toUTCString();
//=> 'Invalid Date'
is.validDate(invalid);
//=> false
```
##### .validLength(value)

@@ -707,8 +737,2 @@

## For enterprise
Available as part of the Tidelift Subscription.
The maintainers of @sindresorhus/is and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-sindresorhus-is?utm_source=npm-sindresorhus-is&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
## Related

@@ -715,0 +739,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