Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add predicate functions of basic types like Promise, Date, Iterable, etc. #118

Closed
8 tasks
lambdalisue opened this issue Aug 11, 2024 · 6 comments
Closed
8 tasks
Labels
enhancement New feature or request

Comments

@lambdalisue
Copy link
Member

lambdalisue commented Aug 11, 2024

We can use isInstanceOf or isObjectOf now but for convinience.

  • Promise
  • Date
  • Temporal
  • Worker
  • Iterable
  • AsyncIterable
  • Disposable
  • AsyncDisposable
  • etc.
@lambdalisue lambdalisue added the enhancement New feature or request label Aug 11, 2024
@Milly
Copy link
Collaborator

Milly commented Aug 15, 2024

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
Copy link
Collaborator

Milly commented Aug 15, 2024

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
Copy link
Collaborator

Milly commented Aug 15, 2024

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
Copy link
Member Author

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

@Milly
Copy link
Collaborator

Milly commented Aug 21, 2024

I think null is jsonable

Discussion and implementation of isJsonable in #128.

@lambdalisue
Copy link
Member Author

I changed my mind. It's impossible to define "what is the bacis types".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants