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>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
47 (url "https://github.com/DaveGamble/cJSON")
48 (commit (string-append "v" version))))
49 (file-name (git-file-name name version))
51 (base32 "1rlnailhjm180zb6pc17jwphjwivw8kfpqgixjfgq4iyryq46sah"))))
52 (build-system cmake-build-system)
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)))
60 (define-public js-context-menu
62 (name "js-context-menu")
68 (url "https://github.com/zorkow/context-menu")
69 (commit (string-append "v" version))))
70 (file-name (git-file-name name version))
73 "1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh"))))
74 (build-system trivial-build-system)
76 `(#:modules ((guix build utils))
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")
85 "--tsconfig=tsconfig.json"
86 (string-append "--outdir=" target)
87 (find-files "ts" "\\.ts$"))))))
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)))
96 (define-public font-mathjax
104 (url "https://github.com/mathjax/MathJax")
106 (file-name (git-file-name name version))
109 "127j12g7v2hx6k7r00b8cp49s7nkrwhxy6l8p03pw34xpxbgbimm"))))
110 (build-system trivial-build-system)
112 `(#:modules ((guix build utils))
115 (use-modules (guix build utils)
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")
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)))
127 (define-public js-mathjax
129 (inherit font-mathjax)
132 `(#:modules ((guix build utils))
135 (use-modules (guix build utils)
139 (set-path-environment-variable
140 "PATH" '("bin") (map (match-lambda
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")
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"))
158 (let ((installed (string-append install-directory
159 ;; remove prefix "./MathJax-unpacked"
160 (string-drop file 18))))
161 (format #t "~a -> ~a~%" file installed)
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
168 (dump-port minified port)))
170 (let ((exit (close-pipe minified)))
172 (error "dear, uglify-js failed" exit)))))
174 (install-file file (dirname installed))))))
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.")))
190 (define-public js-commander
192 (name "js-commander")
198 (url "https://github.com/tj/commander.js")
199 (commit (string-append "v" version))))
200 (file-name (git-file-name name version))
203 "126m25s6mxpxmdj4aw5awz06b47r8r798lcf1c5bnmmh39cik5i1"))))
204 (build-system trivial-build-system)
206 `(#:modules ((guix build utils))
209 (use-modules (guix build utils))
210 (chdir (assoc-ref %build-inputs "source"))
211 (let ((esbuild (string-append (assoc-ref %build-inputs "esbuild")
213 (target (string-append %output "/share/javascript/commander")))
217 "--tsconfig=tsconfig.json"
219 (string-append "--outfile=" target "/index.min.js")
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)))
229 (define-public js-xmldom-sre
230 ;; This commit corresponds to the untagged release 0.1.32
231 (let ((commit "3c79325bc2c9e5d27e3ba44b680fa8c5dd6a381d")
234 (name "js-xmldom-sre")
240 (url "https://github.com/zorkow/xmldom/")
242 (file-name (git-file-name name version))
245 "0a88v0id3mjflpvjqhv8a28br0xvaaszxbf7alg6pxfbnkb69yyq"))))
246 (build-system trivial-build-system)
248 `(#:modules ((guix build utils))
251 (use-modules (guix build utils))
252 (chdir (assoc-ref %build-inputs "source"))
253 (let ((esbuild (string-append (assoc-ref %build-inputs "esbuild")
255 (target (string-append %output "/share/javascript/xmldom-sre")))
260 (string-append "--outfile=" target "/dom-parser.min.js")
263 `(("esbuild" ,esbuild)))
264 (home-page "https://github.com/zorkow/xmldom/")
265 (synopsis "DOM parser and XML serializer")
266 (description "This is a fork of the xmldom library. It allows the use
267 of wicked-good-xpath together with xmldom.")
268 ;; One of these licenses may be selected.
269 (license (list license:expat
272 (define-public js-respond
279 (url "https://github.com/scottjehl/Respond")
281 (file-name (git-file-name name version))
284 "00xid731rirc7sdy1gc8qal3v9g0agr2qx15hm4x97l1lcbylyn2"))))
285 (build-system minify-build-system)
287 `(#:javascript-files '("src/matchmedia.addListener.js"
288 "src/matchmedia.polyfill.js"
290 (home-page "https://github.com/scottjehl/Respond")
291 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
292 (description "The goal of this script is to provide a fast and lightweight
293 script to enable responsive web designs in browsers that don't support CSS3
295 (license license:expat)))
297 (define-public js-html5shiv
299 (name "js-html5shiv")
304 (url "https://github.com/aFarkas/html5shiv")
306 (file-name (git-file-name name version))
309 "0y1c5nyq0brl9fjdihhax33vks4s1ij9iv113879sg3zflmgqpd0"))))
310 (build-system minify-build-system)
311 (home-page "https://github.com/aFarkas/html5shiv")
312 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
313 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
314 legacy Internet Explorer and provides basic HTML5 styling for Internet
315 Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
316 ;; From the file "MIT and GPL2 licenses.md":
318 ;; This software is licensed under a dual license system (MIT or GPL
319 ;; version 2). This means you are free to choose with which of both
320 ;; licenses (MIT or GPL version 2) you want to use this library.
321 (license (list license:expat license:gpl2))))
323 (define-public js-json2
324 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
328 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
332 (url "https://github.com/douglascrockford/JSON-js")
334 (file-name (string-append name "-" version "-checkout"))
337 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
338 (build-system minify-build-system)
340 `(#:javascript-files '("json2.js"
342 "json_parse_state.js"
344 (home-page "https://github.com/douglascrockford/JSON-js")
345 (synopsis "JSON encoders and decoders")
346 (description "The files in this collection implement JSON
347 encoders/decoders in JavaScript.
349 @code{json2.js}: This file creates a JSON property in the global object, if
350 there isn't already one, setting its value to an object containing a stringify
351 method and a parse method. The @code{parse} method uses the @code{eval}
352 method to do the parsing, guarding it with several regular expressions to
353 defend against accidental code execution hazards. On current browsers, this
354 file does nothing, preferring the built-in JSON object.
356 @code{json_parse.js}: This file contains an alternative JSON @code{parse}
357 function that uses recursive descent instead of @code{eval}.
359 @code{json_parse_state.js}: This files contains an alternative JSON
360 @code{parse} function that uses a state machine instead of @code{eval}.
362 @code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
363 @code{JSON.retrocycle}, which make it possible to encode cyclical structures
364 and DAGs in JSON, and to then recover them. This is a capability that is not
365 provided by ES5. @code{JSONPath} is used to represent the links.")
366 (license license:public-domain))))
368 (define-public js-strftime
375 (url"https://github.com/samsonjs/strftime")
376 (commit (string-append "v" version))))
377 (file-name (git-file-name name version))
380 "131nmlivazwxyba25kh9lda99749fq4xsyin6lzfalaaydviby4p"))))
381 (build-system minify-build-system)
383 `(#:javascript-files '("strftime.js")))
384 (home-page "https://github.com/samsonjs/strftime")
385 (synopsis "Implementation of strftime to JavaScript")
386 (description "This is an implementation of the @code{strftime} procedure
387 for JavaScript. It works in (at least) node.js and browsers. It supports
388 localization and timezones. Most standard specifiers from C are supported as
389 well as some other extensions from Ruby.")
390 (license license:expat)))
392 (define-public js-highlight
394 (name "js-highlight")
399 (url "https://github.com/isagalaev/highlight.js")
401 (file-name (git-file-name name version))
404 "12qz22qjpd6svj58pwgcwg2x2rzhihfdrxg6lgj39nfpaln6dris"))))
405 (build-system minify-build-system)
407 `(#:javascript-files '("src/highlight.js")))
408 (home-page "https://github.com/isagalaev/highlight.js")
409 (synopsis "Syntax highlighting for JavaScript")
410 (description "Highlight.js is a syntax highlighter written in JavaScript.
411 It works in the browser as well as on the server. It works with pretty much
412 any markup, doesn’t depend on any framework and has automatic language
414 (license license:bsd-3)))
416 (define-public js-datatables
418 (name "js-datatables")
422 (uri (string-append "https://datatables.net/releases/DataTables-"
426 "0cff8a1g7pjwbjdqq0yzqd963ar7pfi4splmm6rwdzganr77rkhb"))))
427 (build-system minify-build-system)
429 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
430 "media/js/jquery.dataTables.js")))
433 (home-page "https://datatables.net")
434 (synopsis "DataTables plug-in for jQuery")
435 (description "DataTables is a table enhancing plug-in for the jQuery
436 Javascript library, adding sorting, paging and filtering abilities to plain
437 HTML tables with minimal effort.")
438 (license license:expat)))
440 (define-public js-requirejs
442 (name "js-requirejs")
447 (url "https://github.com/requirejs/requirejs")
449 (file-name (git-file-name name version))
452 "0cvd5y2mb3h6yil3niqn3gjqrzixdsxcz4rvc2f0hg4kzp5y0w86"))))
453 (build-system minify-build-system)
454 (arguments `(#:javascript-files '("require.js")))
455 (home-page "https://github.com/requirejs/requirejs/")
456 (synopsis "File and module loader for JavaScript")
457 (description "RequireJS loads plain JavaScript files as well as more
458 defined modules. It is optimized for in-browser use, including in a Web
459 Worker, but it can be used in other JavaScript environments.")
460 (license license:expat)))
462 (define-public js-selectize
464 (name "js-selectize")
469 (url "https://github.com/selectize/selectize.js")
470 (commit (string-append "v" version))))
471 (file-name (git-file-name name version))
474 "15gichl8wi6yxag2ps723nxrgyan15976dzsnvw9h9py8sbyyzjn"))))
475 (build-system minify-build-system)
476 (arguments `(#:javascript-files '("src/selectize.js")))
477 (home-page "https://selectize.github.io/selectize.js/")
478 (synopsis "Hybrid widget between a textbox and <select> box")
479 (description "Selectize is the hybrid of a textbox and @code{<select>}
480 box. It's jQuery based and it has autocomplete and native-feeling keyboard
481 navigation; it is useful for tagging, contact lists, etc.")
482 (license license:asl2.0)))
484 (define-public js-es5-shim
491 (url "https://github.com/es-shims/es5-shim")
492 (commit (string-append "v" version))))
493 (file-name (git-file-name name version))
496 "142w384fbyllq4yggv173g82lw3wix4jqcg6hkhx1ymq89vvnpmh"))))
497 (build-system minify-build-system)
498 (arguments `(#:javascript-files
501 (home-page "https://github.com/es-shims/es5-shim")
502 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
503 (description "@code{es5-shim.js} patches a JavaScript context to contain
504 all ECMAScript 5 methods that can be faithfully emulated with a legacy
505 JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
506 possible. Many of these shams are intended only to allow code to be written
507 to ES5 without causing run-time errors in older engines. In many cases, this
508 means that these shams cause many ES5 methods to silently fail.")
509 (license license:expat)))
511 (define-public js-filesaver
513 (name "js-filesaver")
518 (url "https://github.com/eligrey/FileSaver.js")
520 (file-name (git-file-name name version))
523 "0gvqk0hnr8fig0n4da7vj7q6z31bcyv52916xz3rbmdj3pgpiv1d"))))
524 (build-system minify-build-system)
527 (modify-phases %standard-phases
528 (add-after 'unpack 'fix-uglification
529 ;; Remove "export" keyword which prevents the file from being
530 ;; uglified by uglify-js. Moreover, that keyword is not present in
531 ;; the minified version of the library some projects are using,
533 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
535 (substitute* "src/FileSaver.js"
538 (add-after 'install 'install-unminified-version
539 (lambda* (#:key outputs #:allow-other-keys)
540 (install-file "src/FileSaver.js"
541 (string-append (assoc-ref outputs "out")
542 "/share/javascript"))
545 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
546 (synopsis "HTML5 saveAs() FileSaver implementation")
547 (description "@file{FileSaver.js} implements the @code{saveAs()}
548 FileSaver interface in browsers that do not natively support it.
550 @file{FileSaver.js} is the solution to saving files on the
551 client-side, and is perfect for webapps that need to generate files,
552 or for saving sensitive information that shouldn't be sent to an
554 (license license:expat)))
564 (url "https://github.com/ccxvii/mujs")
566 (file-name (git-file-name name version))
568 (base32 "146lmmigqlvx36d3fzb9kk7sy6y4ddv0ih4pkjz4zyj30zl84gy2"))))
569 (build-system gnu-build-system)
572 (modify-phases %standard-phases
573 (delete 'configure) ; no configure script
575 (lambda* (#:key (make-flags '()) #:allow-other-keys)
576 (apply invoke "make" "install-shared" make-flags))))
578 (list ,(string-append "VERSION=" version)
579 ,(string-append "CC=" (cc-for-target))
580 (string-append "prefix=" (assoc-ref %outputs "out")))
581 #:tests? #f)) ; no tests
583 `(("readline" ,readline)))
584 (home-page "https://mujs.com/")
585 (synopsis "JavaScript interpreter written in C")
586 (description "MuJS is a lightweight Javascript interpreter designed for
587 embedding in other software to extend them with scripting capabilities. MuJS
588 was designed with a focus on small size, correctness, and simplicity. It is
589 written in portable C and implements ECMAScript as specified by ECMA-262. The
590 interface for binding with native code is designed to be as simple as possible
591 to use, and is very similar to Lua. There is no need to interact with byzantine
592 C++ template mechanisms, or worry about marking and unmarking garbage collection
593 roots, or wrestle with obscure build systems.")
594 (license license:isc)))
596 (define-public quickjs
599 (version "2020-11-08")
602 (uri (string-append "https://bellard.org/quickjs/quickjs-"
606 "0yqqcjxi3cqagw184mqrxpvqg486x7c233r3cp9mxachngd6779f"))))
607 (build-system gnu-build-system)
611 (string-append "DESTDIR=" %output))
613 (modify-phases %standard-phases
617 (invoke "make" "microbench"))))))
618 (home-page "https://bellard.org/quickjs/")
619 (synopsis "Small embeddable Javascript engine")
620 (description "QuickJS supports the ES2020 specification including modules,
621 asynchronous generators, proxies, BigInt and BigDecimal. It can compile
622 Javascript sources to executables with no external dependency. It includes a
623 command line interpreter with contextual colorization implemented in
624 Javascript and a small built-in standard library with C library wrappers.")
625 (license license:expat)))