Modules@robinpath/glob
glob

@robinpath/glob

0.1.1Node.jsPublic

File pattern matching: find files by glob patterns, test matches, expand braces

Glob

File pattern matching: find files by glob patterns, test matches, expand braces

Package: @robinpath/glob | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the glob module when you need to:

  • Find files matching a glob pattern -- Use glob.match to perform this operation
  • Test if a path matches a glob pattern -- Use glob.isMatch to perform this operation
  • Convert a glob pattern to a regex string -- Use glob.toRegex to perform this operation
  • Expand brace pattern into array -- Use glob.expand to perform this operation
  • Extract non-glob base directory from pattern -- Use glob.base to perform this operation

Quick Reference

FunctionDescriptionReturns
matchFind files matching a glob patternArray of matching file paths
isMatchTest if a path matches a glob patternTrue if matches
toRegexConvert a glob pattern to a regex stringRegex source string
expandExpand brace pattern into arrayArray of expanded strings
baseExtract non-glob base directory from patternBase directory path
hasMagicCheck if string contains glob charactersTrue if contains glob chars

Functions

match

Find files matching a glob pattern

Module: glob | Returns: array -- Array of matching file paths

glob.match "src/**/*.ts"
ParameterTypeRequiredDescription
patternstringYesGlob pattern (e.g. **/*.ts)
cwdstringNoWorking directory (default: .)

isMatch

Test if a path matches a glob pattern

Module: glob | Returns: boolean -- True if matches

glob.isMatch "src/index.ts" "**/*.ts"
ParameterTypeRequiredDescription
filePathstringYesFile path to test
patternstringYesGlob pattern

toRegex

Convert a glob pattern to a regex string

Module: glob | Returns: string -- Regex source string

glob.toRegex "*.ts"
ParameterTypeRequiredDescription
patternstringYesGlob pattern

expand

Expand brace pattern into array

Module: glob | Returns: array -- Array of expanded strings

glob.expand "file.{ts,js}"
ParameterTypeRequiredDescription
patternstringYesPattern with braces (e.g. {a,b,c})

base

Extract non-glob base directory from pattern

Module: glob | Returns: string -- Base directory path

glob.base "src/**/*.ts"
ParameterTypeRequiredDescription
patternstringYesGlob pattern

hasMagic

Check if string contains glob characters

Module: glob | Returns: boolean -- True if contains glob chars

glob.hasMagic "*.ts"
ParameterTypeRequiredDescription
strstringYesString to check

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Match and validate result"
do
  set $result as glob.match "src/**/*.ts"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Glob workflow

Chain multiple glob operations together.

@desc "Match, is match, and more"
do
  set $r_match as glob.match "src/**/*.ts"
  set $r_isMatch as glob.isMatch "src/index.ts" "**/*.ts"
  set $r_toRegex as glob.toRegex "*.ts"
  print "All operations complete"
enddo

2. Safe match with validation

Check results before proceeding.

@desc "Match and validate result"
do
  set $result as glob.match "src/**/*.ts"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/glob

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size4.1 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities