From 8be5008bcffc900d162cf363e4c5b2c43dfc40a7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 14 Feb 2023 21:21:04 +0100 Subject: [PATCH 1/2] Docs for Type module --- src/Core__Type.resi | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/Core__Type.resi b/src/Core__Type.resi index f2707a08..21ba455c 100644 --- a/src/Core__Type.resi +++ b/src/Core__Type.resi @@ -1,12 +1,62 @@ +/*** +Utilities for classifying the type of JavaScript values at runtime. +*/ + +/** +The possible types of JavaScript values. +*/ type t = [#undefined | #object | #boolean | #number | #bigint | #string | #symbol | #function] +/** +`typeof(someValue)` + +Returns the underlying JavaScript type of any runtime value. + +See [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) on MDN. + +## Examples +```rescript +Console.log(Type.typeof("Hello")) // Logs "string" to the console. + +let someVariable = true + +switch someVariable->Type.typeof { +| #boolean => Console.log("This is a bool, yay!") +| _ => Console.log("Oh, not a bool sadly...") +} +``` +*/ external typeof: 'a => t = "#typeof" module Classify: { + /*** + Classifies JavaScript runtime values. + */ + + /** + An abstract type representing a JavaScript function. + + See [`function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) on MDN. + */ type function + + /** + An abstract type representing an unknown JavaScript object. + + See [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) on MDN. + */ type object + + /** + An abstract type representing a JavaScript symbol. + + See [`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) on MDN. + */ type symbol + /** + The type representing a classified JavaScript value. + */ type t = | Bool(bool) | Null @@ -17,5 +67,17 @@ module Classify: { | Function(function) | Symbol(symbol) + /** +`classify(anyValue)` +Classifies any value to its underlying JavaScript value. + +## Examples +```rescript +switch %raw(`null`)->Type.Classify.classify { +| Null => Console.log("Yup, that's null.") +| _ => Console.log("This doesn't actually appear to be null...") +} +``` +*/ let classify: 'a => t } From ddff5d7dd602940a8e96434e3f93696d2bf2e064 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 15 Feb 2023 15:52:57 +0100 Subject: [PATCH 2/2] fix PR comments --- src/Core__Type.resi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core__Type.resi b/src/Core__Type.resi index 21ba455c..8bfe4bdf 100644 --- a/src/Core__Type.resi +++ b/src/Core__Type.resi @@ -41,7 +41,7 @@ module Classify: { type function /** - An abstract type representing an unknown JavaScript object. + An abstract type representing a JavaScript object. See [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) on MDN. */ @@ -69,7 +69,7 @@ module Classify: { /** `classify(anyValue)` -Classifies any value to its underlying JavaScript value. +Classifies a JavaScript value. ## Examples ```rescript