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-respond
197 (url "https://github.com/scottjehl/Respond")
199 (file-name (git-file-name name version))
202 "00xid731rirc7sdy1gc8qal3v9g0agr2qx15hm4x97l1lcbylyn2"))))
203 (build-system minify-build-system)
205 `(#:javascript-files '("src/matchmedia.addListener.js"
206 "src/matchmedia.polyfill.js"
208 (home-page "https://github.com/scottjehl/Respond")
209 (synopsis "Polyfill for min/max-width CSS3 Media Queries")
210 (description "The goal of this script is to provide a fast and lightweight
211 script to enable responsive web designs in browsers that don't support CSS3
213 (license license:expat)))
215 (define-public js-html5shiv
217 (name "js-html5shiv")
222 (url "https://github.com/aFarkas/html5shiv")
224 (file-name (git-file-name name version))
227 "0y1c5nyq0brl9fjdihhax33vks4s1ij9iv113879sg3zflmgqpd0"))))
228 (build-system minify-build-system)
229 (home-page "https://github.com/aFarkas/html5shiv")
230 (synopsis "Enable HTML5 sectioning elements in legacy browsers")
231 (description "The HTML5 Shiv enables use of HTML5 sectioning elements in
232 legacy Internet Explorer and provides basic HTML5 styling for Internet
233 Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x.")
234 ;; From the file "MIT and GPL2 licenses.md":
236 ;; This software is licensed under a dual license system (MIT or GPL
237 ;; version 2). This means you are free to choose with which of both
238 ;; licenses (MIT or GPL version 2) you want to use this library.
239 (license (list license:expat license:gpl2))))
241 (define-public js-json2
242 (let ((commit "031b1d9e6971bd4c433ca85e216cc853f5a867bd")
246 (version (string-append "2016-10-28." revision "-" (string-take commit 7)))
250 (url "https://github.com/douglascrockford/JSON-js")
252 (file-name (string-append name "-" version "-checkout"))
255 "1fvb6b2y5sd3sqdgcj683sdxcbxdii34q0ysc9wg0dq1sy81l11v"))))
256 (build-system minify-build-system)
258 `(#:javascript-files '("json2.js"
260 "json_parse_state.js"
262 (home-page "https://github.com/douglascrockford/JSON-js")
263 (synopsis "JSON encoders and decoders")
264 (description "The files in this collection implement JSON
265 encoders/decoders in JavaScript.
267 @code{json2.js}: This file creates a JSON property in the global object, if
268 there isn't already one, setting its value to an object containing a stringify
269 method and a parse method. The @code{parse} method uses the @code{eval}
270 method to do the parsing, guarding it with several regular expressions to
271 defend against accidental code execution hazards. On current browsers, this
272 file does nothing, preferring the built-in JSON object.
274 @code{json_parse.js}: This file contains an alternative JSON @code{parse}
275 function that uses recursive descent instead of @code{eval}.
277 @code{json_parse_state.js}: This files contains an alternative JSON
278 @code{parse} function that uses a state machine instead of @code{eval}.
280 @code{cycle.js}: This file contains two functions, @code{JSON.decycle} and
281 @code{JSON.retrocycle}, which make it possible to encode cyclical structures
282 and DAGs in JSON, and to then recover them. This is a capability that is not
283 provided by ES5. @code{JSONPath} is used to represent the links.")
284 (license license:public-domain))))
286 (define-public js-strftime
293 (url"https://github.com/samsonjs/strftime")
294 (commit (string-append "v" version))))
295 (file-name (git-file-name name version))
298 "131nmlivazwxyba25kh9lda99749fq4xsyin6lzfalaaydviby4p"))))
299 (build-system minify-build-system)
301 `(#:javascript-files '("strftime.js")))
302 (home-page "https://github.com/samsonjs/strftime")
303 (synopsis "Implementation of strftime to JavaScript")
304 (description "This is an implementation of the @code{strftime} procedure
305 for JavaScript. It works in (at least) node.js and browsers. It supports
306 localization and timezones. Most standard specifiers from C are supported as
307 well as some other extensions from Ruby.")
308 (license license:expat)))
310 (define-public js-highlight
312 (name "js-highlight")
317 (url "https://github.com/isagalaev/highlight.js")
319 (file-name (git-file-name name version))
322 "12qz22qjpd6svj58pwgcwg2x2rzhihfdrxg6lgj39nfpaln6dris"))))
323 (build-system minify-build-system)
325 `(#:javascript-files '("src/highlight.js")))
326 (home-page "https://github.com/isagalaev/highlight.js")
327 (synopsis "Syntax highlighting for JavaScript")
328 (description "Highlight.js is a syntax highlighter written in JavaScript.
329 It works in the browser as well as on the server. It works with pretty much
330 any markup, doesn’t depend on any framework and has automatic language
332 (license license:bsd-3)))
334 (define-public js-datatables
336 (name "js-datatables")
340 (uri (string-append "https://datatables.net/releases/DataTables-"
344 "0cff8a1g7pjwbjdqq0yzqd963ar7pfi4splmm6rwdzganr77rkhb"))))
345 (build-system minify-build-system)
347 `(#:javascript-files '("media/js/dataTables.bootstrap.js"
348 "media/js/jquery.dataTables.js")))
351 (home-page "https://datatables.net")
352 (synopsis "DataTables plug-in for jQuery")
353 (description "DataTables is a table enhancing plug-in for the jQuery
354 Javascript library, adding sorting, paging and filtering abilities to plain
355 HTML tables with minimal effort.")
356 (license license:expat)))
358 (define-public js-requirejs
360 (name "js-requirejs")
365 (url "https://github.com/requirejs/requirejs")
367 (file-name (git-file-name name version))
370 "0cvd5y2mb3h6yil3niqn3gjqrzixdsxcz4rvc2f0hg4kzp5y0w86"))))
371 (build-system minify-build-system)
372 (arguments `(#:javascript-files '("require.js")))
373 (home-page "https://github.com/requirejs/requirejs/")
374 (synopsis "File and module loader for JavaScript")
375 (description "RequireJS loads plain JavaScript files as well as more
376 defined modules. It is optimized for in-browser use, including in a Web
377 Worker, but it can be used in other JavaScript environments.")
378 (license license:expat)))
380 (define-public js-selectize
382 (name "js-selectize")
387 (url "https://github.com/selectize/selectize.js")
388 (commit (string-append "v" version))))
389 (file-name (git-file-name name version))
392 "15gichl8wi6yxag2ps723nxrgyan15976dzsnvw9h9py8sbyyzjn"))))
393 (build-system minify-build-system)
394 (arguments `(#:javascript-files '("src/selectize.js")))
395 (home-page "https://selectize.github.io/selectize.js/")
396 (synopsis "Hybrid widget between a textbox and <select> box")
397 (description "Selectize is the hybrid of a textbox and @code{<select>}
398 box. It's jQuery based and it has autocomplete and native-feeling keyboard
399 navigation; it is useful for tagging, contact lists, etc.")
400 (license license:asl2.0)))
402 (define-public js-es5-shim
409 (url "https://github.com/es-shims/es5-shim")
410 (commit (string-append "v" version))))
411 (file-name (git-file-name name version))
414 "142w384fbyllq4yggv173g82lw3wix4jqcg6hkhx1ymq89vvnpmh"))))
415 (build-system minify-build-system)
416 (arguments `(#:javascript-files
419 (home-page "https://github.com/es-shims/es5-shim")
420 (synopsis "ECMAScript 5 compatibility shims for legacy JavaScript engines")
421 (description "@code{es5-shim.js} patches a JavaScript context to contain
422 all ECMAScript 5 methods that can be faithfully emulated with a legacy
423 JavaScript engine. @code{es5-sham.js} patches other ES5 methods as closely as
424 possible. Many of these shams are intended only to allow code to be written
425 to ES5 without causing run-time errors in older engines. In many cases, this
426 means that these shams cause many ES5 methods to silently fail.")
427 (license license:expat)))
429 (define-public js-filesaver
431 (name "js-filesaver")
436 (url "https://github.com/eligrey/FileSaver.js")
438 (file-name (git-file-name name version))
441 "0gvqk0hnr8fig0n4da7vj7q6z31bcyv52916xz3rbmdj3pgpiv1d"))))
442 (build-system minify-build-system)
445 (modify-phases %standard-phases
446 (add-after 'unpack 'fix-uglification
447 ;; Remove "export" keyword which prevents the file from being
448 ;; uglified by uglify-js. Moreover, that keyword is not present in
449 ;; the minified version of the library some projects are using,
451 ;; <https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/blob/master/FileSaver.min.js>
453 (substitute* "src/FileSaver.js"
456 (add-after 'install 'install-unminified-version
457 (lambda* (#:key outputs #:allow-other-keys)
458 (install-file "src/FileSaver.js"
459 (string-append (assoc-ref outputs "out")
460 "/share/javascript"))
463 "https://eligrey.com/blog/saving-generated-files-on-the-client-side/")
464 (synopsis "HTML5 saveAs() FileSaver implementation")
465 (description "@file{FileSaver.js} implements the @code{saveAs()}
466 FileSaver interface in browsers that do not natively support it.
468 @file{FileSaver.js} is the solution to saving files on the
469 client-side, and is perfect for webapps that need to generate files,
470 or for saving sensitive information that shouldn't be sent to an
472 (license license:expat)))
482 (url "https://github.com/ccxvii/mujs")
484 (file-name (git-file-name name version))
486 (base32 "146lmmigqlvx36d3fzb9kk7sy6y4ddv0ih4pkjz4zyj30zl84gy2"))))
487 (build-system gnu-build-system)
490 (modify-phases %standard-phases
491 (delete 'configure) ; no configure script
493 (lambda* (#:key (make-flags '()) #:allow-other-keys)
494 (apply invoke "make" "install-shared" make-flags))))
496 (list ,(string-append "VERSION=" version)
497 ,(string-append "CC=" (cc-for-target))
498 (string-append "prefix=" (assoc-ref %outputs "out")))
499 #:tests? #f)) ; no tests
501 `(("readline" ,readline)))
502 (home-page "https://mujs.com/")
503 (synopsis "JavaScript interpreter written in C")
504 (description "MuJS is a lightweight Javascript interpreter designed for
505 embedding in other software to extend them with scripting capabilities. MuJS
506 was designed with a focus on small size, correctness, and simplicity. It is
507 written in portable C and implements ECMAScript as specified by ECMA-262. The
508 interface for binding with native code is designed to be as simple as possible
509 to use, and is very similar to Lua. There is no need to interact with byzantine
510 C++ template mechanisms, or worry about marking and unmarking garbage collection
511 roots, or wrestle with obscure build systems.")
512 (license license:isc)))
514 (define-public quickjs
517 (version "2020-11-08")
520 (uri (string-append "https://bellard.org/quickjs/quickjs-"
524 "0yqqcjxi3cqagw184mqrxpvqg486x7c233r3cp9mxachngd6779f"))))
525 (build-system gnu-build-system)
529 (string-append "DESTDIR=" %output))
531 (modify-phases %standard-phases
535 (invoke "make" "microbench"))))))
536 (home-page "https://bellard.org/quickjs/")
537 (synopsis "Small embeddable Javascript engine")
538 (description "QuickJS supports the ES2020 specification including modules,
539 asynchronous generators, proxies, BigInt and BigDecimal. It can compile
540 Javascript sources to executables with no external dependency. It includes a
541 command line interpreter with contextual colorization implemented in
542 Javascript and a small built-in standard library with C library wrappers.")
543 (license license:expat)))