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, 2021 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 ;;; Copyright © 2021 Pierre Neidhardt <mail@ambrevar.xyz>
9 ;;; This file is part of GNU Guix.
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24 (define-module (gnu packages javascript)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages base)
28 #:use-module (gnu packages compression)
29 #:use-module (gnu packages lisp-xyz)
30 #:use-module (gnu packages readline)
31 #:use-module (gnu packages web)
32 #:use-module (guix packages)
33 #:use-module (guix download)
34 #:use-module (guix git-download)
35 #:use-module (guix build-system gnu)
36 #:use-module (guix build-system cmake)
37 #:use-module (guix build-system trivial)
38 #:use-module (guix build-system minify)
39 #:use-module (guix utils))
48 (url "https://github.com/DaveGamble/cJSON")
49 (commit (string-append "v" version))))
50 (file-name (git-file-name name version))
52 (base32 "1rlnailhjm180zb6pc17jwphjwivw8kfpqgixjfgq4iyryq46sah"))))
53 (build-system cmake-build-system)
55 `(#:configure-flags '("-DENABLE_CJSON_UTILS=On")))
56 (home-page "https://github.com/DaveGamble/cJSON")
57 (synopsis "JSON parser written in ANSI C")
58 (description "This library provides a portable embeddable JSON parser.")
59 (license license:expat)))
61 (define-public js-context-menu
63 (name "js-context-menu")
69 (url "https://github.com/zorkow/context-menu")
70 (commit (string-append "v" version))))
71 (file-name (git-file-name name version))
74 "1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh"))))
75 (build-system trivial-build-system)
77 `(#:modules ((guix build utils))
80 (use-modules (guix build utils))
81 (chdir (assoc-ref %build-inputs "source"))
82 (let ((target (string-append %output "/share/javascript/context-menu")))
83 (apply invoke (string-append (assoc-ref %build-inputs "esbuild")
86 "--tsconfig=tsconfig.json"
87 (string-append "--outdir=" target)
88 (find-files "ts" "\\.ts$"))))))
90 `(("esbuild" ,esbuild)))
91 (home-page "https://github.com/zorkow/context-menu")
92 (synopsis "Generic context menu")
93 (description "This package provides a reimplementation of the MathJax
94 context menu in TypeScript.")
95 (license license:asl2.0)))
97 (define-public font-mathjax
105 (url "https://github.com/mathjax/MathJax")
107 (file-name (git-file-name name version))
110 "127j12g7v2hx6k7r00b8cp49s7nkrwhxy6l8p03pw34xpxbgbimm"))))
111 (build-system trivial-build-system)
113 `(#:modules ((guix build utils))
116 (use-modules (guix build utils)
118 (let ((install-directory (string-append %output "/share/fonts/mathjax")))
119 (mkdir-p install-directory)
120 (copy-recursively (string-append (assoc-ref %build-inputs "source")
122 install-directory)))))
123 (home-page "https://www.mathjax.org/")
124 (synopsis "Fonts for MathJax")
125 (description "This package contains the fonts required for MathJax.")
126 (license license:asl2.0)))
128 (define-public js-mathjax
130 (inherit font-mathjax)
133 `(#:modules ((guix build utils))
136 (use-modules (guix build utils)
140 (set-path-environment-variable
141 "PATH" '("bin") (map (match-lambda
145 (set-path-environment-variable
146 "GUIX_LOCPATH" '("lib/locale")
147 (list (assoc-ref %build-inputs "glibc-utf8-locales")))
148 (setenv "LANG" "en_US.UTF-8")
149 (let ((install-directory (string-append %output "/share/javascript/mathjax")))
150 (copy-recursively (string-append (assoc-ref %build-inputs "source") "/unpacked")
152 (mkdir-p install-directory)
153 (symlink (string-append (assoc-ref %build-inputs "font-mathjax")
154 "/share/fonts/mathjax")
155 (string-append install-directory "/fonts"))
159 (let ((installed (string-append install-directory
160 ;; remove prefix "./MathJax-unpacked"
161 (string-drop file 18))))
162 (format #t "~a -> ~a~%" file installed)
164 ((string-match "\\.js$" file)
165 (mkdir-p (dirname installed))
166 (let ((minified (open-pipe* OPEN_READ "uglify-js" file)))
167 (call-with-output-file installed
169 (dump-port minified port)))
171 (let ((exit (close-pipe minified)))
173 (error "dear, uglify-js failed" exit)))))
175 (install-file file (dirname installed))))))
180 `(("font-mathjax" ,font-mathjax)
181 ("glibc-utf8-locales" ,glibc-utf8-locales)
182 ("uglify-js" ,uglify-js)
183 ,@(package-native-inputs font-mathjax)))
184 (synopsis "JavaScript display engine for LaTeX, MathML, and AsciiMath")
185 (description "MathJax is a JavaScript display engine for LaTeX, MathML,
186 and AsciiMath notation that works in all modern browsers. It requires no
187 plugins or software to be installed on the browser. So the page author can
188 write web documents that include mathematics and be confident that readers will
189 be able to view it naturally and easily.")))
191 (define-public js-commander
193 (name "js-commander")
199 (url "https://github.com/tj/commander.js")
200 (commit (string-append "v" version))))
201 (file-name (git-file-name name version))
204 "126m25s6mxpxmdj4aw5awz06b47r8r798lcf1c5bnmmh39cik5i1"))))
205 (build-system trivial-build-system)
207 `(#:modules ((guix build utils))
210 (use-modules (guix build utils))
211 (chdir (assoc-ref %build-inputs "source"))
212 (let ((esbuild (string-append (assoc-ref %build-inputs "esbuild")
214 (target (string-append %output "/share/javascript/commander")))
218 "--tsconfig=tsconfig.json"
220 (string-append "--outfile=" target "/index.min.js")
223 `(("esbuild" ,esbuild)))
224 (home-page "https://github.com/tj/commander.js")
225 (synopsis "Library for node.js command-line interfaces")
226 (description "Commander.js aims to be the complete solution for node.js
227 command-line interfaces. ")
228 (license license:expat)))
230 (define-public js-xmldom-sre
231 ;; This commit corresponds to the untagged release 0.1.32
232 (let ((commit "3c79325bc2c9e5d27e3ba44b680fa8c5dd6a381d")
235 (name "js-xmldom-sre")
241 (url "https://github.com/zorkow/xmldom/")
243 (file-name (git-file-name name version))
246 "0a88v0id3mjflpvjqhv8a28br0xvaaszxbf7alg6pxfbnkb69yyq"))))
247 (build-system trivial-build-system)
249 `(#:modules ((guix build utils))
252 (use-modules (guix build utils))
253 (chdir (assoc-ref %build-inputs "source"))
254 (let ((esbuild (string-append (assoc-ref %build-inputs "esbuild")
256 (target (string-append %output "/share/javascript/xmldom-sre")))
261 (string-append "--outfile=" target "/dom-parser.min.js")
264 `(("esbuild" ,esbuild)))
265 (home-page "https://github.com/zorkow/xmldom/")
266 (synopsis "DOM parser and XML serializer")
267 (description "This is a fork of the xmldom library. It allows the use
268 of wicked-good-xpath together with xmldom.")
269 ;; One of these licenses may be selected.
270 (license (list license:expat
273 (define-public js-respond
280 (url "https://github.com/scottjehl/Respond")
282 (file-name (git-file-name name version))
285 "00xid731rirc7sdy1gc8qal3v9g0agr2qx15hm4x97l1lcbylyn2"))))
286 (build-system minify-build-system)
288 `(#:javascript-files '("src/matchmedia.addListener.js"
289 "src/matchmedia.polyfill.js"
291 (home-page "https://github.com/scottjehl/Respond")
292 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
293 (description "The goal of this script is to provide a fast and lightweight
294 script to enable responsive web designs in browsers that don't support CSS3
296 (license license:expat)))
298 (define-public js-html5shiv
300 (name "js-html5shiv")
305 (url "https://github.com/aFarkas/html5shiv")
307 (file-name (git-file-name name version))
310 "0y1c5nyq0brl9fjdihhax33vks4s1ij9iv113879sg3zflmgqpd0"))))
311 (build-system minify-build-system)
312 (home-page "https://github.com/aFarkas/html5shiv")
313 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
314 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
315 legacy Internet Explorer and provides basic HTML5 styling for Internet
316 Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
317 ;; From the file "MIT and GPL2 licenses.md":
319 ;; This software is licensed under a dual license system (MIT or GPL
320 ;; version 2). This means you are free to choose with which of both
321 ;; licenses (MIT or GPL version 2) you want to use this library.
322 (license (list license:expat license:gpl2))))
324 (define-public js-json2
325 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
329 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
333 (url "https://github.com/douglascrockford/JSON-js")
335 (file-name (string-append name "-" version "-checkout"))
338 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
339 (build-system minify-build-system)
341 `(#:javascript-files '("json2.js"
343 "json_parse_state.js"
345 (home-page "https://github.com/douglascrockford/JSON-js")
346 (synopsis "JSON encoders and decoders")
347 (description "The files in this collection implement JSON
348 encoders/decoders in JavaScript.
350 @code{json2.js}: This file creates a JSON property in the global object, if
351 there isn't already one, setting its value to an object containing a stringify
352 method and a parse method. The @code{parse} method uses the @code{eval}
353 method to do the parsing, guarding it with several regular expressions to
354 defend against accidental code execution hazards. On current browsers, this
355 file does nothing, preferring the built-in JSON object.
357 @code{json_parse.js}: This file contains an alternative JSON @code{parse}
358 function that uses recursive descent instead of @code{eval}.
360 @code{json_parse_state.js}: This files contains an alternative JSON
361 @code{parse} function that uses a state machine instead of @code{eval}.
363 @code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
364 @code{JSON.retrocycle}, which make it possible to encode cyclical structures
365 and DAGs in JSON, and to then recover them. This is a capability that is not
366 provided by ES5. @code{JSONPath} is used to represent the links.")
367 (license license:public-domain))))
369 (define-public js-strftime
376 (url"https://github.com/samsonjs/strftime")
377 (commit (string-append "v" version))))
378 (file-name (git-file-name name version))
381 "131nmlivazwxyba25kh9lda99749fq4xsyin6lzfalaaydviby4p"))))
382 (build-system minify-build-system)
384 `(#:javascript-files '("strftime.js")))
385 (home-page "https://github.com/samsonjs/strftime")
386 (synopsis "Implementation of strftime to JavaScript")
387 (description "This is an implementation of the @code{strftime} procedure
388 for JavaScript. It works in (at least) node.js and browsers. It supports
389 localization and timezones. Most standard specifiers from C are supported as
390 well as some other extensions from Ruby.")
391 (license license:expat)))
393 (define-public js-highlight
395 (name "js-highlight")
400 (url "https://github.com/isagalaev/highlight.js")
402 (file-name (git-file-name name version))
405 "12qz22qjpd6svj58pwgcwg2x2rzhihfdrxg6lgj39nfpaln6dris"))))
406 (build-system minify-build-system)
408 `(#:javascript-files '("src/highlight.js")))
409 (home-page "https://github.com/isagalaev/highlight.js")
410 (synopsis "Syntax highlighting for JavaScript")
411 (description "Highlight.js is a syntax highlighter written in JavaScript.
412 It works in the browser as well as on the server. It works with pretty much
413 any markup, doesn’t depend on any framework and has automatic language
415 (license license:bsd-3)))
417 (define-public js-datatables
419 (name "js-datatables")
423 (uri (string-append "https://datatables.net/releases/DataTables-"
427 "0cff8a1g7pjwbjdqq0yzqd963ar7pfi4splmm6rwdzganr77rkhb"))))
428 (build-system minify-build-system)
430 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
431 "media/js/jquery.dataTables.js")))
434 (home-page "https://datatables.net")
435 (synopsis "DataTables plug-in for jQuery")
436 (description "DataTables is a table enhancing plug-in for the jQuery
437 Javascript library, adding sorting, paging and filtering abilities to plain
438 HTML tables with minimal effort.")
439 (license license:expat)))
441 (define-public js-requirejs
443 (name "js-requirejs")
448 (url "https://github.com/requirejs/requirejs")
450 (file-name (git-file-name name version))
453 "0cvd5y2mb3h6yil3niqn3gjqrzixdsxcz4rvc2f0hg4kzp5y0w86"))))
454 (build-system minify-build-system)
455 (arguments `(#:javascript-files '("require.js")))
456 (home-page "https://github.com/requirejs/requirejs/")
457 (synopsis "File and module loader for JavaScript")
458 (description "RequireJS loads plain JavaScript files as well as more
459 defined modules. It is optimized for in-browser use, including in a Web
460 Worker, but it can be used in other JavaScript environments.")
461 (license license:expat)))
463 (define-public js-selectize
465 (name "js-selectize")
470 (url "https://github.com/selectize/selectize.js")
471 (commit (string-append "v" version))))
472 (file-name (git-file-name name version))
475 "15gichl8wi6yxag2ps723nxrgyan15976dzsnvw9h9py8sbyyzjn"))))
476 (build-system minify-build-system)
477 (arguments `(#:javascript-files '("src/selectize.js")))
478 (home-page "https://selectize.github.io/selectize.js/")
479 (synopsis "Hybrid widget between a textbox and <select> box")
480 (description "Selectize is the hybrid of a textbox and @code{<select>}
481 box. It's jQuery based and it has autocomplete and native-feeling keyboard
482 navigation; it is useful for tagging, contact lists, etc.")
483 (license license:asl2.0)))
485 (define-public js-es5-shim
492 (url "https://github.com/es-shims/es5-shim")
493 (commit (string-append "v" version))))
494 (file-name (git-file-name name version))
497 "142w384fbyllq4yggv173g82lw3wix4jqcg6hkhx1ymq89vvnpmh"))))
498 (build-system minify-build-system)
499 (arguments `(#:javascript-files
502 (home-page "https://github.com/es-shims/es5-shim")
503 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
504 (description "@code{es5-shim.js} patches a JavaScript context to contain
505 all ECMAScript 5 methods that can be faithfully emulated with a legacy
506 JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
507 possible. Many of these shams are intended only to allow code to be written
508 to ES5 without causing run-time errors in older engines. In many cases, this
509 means that these shams cause many ES5 methods to silently fail.")
510 (license license:expat)))
512 (define-public js-filesaver
514 (name "js-filesaver")
519 (url "https://github.com/eligrey/FileSaver.js")
521 (file-name (git-file-name name version))
524 "0gvqk0hnr8fig0n4da7vj7q6z31bcyv52916xz3rbmdj3pgpiv1d"))))
525 (build-system minify-build-system)
528 (modify-phases %standard-phases
529 (add-after 'unpack 'fix-uglification
530 ;; Remove "export" keyword which prevents the file from being
531 ;; uglified by uglify-js. Moreover, that keyword is not present in
532 ;; the minified version of the library some projects are using,
534 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
536 (substitute* "src/FileSaver.js"
539 (add-after 'install 'install-unminified-version
540 (lambda* (#:key outputs #:allow-other-keys)
541 (install-file "src/FileSaver.js"
542 (string-append (assoc-ref outputs "out")
543 "/share/javascript"))
546 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
547 (synopsis "HTML5 saveAs() FileSaver implementation")
548 (description "@file{FileSaver.js} implements the @code{saveAs()}
549 FileSaver interface in browsers that do not natively support it.
551 @file{FileSaver.js} is the solution to saving files on the
552 client-side, and is perfect for webapps that need to generate files,
553 or for saving sensitive information that shouldn't be sent to an
555 (license license:expat)))
565 (url "https://github.com/ccxvii/mujs")
567 (file-name (git-file-name name version))
569 (base32 "0ivqz06fq8v36p2gkjh64vgv0gm7nghds0n42vrv7vm46phdffvb"))))
570 (build-system gnu-build-system)
573 (modify-phases %standard-phases
574 (delete 'configure) ; no configure script
576 (lambda* (#:key (make-flags '()) #:allow-other-keys)
577 (apply invoke "make" "install-shared" make-flags))))
579 (list ,(string-append "VERSION=" version)
580 ,(string-append "CC=" (cc-for-target))
581 (string-append "prefix=" (assoc-ref %outputs "out")))
582 #:tests? #f)) ; no tests
584 `(("readline" ,readline)))
585 (home-page "https://mujs.com/")
586 (synopsis "JavaScript interpreter written in C")
587 (description "MuJS is a lightweight Javascript interpreter designed for
588 embedding in other software to extend them with scripting capabilities. MuJS
589 was designed with a focus on small size, correctness, and simplicity. It is
590 written in portable C and implements ECMAScript as specified by ECMA-262. The
591 interface for binding with native code is designed to be as simple as possible
592 to use, and is very similar to Lua. There is no need to interact with byzantine
593 C++ template mechanisms, or worry about marking and unmarking garbage collection
594 roots, or wrestle with obscure build systems.")
595 (license license:isc)))
597 (define-public quickjs
600 (version "2021-03-27")
603 (uri (string-append "https://bellard.org/quickjs/quickjs-"
607 "06pywwpmfwjz225h59wf90q96a2fd66qfcw5xa6m6y9k9k7glnx4"))))
608 (build-system gnu-build-system)
612 (string-append "DESTDIR=" %output))
614 (modify-phases %standard-phases
618 (invoke "make" "microbench"))))))
619 (home-page "https://bellard.org/quickjs/")
620 (synopsis "Small embeddable Javascript engine")
621 (description "QuickJS supports the ES2020 specification including modules,
622 asynchronous generators, proxies, BigInt and BigDecimal. It can compile
623 Javascript sources to executables with no external dependency. It includes a
624 command line interpreter with contextual colorization implemented in
625 Javascript and a small built-in standard library with C library wrappers.")
626 (license license:expat)))
628 (define-public duktape
634 (uri (string-append "https://duktape.org/duktape-"
638 "19szwxzvl2g65fw95ggvb8h0ma5bd9vvnnccn59hwnc4dida1x4n"))))
639 (build-system gnu-build-system)
641 '(#:tests? #f ; No tests.
642 #:make-flags (list "-f" "Makefile.sharedlibrary"
643 (string-append "INSTALL_PREFIX=" %output))
645 (modify-phases %standard-phases
646 (delete 'configure))))
647 (home-page "https://duktape.org/")
648 (synopsis "Small embeddable Javascript engine")
649 (description "Duktape is an embeddable Javascript engine, with a focus on
650 portability and compact footprint. Duktape is easy to integrate into a C/C++
651 project: add @file{duktape.c}, @file{duktape.h}, and @file{duk_config.h} to
652 your build, and use the Duktape API to call ECMAScript functions from C code
654 (license license:expat)))