{"id":13241,"library":"glob2base","title":"Glob Base Path Extractor","description":"glob2base is a small, focused utility library for Node.js that extracts the static base path portion from a `node-glob` instance. It identifies the non-globbing part of a pattern (e.g., `js/` from `js/**/*.js`), allowing for operations on the fixed directory structure before any file matching occurs. The current stable version is 0.0.12, which was last updated in 2015. The project appears to be unmaintained, with no significant updates in a long time, indicating an abandoned release cadence. Its primary differentiator is its direct integration with `node-glob`'s internal structure to derive the base path, rather than attempting to parse glob strings independently, though this tight coupling might also limit its flexibility with other glob implementations or newer `node-glob` versions.","status":"abandoned","version":"0.0.12","language":"javascript","source_language":"en","source_url":"git://github.com/wearefractal/glob2base","tags":["javascript"],"install":[{"cmd":"npm install glob2base","lang":"bash","label":"npm"},{"cmd":"yarn add glob2base","lang":"bash","label":"yarn"},{"cmd":"pnpm add glob2base","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"glob2base takes an instance of `node-glob` as its input, making `glob` a core runtime dependency for any practical use.","package":"glob","optional":false}],"imports":[{"note":"This package is a CommonJS module and exports a single function as its default. Direct `import` statements will fail in pure ESM environments or without transpilation due to its CJS nature.","wrong":"import glob2base from 'glob2base';","symbol":"(Default Export)","correct":"const glob2base = require('glob2base');"},{"note":"glob2base expects an instance of `glob.Glob`. Ensure the `glob` package is imported correctly, typically using CommonJS `require()` as well, especially if using an older version of `glob`.","wrong":"import { Glob } from 'glob';\nconst globInstance = new Glob('pattern');","symbol":"Glob (from 'glob')","correct":"const glob = require('glob');\nconst globInstance = new glob.Glob('pattern');"}],"quickstart":{"code":"const glob2base = require('glob2base');\nconst glob = require('glob'); // Make sure 'glob' is installed (npm install glob)\n\n// Create a new Glob instance for 'js/**/*.js'\nconst globInstance1 = new glob.Glob('js/**/*.js');\nconst base1 = glob2base(globInstance1);\nconsole.log(`Base path for 'js/**/*.js': ${base1}`); // Expected output: js/\n\n// Create a new Glob instance for 'css/test/{a,b}/*.css'\nconst globInstance2 = new glob.Glob('css/test/{a,b}/*.css');\nconst base2 = glob2base(globInstance2);\nconsole.log(`Base path for 'css/test/{a,b}/*.css': ${base2}`); // Expected output: css/test/\n\n// Create a new Glob instance for a specific file 'pages/whatever/index.html'\nconst globInstance3 = new glob.Glob('pages/whatever/index.html');\nconst base3 = glob2base(globInstance3);\nconsole.log(`Base path for 'pages/whatever/index.html': ${base3}`); // Expected output: pages/whatever/","lang":"javascript","description":"This quickstart demonstrates how to import `glob2base` and `glob`, then use `glob2base` to extract the common base path from various `node-glob` patterns, printing the result to the console."},"warnings":[{"fix":"Consider migrating to a maintained alternative or thoroughly auditing the package for security and compatibility if continued use is necessary.","message":"The package has not been updated since 2015 and is considered abandoned. It may contain unpatched security vulnerabilities or have compatibility issues with modern Node.js environments and newer versions of its `glob` dependency.","severity":"breaking","affected_versions":"0.0.12"},{"fix":"Use `const glob2base = require('glob2base');` for CJS environments or configure your ESM project to correctly interoperate with CommonJS modules (e.g., using `createRequire` in Node.js ESM).","message":"`glob2base` is a CommonJS module. Attempting to use `import` statements directly in a pure ESM project will lead to errors.","severity":"gotcha","affected_versions":"0.0.12"},{"fix":"Create a `glob2base.d.ts` file with `declare module 'glob2base' { function glob2base(globInstance: any): string; export = glob2base; }` or a more specific type if desired.","message":"There are no official TypeScript declaration files (`.d.ts`) provided for `glob2base`. Users integrating this package into TypeScript projects will need to create their own ambient module declarations.","severity":"gotcha","affected_versions":"0.0.12"},{"fix":"Test `glob2base` thoroughly if updating the `glob` dependency to a new major version. If issues arise, consider pinning an older, compatible `glob` version or seeking an alternative base path extractor.","message":"`glob2base` relies on the internal structure of `node-glob` instances. Future major versions of the `glob` package could introduce breaking changes to its internal `Glob` class, potentially causing `glob2base` to malfunction.","severity":"gotcha","affected_versions":"0.0.12"},{"fix":"Proceed with caution on modern Node.js versions. If encountering unexpected behavior, investigate potential incompatibilities or use an alternative.","message":"The package's `engines` field specifies Node.js `>= 0.10`, which is extremely outdated. While simple CJS modules often function on newer Node.js versions, there's no guarantee of full compatibility or optimal performance.","severity":"gotcha","affected_versions":"0.0.12"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using the CommonJS default import: `const glob2base = require('glob2base');`.","cause":"This error typically occurs when `glob2base` is not correctly imported as a default (function) export, often by attempting `import { glob2base } from 'glob2base';`.","error":"TypeError: glob2base is not a function"},{"fix":"Change the import statement to a CommonJS `require`: `const glob2base = require('glob2base');`.","cause":"Attempting to `import glob2base from 'glob2base';` in a CommonJS module context or an unconfigured pure ESM environment without proper interop setup.","error":"ERR_REQUIRE_ESM or SyntaxError: Cannot use import statement outside a module"},{"fix":"Try installing an older, compatible version of the `glob` package (e.g., `npm install glob@^7.0.0` or `glob@^6.0.0`) or consider using a more recently maintained alternative for extracting base paths from glob patterns.","cause":"This issue arises when `glob2base` attempts to access internal properties of the `glob` instance that have either changed or been removed in a newer major version of the `glob` package, leading to incompatibility.","error":"TypeError: Cannot read properties of undefined (reading 'minimatch') or similar errors related to `glob` internals."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}