diff mbox series

[bug#68941,02/44] guix: build-system: node: Add node-is-type-object helper.

Message ID 20240205231952.26410-2-ngraves@ngraves.fr
State New
Headers show
Series Node : a solution for tiny packages. | expand

Commit Message

Nicolas Graves Feb. 5, 2024, 11:18 p.m. UTC
* guix/build-system/node.scm (node-is-type-object): Add function.

Change-Id: I7027aff3b314cd999798afd8c11dc90ef7c6e43c
---
 guix/build-system/node.scm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Liliana Marie Prikler Feb. 6, 2024, 7:33 p.m. UTC | #1
Am Dienstag, dem 06.02.2024 um 00:18 +0100 schrieb Nicolas Graves:
> * guix/build-system/node.scm (node-is-type-object): Add function.
> 
> Change-Id: I7027aff3b314cd999798afd8c11dc90ef7c6e43c
> ---
>  guix/build-system/node.scm | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm
> index 8a903b4fe5..b52b8f4f3e 100644
> --- a/guix/build-system/node.scm
> +++ b/guix/build-system/node.scm
> @@ -35,8 +35,22 @@ (define-module (guix build-system node)
>              node-build
>              node-build-system
>  
> +            node-is-type-object
>              node-trivial-package))
>  
> +(define* (node-is-type-object type #:optional (type-exists? #t))
> +  "Helper for node packages replacement.  This is actual code
> factorized from
> +the packages it replaces, use with caution.  It doesn't apply to all
> +javascript types."
Which types are excluded?
> +  (string-append
> +   "function(value) {"
> +   (if type-exists?
> +       (string-append
> +        "if (typeof value === '" (string-downcase type) "') {return
> true;} ")
> +       "")
> +   "if (value === null || typeof value !== 'object') {return false;}
> +  return Object.prototype.toString.call(value) === '[object " type
> "]';}"))
> +
I'd call this js-type-object? or perhaps make-js-type-predicate.

Cheers
Nicolas Graves Feb. 18, 2024, 10:58 p.m. UTC | #2
On 2024-02-06 20:33, Liliana Marie Prikler wrote:

> Am Dienstag, dem 06.02.2024 um 00:18 +0100 schrieb Nicolas Graves:
>> * guix/build-system/node.scm (node-is-type-object): Add function.
>>
>> Change-Id: I7027aff3b314cd999798afd8c11dc90ef7c6e43c
>> ---
>>  guix/build-system/node.scm | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm
>> index 8a903b4fe5..b52b8f4f3e 100644
>> --- a/guix/build-system/node.scm
>> +++ b/guix/build-system/node.scm
>> @@ -35,8 +35,22 @@ (define-module (guix build-system node)
>>              node-build
>>              node-build-system
>>  
>> +            node-is-type-object
>>              node-trivial-package))
>>  
>> +(define* (node-is-type-object type #:optional (type-exists? #t))
>> +  "Helper for node packages replacement.  This is actual code
>> factorized from
>> +the packages it replaces, use with caution.  It doesn't apply to all
>> +javascript types."
> Which types are excluded?

Sorry, I haven't seen your email earlier. Basically all types that I've
kept in a true package are in this case. The process was to look the
source code to see if we could use this replacement instead. The
packages where that was not as straightforward I've simply kept the
original packages. This includes for instance : node-is-set,
node-is-map, node-is-callable, node-is-symbol...

>> +  (string-append
>> +   "function(value) {"
>> +   (if type-exists?
>> +       (string-append
>> +        "if (typeof value === '" (string-downcase type) "') {return
>> true;} ")
>> +       "")
>> +   "if (value === null || typeof value !== 'object') {return false;}
>> +  return Object.prototype.toString.call(value) === '[object " type
>> "]';}"))
>> +
> I'd call this js-type-object? or perhaps make-js-type-predicate.

I've renamed this make-js-type-predicate. I'm trying to send an
extensive v2 that would bootstrap up to node-tape instead of just
node-deep-equal.

>
> Cheers
>
>
>
diff mbox series

Patch

diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm
index 8a903b4fe5..b52b8f4f3e 100644
--- a/guix/build-system/node.scm
+++ b/guix/build-system/node.scm
@@ -35,8 +35,22 @@  (define-module (guix build-system node)
             node-build
             node-build-system
 
+            node-is-type-object
             node-trivial-package))
 
+(define* (node-is-type-object type #:optional (type-exists? #t))
+  "Helper for node packages replacement.  This is actual code factorized from
+the packages it replaces, use with caution.  It doesn't apply to all
+javascript types."
+  (string-append
+   "function(value) {"
+   (if type-exists?
+       (string-append
+        "if (typeof value === '" (string-downcase type) "') {return true;} ")
+       "")
+   "if (value === null || typeof value !== 'object') {return false;}
+  return Object.prototype.toString.call(value) === '[object " type "]';}"))
+
 (define* (node-trivial-package node-name version replacement description
                                #:key (propagated-inputs '())
                                (mozilla-doclink #f)  ;maybe-string