Skip to content

Commit

Permalink
feat(exports): add exports for sync hasMagic Glob and original …
Browse files Browse the repository at this point in the history
…async
  • Loading branch information
Ahmad Nassri committed Dec 16, 2016
1 parent 76435d2 commit 4f20338
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ npm install --only=production --save glob-promise

## API

### glob(pattern [, options])
### `glob(pattern [, options])`

Alias for `glob.promise`

### `glob.promise(pattern [, options])`

_pattern_: `String` (glob pattern)
_options_: `Object` or `String`
Expand All @@ -41,6 +45,23 @@ glob('{foo,bar.baz}.txt', { nobrace: true })
});
```

### `glob.glob(pattern [, options], cb)`

> see [`glob`](https://github.com/isaacs/node-glob#globpattern-options-cb)
### `glob.sync(pattern [, options])`

> see [`glob.sync()`](https://github.com/isaacs/node-glob#globsyncpattern-options)
### `glob.hasMagic(pattern, [options])`

> see [`glob.hasMagic()`](https://github.com/isaacs/node-glob#globhasmagicpattern-options)
### `Class: glob.Glob`

> see [`Glob`](https://github.com/isaacs/node-glob#class-globglob)

#### options

The option object will be directly passed to [glob](https://github.com/isaacs/node-glob#options).
Expand Down
12 changes: 11 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

const glob = require('glob')

module.exports = function (pattern, options) {
const promise = function (pattern, options) {
return new Promise((resolve, reject) => {
glob(pattern, options, (err, files) => err === null ? resolve(files) : reject(err))
})
}

// default
module.exports = promise

// utility exports
module.exports.glob = glob
module.exports.Glob = glob.Glob
module.exports.hasMagic = glob.hasMagic
module.exports.promise = promise
module.exports.sync = glob.sync
19 changes: 15 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
const glob = require('../lib')
const test = require('tap').test

test('should successfully parse', assert => {
test('exports', assert => {
assert.plan(6)

assert.type(glob, 'function')
assert.type(glob.glob, 'function')
assert.type(glob.Glob, 'function')
assert.type(glob.hasMagic, 'function')
assert.type(glob.promise, 'function')
assert.type(glob.sync, 'function')
})

test('successfully parse', assert => {
assert.plan(2)

glob('test/**')
Expand All @@ -13,21 +24,21 @@ test('should successfully parse', assert => {
})
})

test('should be rejected when globbing fails', assert => {
test('be rejected when globbing fails', assert => {
assert.plan(1)

glob('/**/*', { silent: true })
.catch(err => assert.equal(err.code, 'EACCES'))
})

test('should throw a type error when the first argument is not a string.', assert => {
test('throw a type error when the first argument is not a string.', assert => {
assert.plan(1)

glob({})
.catch(err => assert.equal(err.message, 'glob pattern string required'))
})

test('should throw a type error when it takes no arguments.', assert => {
test('throw a type error when it takes no arguments.', assert => {
assert.plan(1)

glob()
Expand Down

0 comments on commit 4f20338

Please sign in to comment.