3.0.0 • Published 5 years ago

checkpath v3.0.0

Weekly downloads
-
License
GPL-2.0
Repository
github
Last release
5 years ago

checkpath

Check the existence, type and permission of path specified

Usage

npm i checkpath

javascript:

const checkpath=require('checkpath')
checkpath('/home/you')
.then(() => {
  console.log('path exists!')
  })
  .catch(e => {
    if(e.code=='ENOENT') console.log('path not exists!')
  })

typescript:

import { SystemError, checkpath } from 'checkpath'
checkpath('/home/you', {
    type: 'd',
    permission: 'w'
})
.then()
.catch((e : SystemError) => {
    if(e.code === 'ENOENT') console.log('/home/you dose not exist!')
    else if(e.code === 'EACCES' || e.code === 'EPERM') console.log('/home/you refused access!')
    else if(e.code === 'ENOTDIR') console.log('/home/you is not a directory!')
})

The returned promise is resolved with no arguments on success, rejected with the first error encountered on failure. callback version is similar.

e.code:

  • ENOENT existence check failed
  • EISDIR {type:'f'} is passed but it is directory
  • ENOTDIR {type:'d'} is passed but it is file
  • EACCES permission check failed

Configuration

checkpath receives at most 3 arguments (path, opt, callback)

  • path is the relative or absolute path of the path being checked
  • opt:

    • type:'f'/'d'
    • permission:'w'/'r'

    by default only the existence of the path is checked. the type of the path is checked only if type is defined. The read/write permission can also be checked on request. note that when permission is specified, read access is always checked.

  • callback is the callback function(error). If not defined, a promise is returned instead

Test

npm t
3.0.0

5 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago