A toolkit for path can run in browsers and node runtime. But I think it is proper for javascript codes in browsers because of the module called path in Node.js.
The lib aim to handle path in the same logic between browser and backend.
npm install --save path-tookit
import pathTookit from 'path-tookit';
pathTookit.join('') // console .
pathTookit.join('/a', 'b', 'c') // console /a/b/c
pathTookit.join('/a', '..', 'c') // console /c
pathTookit.join('./', '/a', 'b') // console a/b
pathTookit.normalize('a/b/../c') // console a/c
pathTookit.normalize('//a//b//c//') // console /a/b/c/
pathTookit.isAbsolute('/abc/') // console true
pathTookit.isAbsolute('./') // console false
pathTookit.existTailSlash('/a/b/c/') // console true
pathTookit.existTailSlash('/a/b/c') // console false
<script src="http://example.com/public/node_modules/path-tookit/dist/path-tookit.js"></script>
<script>
window.join('/a', 'b', 'c')
</script>
Join path segments to a path string. Note that:
- Empty strings ‘’ will be converted to '.'
- The './' which strings start with will be removed like './a/b/c' to 'a/b/c'
- Strings start with '../' will be regard as relative path
Normalizes the path param. It can resolve '.' and '..' and remove extra slashes. The logic about resolving empty strings, './', '../' is same as join() method.
Judge if the path param is a absolute path.
Judge if there is a '/' at the end of the path param.
If you have any questions or requirements, use Issues.