From 57b8b8e18e5e2007114c63b71bf0baedc01936a6 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sun, 23 Jun 2024 01:08:59 -0500 Subject: [PATCH] path: add `matchesGlob` method PR-URL: https://github.com/nodejs/node/pull/52881 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum --- doc/api/path.md | 23 +++++++++++++++++ lib/path.js | 32 ++++++++++++++++++++++++ test/parallel/test-path-glob.js | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 test/parallel/test-path-glob.js diff --git a/doc/api/path.md b/doc/api/path.md index c7a999cbb1ec22..ef710106efd23b 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -279,6 +279,29 @@ path.format({ // Returns: 'C:\\path\\dir\\file.txt' ``` +## `path.matchesGlob(path, pattern)` + + + +> Stability: 1 - Experimental + +* `path` {string} The path to glob-match against. +* `pattern` {string} The glob to check the path against. +* Returns: {boolean} Whether or not the `path` matched the `pattern`. + +The `path.matchesGlob()` method determines if `path` matches the `pattern`. + +For example: + +```js +path.matchesGlob('/foo/bar', '/foo/*'); // true +path.matchesGlob('/foo/bar*', 'foo/bird'); // false +``` + +A [`TypeError`][] is thrown if `path` or `pattern` are not strings. + ## `path.isAbsolute(path)`