Extended magic-string with extra utilities

Overview

DEPRECATED. It has been ported back to magic-string >= 0.26.0


magic-string-extra

NPM version

Extended Rich-Harris/magic-string with extra utilities.

Install

npm i magic-string-extra

magic-string-extra can be a drop-in replacement for magic-string:

- import MagicString from 'magic-string'
+ import MagicString from 'magic-string-extra'

Extra Utils

Check magic-string's documentation for the base utils.

.replace()

Shares the same signature as String.prototype.replace. Supports RegExp and replacer functions.

import MagicString from 'magic-string-extra'

const s = new MagicString(source)

s.replace(foo, 'bar')
s.replace(/foo/g, 'bar')
s.replace(/(\w)(\d+)/g, (_, $1, $2) => $1.toUpperCase() + $2)

The differences from String.replace:

  • It will always match against the original string
  • It mutates the magic string state (use .clone() to be immutable)

.hasChanged()

In some cases, when the string does not change you might be able to skip the sourcemap generation to improve the performance (e.g. Rollup and Vite's transform hook). This function allows you to check the state without tracking it externally.

import MagicString from 'magic-string-extra'

const s = new MagicString(source)

s.hasChanged() // false

s.prepend('foo')

s.hasChanged() // true

.toRollupResult()

It's common to use the magic string for code transformations in plugins. This function provides a shorthand to generate the result in Rollup's TransformResult format. When the string has not changed, null will be returned to skip the Rollup transformation.

import MagicString from 'magic-string-extra'

const s = new MagicString(source)

s.toRollupResult() // { code, map } | null

Included Upstream PRs

Sponsors

License

MIT License © 2022 Anthony Fu

You might also like...

Extra modifications and enhancements for Discord Bot Maker. Mods you won't find on the DBM Network!

Extra modifications and enhancements for Discord Bot Maker. Mods you won't find on the DBM Network!

DBM Extended is a open source project meant to enhance and extend Discord Bot Maker. Downloads This repository is not meant to be downloaded or cloned

Oct 10, 2022

Pure JS Auto Complete plugin with extra features.

Pure JS Auto Complete plugin with extra features.

Cndk.AutoComplete.js Cndk.AutoComplete.js is a pure JavaScript plugin. It performs auto-complete operations within an INPUT. Installation Include the

Jan 25, 2022

A JSX transformer with extra hints around interpolations and outer templates.

@ungap/babel-plugin-transform-hinted-jsx This plugin is a follow up of this post and it can be used together with @babel/plugin-transform-react-jsx. A

Nov 12, 2022

Weather-magic - Working with APIs to create a weather dashboard

Weather-magic - Working with APIs to create a weather dashboard

Weather Magic link to website Following the link above will bring you to the Wea

Feb 3, 2022

Querying Solana Blockchain, leveraging Magic Eden Apis!

Querying Solana Blockchain, leveraging Magic Eden Apis!

Solana Bot Deployment Instructions- Create a bot on discord dev portal learn basics here Copy the Bot Token and go to OAuth field for URL generation F

Sep 8, 2022

Adds a handy $parent magic property to your Alpine components.

✨ Help support the maintenance of this package by sponsoring me. Alpine $parent Access parent components using a handy $parent magic variable. This pa

Aug 29, 2022

The Remix Stack for Web2 apps and Web3 DApps with authentication with Magic, testing, linting, formatting, etc.

The Remix Stack for Web2 apps and Web3 DApps with authentication with Magic, testing, linting, formatting, etc.

Remix French House Stack Learn more about Remix Stacks. npx create-remix --template janhesters/french-house-stack What's in the Stack? The French Hou

Dec 26, 2022

MagicSniffer is a amazing tool could help you decrypt GI traffic by MAGIC of WindSeedClientNotify

MagicSniffer We have posted an article about this on sdl.moe: 原神 2.8 KCP 验证密钥交互流程解析与流量解密 As everyone knows, RSA is the most secure way to encrypt data

Dec 29, 2022

Flexible JavaScript library for creating squircley magic ✨

Flexible JavaScript library for creating squircley magic ✨

squircley.js squircley.js is the core squirclular magic ✨ from https://squircley.app wrapped up into a simple, 0 dependency JavaScript library. squirc

Dec 24, 2022
Releases(v0.1.2)
Owner
Anthony Fu
A ship in harbor is safe, but that is not what ships are built for.
Anthony Fu
A plugin that provides utilities for extended backgrounds and borders.

tailwindcss-full-bleed A plugin that provides utilities for extended backgrounds and borders. Demo Installation Install the plugin from npm: npm insta

Doğukan Çavuş 8 Dec 24, 2022
Convert some JavaScript/TypeScript code string into a .d.ts TypeScript Declaration code string

convert-to-dts Converts the source code for any .js or .ts file into the equivalent .d.ts code TypeScript would generate. Usage import { convertToDecl

Lily Scott 11 Mar 3, 2022
Simple and Extensible Markdown Parser for Svelte, however its simplicity can be extended to any framework.

svelte-simple-markdown This is a fork of Simple-Markdown, modified to target Svelte, however due to separating the parsing and outputting steps, it ca

Dave Caruso 3 May 22, 2022
An extended table to integration with some of the most widely used CSS frameworks.

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)

文翼 11.4k Dec 20, 2022
Extended version of create-t3-app to make it even faster to start (or maybe slower)

create-T3-app with extra tools/config out of the box create-t3-app is one of the fastest and easiest way to scaffold fullstack app. create-t3-extended

A Riolly C 7 Jan 4, 2023
Obsidian plugin allowing for linking to a heading range, in the [[Page#HeaderA#HeaderB]] extended wikilink format.

Obsidian Link Heading Range Plugin This is a plugin for Obsidian (https://obsidian.md). It allows linking to a heading range, in the [[Page#HeaderA#He

Anthropologie Biblique 7 Nov 14, 2022
Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

parallax-vanilla.js Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra perfo

Erik Engervall 91 Dec 16, 2022
DevArms - a collection of developer utils that gives you extra arms to reach more in your tasks

DevArms is a collection of developer utils that gives you extra arms to reach more in your tasks. It runs completely offline, and cross-platform across Windows, Mac and Linux. Written in Rust, React. Powered by Tauri.

Qiushi Pan 82 Dec 18, 2022
Lavalink client with lots of extra functionality, easy to use and well optimized.

?? nSysLava Lavalink client with lots of extra functionality, easy to use and well optimized! พัฒนาโดยคนไทย ?? Many utility functions - มีฟังก์ชันอรรถ

nicenathapong 3 Apr 12, 2022
Completely free TS/JS one-file source code snippets with tests, which can be copied to avoid extra dependencies (contributions welcome).

TinySource Completely free TS/JS one-file source code snippets with tests, which can be copied to avoid extra dependencies (contributions welcome). Sn

null 81 Jan 3, 2023