1. pre-suf
Manipulate strings with prefixes and suffixes.
pre-suf
Package: pre-suf
Created by: kaelzhang
Last modified: Fri, 24 Jun 2022 13:24:34 GMT
Version: 1.1.1
License: MIT
Downloads: 2,326
Repository: https://github.com/kaelzhang/node-pre-suf

Install

npm install pre-suf
yarn add pre-suf

Build Status

pre-suf

Manipulate strings with prefixes and suffixes.

Install

 $ npm install pre-suf --save

Usage

 const presuf = require('pre-suf')

presuf.ensureLeading('path/to', '/')    // '/path/to'
presuf.removeEnding('/path/to//', '/')  // '/path/to'

presuf.ensureLeading(str, prefix)

Ensures that the new string will have prefix at the beginning of str.

If str does not begin with prefix, prefix will be added to the beggining of str.

presuf.removeLeading(str, prefix)

Removes the leading prefix of str.

 presuf.removeLeading('/abc', '/a')       // 'bc'
presuf.removeLeading('/a/abc', '/a')     // 'bc'. removes 2 groups of '/a'

presuf.ensureEnding(str, suffix)

presuf.removeEnding(str, suffix)

License

MIT

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code