feat: add predicate functions of basic types like `Promise`, `Date`, `Iterable`, etc.
lambdalisue opened this issue ยท 6 comments
lambdalisue commented
We can use isInstanceOf
or isObjectOf
now but for convinience.
-
Promise
-
Date
-
Temporal
-
Worker
-
Iterable
-
AsyncIterable
-
Disposable
-
AsyncDisposable
- etc.
Milly commented
Are they added under is
?
Like:
import { isPromise } from "@core/unknownutil/is/promise";
import { is } from "@core/unknownutil/is";
const x: unknown = 0;
isPromise(x);
is.Promise(x);
Milly commented
type Jsonable = {
/**
* Returns a JSON value that can be specified to {@linkcode JSON.stringify}.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior|toJSON() behavior}
*/
toJSON(key: string | number): unknown;
};
function isJsonable(x: unknown): x is Jsonable {
return x != null && isFunction((x as Jsonable).toJSON);
}
๐ญ I wonder if we define this in unknownutil.
Originally posted by @lambdalisue in vim-denops/deno-denops-std#260 (comment)
Milly commented
const isInstanceOfBoolean = isInstanceOf(Boolean);
const isInstanceOfNumber = isInstanceOf(Number);
const isInstanceOfString = isInstanceOf(String);
๐ญ I wonder if we define these in unknownutil like isBooleanInstance
, etc.
Originally posted by @lambdalisue in vim-denops/deno-denops-std#260 (comment)
lambdalisue commented
type Jsonable = { /** * Returns a JSON value that can be specified to {@linkcode JSON.stringify}. * * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior|toJSON() behavior} */ toJSON(key: string | number): unknown; }; function isJsonable(x: unknown): x is Jsonable { return x != null && isFunction((x as Jsonable).toJSON); }๐ญ I wonder if we define this in unknownutil.
Originally posted by @lambdalisue in vim-denops/deno-denops-std#260 (comment)
I think null is jsonable
lambdalisue commented
I changed my mind. It's impossible to define "what is the bacis types".