|
|
GJS includes some built-in modules that are mostly undocumented but are fairly simple to understand and contain a number of useful helper functions. They can be imported using `const imports.<name> = Name;`.
|
|
|
GJS includes some built-in modules that are mostly undocumented but are fairly simple to understand and contain a number of useful helper functions. They can be imported using `const Name = imports.<name>;`.
|
|
|
|
|
|
Each heading below is a link to the JavaScript source, which are decently documented and informative of usage.
|
|
|
|
... | ... | @@ -48,6 +48,8 @@ String.prototype.format = Format.format; |
|
|
_("%d:%d").format(hours, minutes);
|
|
|
```
|
|
|
|
|
|
> **PC** You could mention that string templates (backtick strings) are an easier and more Javascript-y way to do this. I wouldn't recommend using Format in new code except in a few specialized situations.
|
|
|
|
|
|
### [Gettext](https://gitlab.gnome.org/GNOME/gjs/blob/master/modules/gettext.js)
|
|
|
|
|
|
Helper functions for gettext. See also [examples/gettext.js][example-gettext] for usage.
|
... | ... | @@ -60,6 +62,8 @@ Unit test functions for GJS, demonstrated extensively in the [test-suite][instal |
|
|
|
|
|
[installed-tests]: https://gitlab.gnome.org/GNOME/gjs/blob/master/installed-tests/js
|
|
|
|
|
|
> **PC** JSUnit isn't actually used anywhere in GJS anymore. It's a module so other code can still use it, but it's not actually a very good unit test library. I wouldn't recommend using it.
|
|
|
|
|
|
### [Lang](https://gitlab.gnome.org/GNOME/gjs/blob/master/modules/lang.js)
|
|
|
|
|
|
Utilities that are "meta-language" things like manipulating object props.
|
... | ... | @@ -93,10 +97,14 @@ var MyNewClass = class { |
|
|
}
|
|
|
```
|
|
|
|
|
|
> **PC** I'd mention here that Lang is pretty much obsolete these days too.
|
|
|
|
|
|
### [Mainloop](https://gitlab.gnome.org/GNOME/gjs/blob/master/modules/mainloop.js)
|
|
|
|
|
|
Some of the GLib methods pertaining to the Main Event Loop are mapped with different argument signatures in GJS. The Mainloop module provides a layer of convenience and backwards-compatibility over these functions.
|
|
|
|
|
|
> **PC** I'm not actually sure why Mainloop exists. The difference in arguments is because `g_timeout_add_full()` maps to `GLib.timeout_add()` which is specified in the GLib source: https://github.com/GNOME/glib/blob/master/glib/gmain.c#L4723 It's mildly more convenient, I guess.
|
|
|
|
|
|
```js
|
|
|
const GLib = imports.gi.GLib;
|
|
|
const Mainloop = imports.mainloop;
|
... | ... | |