New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

remove-prefix

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remove-prefix

Removes a string from the beginning of another string.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

remove-prefix

Removes a string from the beginning of another string.

Installation

Requires Node.js 6.0.0 or above.

npm i remove-prefix

API

The module exports a single function.

Parameters

  • Bindable: subject (string): The string that may or may not have a prefix to be removed.
  • ...prefixes (one or more of: string or Array of strings): The first prefix found will be removed. Longer prefixes are checked first.

Return Value

A two-element Array:

  • The string without its prefix, or the original string if no prefix was found.
  • The prefix if one was found; otherwise an empty string.

Example

const removePrefix = require('remove-prefix')

const subject = 'abcdef'
let result, prefix

// Removes the prefix
[result] = removePrefix(subject, 'abc')
result // 'def'

// Returns prefix as second element, or returns an empty string if not found
[result, prefix] = removePrefix(subject, 'xyz')
result // 'abcdef'
prefix // ''

// Removes the first prefix found. Longer prefixes are checked first.
// Prefixes can be given as an arguments list or in an array.
[result, prefix] = removePrefix(subject, 'xyz', 'abc', 'de')
result // 'def'
prefix // 'abc'

// Supports the bind operator
subject::removePrefix('abc') // ['def', 'abc']
  • remove-suffix: Removes a string from the end of another string.

Keywords

remove

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts