Giter Club home page Giter Club logo

path-toolkit's Introduction

path-toolkit

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.

Build Status Coverage Status

Get Started

npm install --save path-tookit

Commonjs/CMD

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

Browser without AMD/CMD/UMD

<script src="http://example.com/public/node_modules/path-tookit/dist/path-tookit.js"></script>
<script>
window.join('/a', 'b', 'c')
</script>		

API

join(path1,path2...)

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

normalize(path)

Normalizes the path param. It can resolve '.' and '..' and remove extra slashes. The logic about resolving empty strings, './', '../' is same as join() method.

isAbsolute(path)

Judge if the path param is a absolute path.

existTailSlash(path)

Judge if there is a '/' at the end of the path param.

Feedback



If you have any questions or requirements, use Issues.

path-toolkit's People

Contributors

yedaodao avatar gerhut avatar

Stargazers

Jinyang Liu avatar Max Liu avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

gerhut

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.