drewmrk / get-url-slug

Get the last part of a URL (slug)

Home Page:https://www.npmjs.com/package/get-url-slug

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get-url-slug

Get the last part of a URL (slug)

Why?

I have noticed that recently I have been needing to grab the slug of a URL and also noticed that the NPM repository did not have any (that I could find) packages that simply retrieved the slug of a URL. Tired of manually getting the slug everytime, I decided to create this package.

Usage

*Assume the URL in every example/demonstration is https://example.com/one/two/three

import getURLSlug from 'get-url-slug'

console.log(getURLSlug()) // `three`

You can also pass two parameters to the function, pattern and range.

pattern uses a string/character of your choice (by default it is /) range is the index past the location of pattern to be used (by default it is 1)

import getURLSlug from 'get-url-slug'

console.log(getURLSlug('e/')) // `/two/three`
import getURLSlug from 'get-url-slug'

console.log(getURLSlug('e/t', 3)) // `ow/three`

About

Get the last part of a URL (slug)

https://www.npmjs.com/package/get-url-slug

License:MIT License


Languages

Language:TypeScript 100.0%