Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@igor.dvlpr/magic-string

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@igor.dvlpr/magic-string

๐Ÿงต An expressive and chainable library for advanced string manipulations. Supports appending, prepending, trimming, quoting, and path formatting with customizable whitespace handling. Makes advanced String manipulations a piece of cake. ๐Ÿฆฅ

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by75%
Maintainers
0
Weekly downloads
ย 
Created
Source

MagicString


๐Ÿงต An expressive and chainable library for advanced string manipulations.
Supports appending, prepending, trimming, quoting, and
path formatting with customizable whitespace handling. ๐Ÿฆฅ

Makes advanced String manipulations a piece of cake.



๐Ÿ’– Support further development
I work hard for every project, including this one
and your support means a lot to me!

Consider buying me a coffee. โ˜•
Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š


Donate to igorskyflyer

@igorskyflyer




๐Ÿ“ƒ Table of contents



๐Ÿ•ต๐Ÿผ Usage

Install it by executing:

npm i '@igor.dvlpr/magic-string'

๐Ÿคน๐Ÿผ API

All string-related methods use a common string type that can either be a string or a string array. StringValue defined as:

type StringValue = string | string[]


constructor(): MagicString

Creates a new instance of MagicString.


value: string

Gets the accumulator value.

Returns the accumulator as a string.


isEmpty(): boolean

Checks if the accumulator is empty.

Returns true if the accumulator is empty, false otherwise.


clear(): MagicString

Clears the accumulator.

Returns the current instance of MagicString.


append(value: StringValue): MagicString

Appends a value to the accumulator.

value - The value to append.


Returns the current instance of MagicString.


appendSingleQuoted(value: StringValue): MagicString

Appends a single-quoted value to the accumulator.

value - The value to append.


Returns the current instance of MagicString.


appendQuoted(value: StringValue): MagicString

Appends a double-quoted value to the accumulator.

value - The value to append.


Returns the current instance of MagicString.


trimAll(): MagicString

Trims all whitespace in the accumulator.


Returns the current instance of MagicString.


trim(): MagicString

Trims only leading and trailing whitespace from the accumulator.


Returns the current instance of MagicString.


trimOn(): MagicString

Enables trimming of values before adding them to the accumulator.


Returns the current instance of MagicString.


trimOff(): MagicString

Disables trimming of values before adding them to the accumulator.


Returns the current instance of MagicString.


path(value: StringValue): MagicString

Appends a value representing a path to the accumulator, wrapping it in double quotes if necessary.

value - The path value to append.


Returns the current instance of MagicString.


prepend(value: StringValue): MagicString

Prepends a value to the accumulator.

value - The value to prepend.


Returns the current instance of MagicString.


toLowerCase(): MagicString

Converts the accumulator to lower case.


Returns the current instance of MagicString.


toUpperCase(): MagicString

Converts the accumulator to upper case.


Returns the current instance of MagicString.


โœจ Examples

example.ts

import { MagicString } from '@igor.dvlpr/magic-string'


console.log(
  new MagicString()
    .append('Hello')
    .appendSingleQuoted('world')
    .appendQuoted('this is     a test')
    .prepend('Start:    ')
    .trimAll()
    .path('/usr/local/bin')
    .toUpperCase()
    .path('/usr/local/my file.txt"') // intentional stray quote
    .toLowerCase()
    .toUpperCase()
    .trimOn()
    .append('   Trimmed   ')
    .trimOff()
    .append('  Not trimmed')
    .trim().value
)

// prints 'START: HELLO \'WORLD\' "THIS IS A TEST" /USR/LOCAL/BIN "/USR/LOCAL/MY FILE.TXT" Trimmed   Not trimmed'

๐Ÿ“ Changelog

๐Ÿ“‘ The changelog is available here: CHANGELOG.md.


๐Ÿชช License

Licensed under the MIT license which is available here, MIT license.


@igor.dvlpr/extendable-string

๐Ÿฆ€ ExtendableString allows you to create strings on steroids that have custom transformations applied to them, unlike common, plain strings. ๐Ÿช€


@igor.dvlpr/str-is-in

๐Ÿงต Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. ๐Ÿ”


@igor.dvlpr/normalized-string

๐Ÿ’Š NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐Ÿ“ฎ


@igor.dvlpr/astro-escaped-component

๐Ÿƒ๐Ÿปโ€โ™‚๏ธโ€โžก๏ธ An Astro component that holds only HTML-encoded content. ๐Ÿ“œ


@igor.dvlpr/strip-html

๐Ÿฅž Removes HTML code from the given string. Can even extract text-only from the given an HTML string. โœจ



๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author

Created by Igor Dimitrijeviฤ‡ (@igorskyflyer).

Keywords

FAQs

Package last updated on 01 Aug 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc