[gjs: 1/2] doc: add an example to get relative filename and dirname with import.meta.url
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] doc: add an example to get relative filename and dirname with import.meta.url
- Date: Fri, 9 Apr 2021 03:35:00 +0000 (UTC)
commit b5e7802d80b399b868505067556a7fe40e8565f1
Author: Sonny Piers <sonny fastmail net>
Date: Thu Apr 8 16:41:01 2021 +0000
doc: add an example to get relative filename and dirname with import.meta.url
doc/ESModules.md | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/doc/ESModules.md b/doc/ESModules.md
index b63f06b6..850c2602 100644
--- a/doc/ESModules.md
+++ b/doc/ESModules.md
@@ -201,6 +201,14 @@ const data = file.get_parent().resolve_relative_path('data.json');
const [, contents] = data.load_contents(null);
```
+or if you want the path for the current file or directory
+
+```js
+import GLib from 'gi://GLib';
+const [filename] = GLib.filename_from_uri(import.meta.url);
+const dirname = GLib.path_get_dirname(path);
+```
+
## Interoperability with legacy `imports` modules
Because `imports` is a global object, it is still available in ES
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]