aed2ead7197bce131db72156b339a87c01bd44fb
[jackhill/guix/guix.git] / gnu / packages / javascript.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net>
3 ;;; Copyright © 2017, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2017, 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2017, 2018, 2019, 2020 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages javascript)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (gnu packages)
26 #:use-module (gnu packages base)
27 #:use-module (gnu packages compression)
28 #:use-module (gnu packages lisp-xyz)
29 #:use-module (gnu packages readline)
30 #:use-module (gnu packages web)
31 #:use-module (guix packages)
32 #:use-module (guix download)
33 #:use-module (guix git-download)
34 #:use-module (guix build-system gnu)
35 #:use-module (guix build-system cmake)
36 #:use-module (guix build-system trivial)
37 #:use-module (guix build-system minify)
38 #:use-module (guix utils))
39
40 (define-public cjson
41 (package
42 (name "cjson")
43 (version "1.7.14")
44 (source (origin
45 (method git-fetch)
46 (uri (git-reference
47 (url "https://github.com/DaveGamble/cJSON")
48 (commit (string-append "v" version))))
49 (file-name (git-file-name name version))
50 (sha256
51 (base32 "1rlnailhjm180zb6pc17jwphjwivw8kfpqgixjfgq4iyryq46sah"))))
52 (build-system cmake-build-system)
53 (arguments
54 `(#:configure-flags '("-DENABLE_CJSON_UTILS=On")))
55 (home-page "https://github.com/DaveGamble/cJSON")
56 (synopsis "JSON parser written in ANSI C")
57 (description "This library provides a portable embeddable JSON parser.")
58 (license license:expat)))
59
60 (define-public js-context-menu
61 (package
62 (name "js-context-menu")
63 (version "0.6.1")
64 (source
65 (origin
66 (method git-fetch)
67 (uri (git-reference
68 (url "https://github.com/zorkow/context-menu")
69 (commit (string-append "v" version))))
70 (file-name (git-file-name name version))
71 (sha256
72 (base32
73 "1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh"))))
74 (build-system trivial-build-system)
75 (arguments
76 `(#:modules ((guix build utils))
77 #:builder
78 (begin
79 (use-modules (guix build utils))
80 (chdir (assoc-ref %build-inputs "source"))
81 (let ((target (string-append %output "/share/javascript/context-menu")))
82 (apply invoke (string-append (assoc-ref %build-inputs "esbuild")
83 "/bin/esbuild")
84 "--bundle"
85 "--tsconfig=tsconfig.json"
86 (string-append "--outdir=" target)
87 (find-files "ts" "\\.ts$"))))))
88 (native-inputs
89 `(("esbuild" ,esbuild)))
90 (home-page "https://github.com/zorkow/context-menu")
91 (synopsis "Generic context menu")
92 (description "This package provides a reimplementation of the MathJax
93 context menu in TypeScript.")
94 (license license:asl2.0)))
95
96 (define-public font-mathjax
97 (package
98 (name "font-mathjax")
99 (version "2.7.2")
100 (source
101 (origin
102 (method git-fetch)
103 (uri (git-reference
104 (url "https://github.com/mathjax/MathJax")
105 (commit version)))
106 (file-name (git-file-name name version))
107 (sha256
108 (base32
109 "127j12g7v2hx6k7r00b8cp49s7nkrwhxy6l8p03pw34xpxbgbimm"))))
110 (build-system trivial-build-system)
111 (arguments
112 `(#:modules ((guix build utils))
113 #:builder
114 (begin
115 (use-modules (guix build utils)
116 (ice-9 match))
117 (let ((install-directory (string-append %output "/share/fonts/mathjax")))
118 (mkdir-p install-directory)
119 (copy-recursively (string-append (assoc-ref %build-inputs "source")
120 "/fonts")
121 install-directory)))))
122 (home-page "https://www.mathjax.org/")
123 (synopsis "Fonts for MathJax")
124 (description "This package contains the fonts required for MathJax.")
125 (license license:asl2.0)))
126
127 (define-public js-mathjax
128 (package
129 (inherit font-mathjax)
130 (name "js-mathjax")
131 (arguments
132 `(#:modules ((guix build utils))
133 #:builder
134 (begin
135 (use-modules (guix build utils)
136 (ice-9 match)
137 (ice-9 popen)
138 (ice-9 regex))
139 (set-path-environment-variable
140 "PATH" '("bin") (map (match-lambda
141 ((_ . input)
142 input))
143 %build-inputs))
144 (set-path-environment-variable
145 "GUIX_LOCPATH" '("lib/locale")
146 (list (assoc-ref %build-inputs "glibc-utf8-locales")))
147 (setenv "LANG" "en_US.UTF-8")
148 (let ((install-directory (string-append %output "/share/javascript/mathjax")))
149 (copy-recursively (string-append (assoc-ref %build-inputs "source") "/unpacked")
150 "MathJax-unpacked")
151 (mkdir-p install-directory)
152 (symlink (string-append (assoc-ref %build-inputs "font-mathjax")
153 "/share/fonts/mathjax")
154 (string-append install-directory "/fonts"))
155
156 (for-each
157 (lambda (file)
158 (let ((installed (string-append install-directory
159 ;; remove prefix "./MathJax-unpacked"
160 (string-drop file 18))))
161 (format #t "~a -> ~a~%" file installed)
162 (cond
163 ((string-match "\\.js$" file)
164 (mkdir-p (dirname installed))
165 (let ((minified (open-pipe* OPEN_READ "uglify-js" file)))
166 (call-with-output-file installed
167 (lambda (port)
168 (dump-port minified port)))
169
170 (let ((exit (close-pipe minified)))
171 (unless (zero? exit)
172 (error "dear, uglify-js failed" exit)))))
173 (else
174 (install-file file (dirname installed))))))
175 (find-files "."))
176
177 #t))))
178 (native-inputs
179 `(("font-mathjax" ,font-mathjax)
180 ("glibc-utf8-locales" ,glibc-utf8-locales)
181 ("uglify-js" ,uglify-js)
182 ,@(package-native-inputs font-mathjax)))
183 (synopsis "JavaScript display engine for LaTeX, MathML, and AsciiMath")
184 (description "MathJax is a JavaScript display engine for LaTeX, MathML,
185 and AsciiMath notation that works in all modern browsers. It requires no
186 plugins or software to be installed on the browser. So the page author can
187 write web documents that include mathematics and be confident that readers will
188 be able to view it naturally and easily.")))
189
190 (define-public js-commander
191 (package
192 (name "js-commander")
193 (version "6.2.1")
194 (source
195 (origin
196 (method git-fetch)
197 (uri (git-reference
198 (url "https://github.com/tj/commander.js")
199 (commit (string-append "v" version))))
200 (file-name (git-file-name name version))
201 (sha256
202 (base32
203 "126m25s6mxpxmdj4aw5awz06b47r8r798lcf1c5bnmmh39cik5i1"))))
204 (build-system trivial-build-system)
205 (arguments
206 `(#:modules ((guix build utils))
207 #:builder
208 (begin
209 (use-modules (guix build utils))
210 (chdir (assoc-ref %build-inputs "source"))
211 (let ((esbuild (string-append (assoc-ref %build-inputs "esbuild")
212 "/bin/esbuild"))
213 (target (string-append %output "/share/javascript/commander")))
214 (invoke esbuild
215 "--bundle"
216 "--minify"
217 "--tsconfig=tsconfig.json"
218 "--platform=node"
219 (string-append "--outfile=" target "/index.min.js")
220 "index.js")))))
221 (native-inputs
222 `(("esbuild" ,esbuild)))
223 (home-page "https://github.com/tj/commander.js")
224 (synopsis "Library for node.js command-line interfaces")
225 (description "Commander.js aims to be the complete solution for node.js
226 command-line interfaces. ")
227 (license license:expat)))
228
229 (define-public js-respond
230 (package
231 (name "js-respond")
232 (version "1.4.2")
233 (source (origin
234 (method git-fetch)
235 (uri (git-reference
236 (url "https://github.com/scottjehl/Respond")
237 (commit version)))
238 (file-name (git-file-name name version))
239 (sha256
240 (base32
241 "00xid731rirc7sdy1gc8qal3v9g0agr2qx15hm4x97l1lcbylyn2"))))
242 (build-system minify-build-system)
243 (arguments
244 `(#:javascript-files '("src/matchmedia.addListener.js"
245 "src/matchmedia.polyfill.js"
246 "src/respond.js")))
247 (home-page "https://github.com/scottjehl/Respond")
248 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
249 (description "The goal of this script is to provide a fast and lightweight
250 script to enable responsive web designs in browsers that don't support CSS3
251 Media Queries.")
252 (license license:expat)))
253
254 (define-public js-html5shiv
255 (package
256 (name "js-html5shiv")
257 (version "3.7.3")
258 (source (origin
259 (method git-fetch)
260 (uri (git-reference
261 (url "https://github.com/aFarkas/html5shiv")
262 (commit version)))
263 (file-name (git-file-name name version))
264 (sha256
265 (base32
266 "0y1c5nyq0brl9fjdihhax33vks4s1ij9iv113879sg3zflmgqpd0"))))
267 (build-system minify-build-system)
268 (home-page "https://github.com/aFarkas/html5shiv")
269 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
270 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
271 legacy Internet Explorer and provides basic HTML5 styling for Internet
272 Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
273 ;; From the file "MIT and GPL2 licenses.md":
274 ;;
275 ;; This software is licensed under a dual license system (MIT or GPL
276 ;; version 2). This means you are free to choose with which of both
277 ;; licenses (MIT or GPL version 2) you want to use this library.
278 (license (list license:expat license:gpl2))))
279
280 (define-public js-json2
281 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
282 (revision "1"))
283 (package
284 (name "js-json2")
285 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
286 (source (origin
287 (method git-fetch)
288 (uri (git-reference
289 (url "https://github.com/douglascrockford/JSON-js")
290 (commit commit)))
291 (file-name (string-append name "-" version "-checkout"))
292 (sha256
293 (base32
294 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
295 (build-system minify-build-system)
296 (arguments
297 `(#:javascript-files '("json2.js"
298 "json_parse.js"
299 "json_parse_state.js"
300 "cycle.js")))
301 (home-page "https://github.com/douglascrockford/JSON-js")
302 (synopsis "JSON encoders and decoders")
303 (description "The files in this collection implement JSON
304 encoders/decoders in JavaScript.
305
306 @code{json2.js}: This file creates a JSON property in the global object, if
307 there isn't already one, setting its value to an object containing a stringify
308 method and a parse method. The @code{parse} method uses the @code{eval}
309 method to do the parsing, guarding it with several regular expressions to
310 defend against accidental code execution hazards. On current browsers, this
311 file does nothing, preferring the built-in JSON object.
312
313 @code{json_parse.js}: This file contains an alternative JSON @code{parse}
314 function that uses recursive descent instead of @code{eval}.
315
316 @code{json_parse_state.js}: This files contains an alternative JSON
317 @code{parse} function that uses a state machine instead of @code{eval}.
318
319 @code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
320 @code{JSON.retrocycle}, which make it possible to encode cyclical structures
321 and DAGs in JSON, and to then recover them. This is a capability that is not
322 provided by ES5. @code{JSONPath} is used to represent the links.")
323 (license license:public-domain))))
324
325 (define-public js-strftime
326 (package
327 (name "js-strftime")
328 (version "0.10.0")
329 (source (origin
330 (method git-fetch)
331 (uri (git-reference
332 (url"https://github.com/samsonjs/strftime")
333 (commit (string-append "v" version))))
334 (file-name (git-file-name name version))
335 (sha256
336 (base32
337 "131nmlivazwxyba25kh9lda99749fq4xsyin6lzfalaaydviby4p"))))
338 (build-system minify-build-system)
339 (arguments
340 `(#:javascript-files '("strftime.js")))
341 (home-page "https://github.com/samsonjs/strftime")
342 (synopsis "Implementation of strftime to JavaScript")
343 (description "This is an implementation of the @code{strftime} procedure
344 for JavaScript. It works in (at least) node.js and browsers. It supports
345 localization and timezones. Most standard specifiers from C are supported as
346 well as some other extensions from Ruby.")
347 (license license:expat)))
348
349 (define-public js-highlight
350 (package
351 (name "js-highlight")
352 (version "9.12.0")
353 (source (origin
354 (method git-fetch)
355 (uri (git-reference
356 (url "https://github.com/isagalaev/highlight.js")
357 (commit version)))
358 (file-name (git-file-name name version))
359 (sha256
360 (base32
361 "12qz22qjpd6svj58pwgcwg2x2rzhihfdrxg6lgj39nfpaln6dris"))))
362 (build-system minify-build-system)
363 (arguments
364 `(#:javascript-files '("src/highlight.js")))
365 (home-page "https://github.com/isagalaev/highlight.js")
366 (synopsis "Syntax highlighting for JavaScript")
367 (description "Highlight.js is a syntax highlighter written in JavaScript.
368 It works in the browser as well as on the server. It works with pretty much
369 any markup, doesn’t depend on any framework and has automatic language
370 detection.")
371 (license license:bsd-3)))
372
373 (define-public js-datatables
374 (package
375 (name "js-datatables")
376 (version "1.10.19")
377 (source (origin
378 (method url-fetch)
379 (uri (string-append "https://datatables.net/releases/DataTables-"
380 version ".zip"))
381 (sha256
382 (base32
383 "0cff8a1g7pjwbjdqq0yzqd963ar7pfi4splmm6rwdzganr77rkhb"))))
384 (build-system minify-build-system)
385 (arguments
386 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
387 "media/js/jquery.dataTables.js")))
388 (native-inputs
389 `(("unzip" ,unzip)))
390 (home-page "https://datatables.net")
391 (synopsis "DataTables plug-in for jQuery")
392 (description "DataTables is a table enhancing plug-in for the jQuery
393 Javascript library, adding sorting, paging and filtering abilities to plain
394 HTML tables with minimal effort.")
395 (license license:expat)))
396
397 (define-public js-requirejs
398 (package
399 (name "js-requirejs")
400 (version "2.3.6")
401 (source (origin
402 (method git-fetch)
403 (uri (git-reference
404 (url "https://github.com/requirejs/requirejs")
405 (commit version)))
406 (file-name (git-file-name name version))
407 (sha256
408 (base32
409 "0cvd5y2mb3h6yil3niqn3gjqrzixdsxcz4rvc2f0hg4kzp5y0w86"))))
410 (build-system minify-build-system)
411 (arguments `(#:javascript-files '("require.js")))
412 (home-page "https://github.com/requirejs/requirejs/")
413 (synopsis "File and module loader for JavaScript")
414 (description "RequireJS loads plain JavaScript files as well as more
415 defined modules. It is optimized for in-browser use, including in a Web
416 Worker, but it can be used in other JavaScript environments.")
417 (license license:expat)))
418
419 (define-public js-selectize
420 (package
421 (name "js-selectize")
422 (version "0.12.6")
423 (source (origin
424 (method git-fetch)
425 (uri (git-reference
426 (url "https://github.com/selectize/selectize.js")
427 (commit (string-append "v" version))))
428 (file-name (git-file-name name version))
429 (sha256
430 (base32
431 "15gichl8wi6yxag2ps723nxrgyan15976dzsnvw9h9py8sbyyzjn"))))
432 (build-system minify-build-system)
433 (arguments `(#:javascript-files '("src/selectize.js")))
434 (home-page "https://selectize.github.io/selectize.js/")
435 (synopsis "Hybrid widget between a textbox and <select> box")
436 (description "Selectize is the hybrid of a textbox and @code{<select>}
437 box. It's jQuery based and it has autocomplete and native-feeling keyboard
438 navigation; it is useful for tagging, contact lists, etc.")
439 (license license:asl2.0)))
440
441 (define-public js-es5-shim
442 (package
443 (name "js-es5-shim")
444 (version "4.5.13")
445 (source (origin
446 (method git-fetch)
447 (uri (git-reference
448 (url "https://github.com/es-shims/es5-shim")
449 (commit (string-append "v" version))))
450 (file-name (git-file-name name version))
451 (sha256
452 (base32
453 "142w384fbyllq4yggv173g82lw3wix4jqcg6hkhx1ymq89vvnpmh"))))
454 (build-system minify-build-system)
455 (arguments `(#:javascript-files
456 '("es5-sham.js"
457 "es5-shim.js")))
458 (home-page "https://github.com/es-shims/es5-shim")
459 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
460 (description "@code{es5-shim.js} patches a JavaScript context to contain
461 all ECMAScript 5 methods that can be faithfully emulated with a legacy
462 JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
463 possible. Many of these shams are intended only to allow code to be written
464 to ES5 without causing run-time errors in older engines. In many cases, this
465 means that these shams cause many ES5 methods to silently fail.")
466 (license license:expat)))
467
468 (define-public js-filesaver
469 (package
470 (name "js-filesaver")
471 (version "1.3.8")
472 (source (origin
473 (method git-fetch)
474 (uri (git-reference
475 (url "https://github.com/eligrey/FileSaver.js")
476 (commit version)))
477 (file-name (git-file-name name version))
478 (sha256
479 (base32
480 "0gvqk0hnr8fig0n4da7vj7q6z31bcyv52916xz3rbmdj3pgpiv1d"))))
481 (build-system minify-build-system)
482 (arguments
483 `(#:phases
484 (modify-phases %standard-phases
485 (add-after 'unpack 'fix-uglification
486 ;; Remove "export" keyword which prevents the file from being
487 ;; uglified by uglify-js. Moreover, that keyword is not present in
488 ;; the minified version of the library some projects are using,
489 ;; e.g.,
490 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
491 (lambda _
492 (substitute* "src/FileSaver.js"
493 (("export ") ""))
494 #t))
495 (add-after 'install 'install-unminified-version
496 (lambda* (#:key outputs #:allow-other-keys)
497 (install-file "src/FileSaver.js"
498 (string-append (assoc-ref outputs "out")
499 "/share/javascript"))
500 #t)))))
501 (home-page
502 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
503 (synopsis "HTML5 saveAs() FileSaver implementation")
504 (description "@file{FileSaver.js} implements the @code{saveAs()}
505 FileSaver interface in browsers that do not natively support it.
506
507 @file{FileSaver.js} is the solution to saving files on the
508 client-side, and is perfect for webapps that need to generate files,
509 or for saving sensitive information that shouldn't be sent to an
510 external server.")
511 (license license:expat)))
512
513 (define-public mujs
514 (package
515 (name "mujs")
516 (version "1.0.9")
517 (source
518 (origin
519 (method git-fetch)
520 (uri (git-reference
521 (url "https://github.com/ccxvii/mujs")
522 (commit version)))
523 (file-name (git-file-name name version))
524 (sha256
525 (base32 "146lmmigqlvx36d3fzb9kk7sy6y4ddv0ih4pkjz4zyj30zl84gy2"))))
526 (build-system gnu-build-system)
527 (arguments
528 `(#:phases
529 (modify-phases %standard-phases
530 (delete 'configure) ; no configure script
531 (replace 'install
532 (lambda* (#:key (make-flags '()) #:allow-other-keys)
533 (apply invoke "make" "install-shared" make-flags))))
534 #:make-flags
535 (list ,(string-append "VERSION=" version)
536 ,(string-append "CC=" (cc-for-target))
537 (string-append "prefix=" (assoc-ref %outputs "out")))
538 #:tests? #f)) ; no tests
539 (inputs
540 `(("readline" ,readline)))
541 (home-page "https://mujs.com/")
542 (synopsis "JavaScript interpreter written in C")
543 (description "MuJS is a lightweight Javascript interpreter designed for
544 embedding in other software to extend them with scripting capabilities. MuJS
545 was designed with a focus on small size, correctness, and simplicity. It is
546 written in portable C and implements ECMAScript as specified by ECMA-262. The
547 interface for binding with native code is designed to be as simple as possible
548 to use, and is very similar to Lua. There is no need to interact with byzantine
549 C++ template mechanisms, or worry about marking and unmarking garbage collection
550 roots, or wrestle with obscure build systems.")
551 (license license:isc)))
552
553 (define-public quickjs
554 (package
555 (name "quickjs")
556 (version "2020-11-08")
557 (source (origin
558 (method url-fetch)
559 (uri (string-append "https://bellard.org/quickjs/quickjs-"
560 version ".tar.xz"))
561 (sha256
562 (base32
563 "0yqqcjxi3cqagw184mqrxpvqg486x7c233r3cp9mxachngd6779f"))))
564 (build-system gnu-build-system)
565 (arguments
566 `(#:make-flags
567 (list "prefix="
568 (string-append "DESTDIR=" %output))
569 #:phases
570 (modify-phases %standard-phases
571 (delete 'configure)
572 (replace 'check
573 (lambda _
574 (invoke "make" "microbench"))))))
575 (home-page "https://bellard.org/quickjs/")
576 (synopsis "Small embeddable Javascript engine")
577 (description "QuickJS supports the ES2020 specification including modules,
578 asynchronous generators, proxies, BigInt and BigDecimal. It can compile
579 Javascript sources to executables with no external dependency. It includes a
580 command line interpreter with contextual colorization implemented in
581 Javascript and a small built-in standard library with C library wrappers.")
582 (license license:expat)))