magic-string - Manipulate strings like a wizard

  •        4

Suppose you have some source code. You want to make some light modifications to it - replacing a few characters here and there, wrapping it with a header and footer, etc - and ideally you'd like to generate a source map at the end of it. You've thought about using something like recast (which allows you to generate an AST from some JavaScript, manipulate it, and reprint it with a sourcemap without losing your comments and formatting), but it seems like overkill for your needs (or maybe the source code isn't JavaScript).Your requirements are, frankly, rather niche. But they're requirements that I also have, and for which I made magic-string. It's a small, fast utility for manipulating strings and generating sourcemaps.

https://github.com/Rich-Harris/magic-string

Tags
Implementation
License
Platform

   




Related Projects

strman-java - A Java 8 string manipulation library.


A Java 8 library for working with Strings. You can learn about all the String utility functions implemented in strman library by reading the documentation. To use strman in your application, you have to add strman to your classpath. strman is available on Maven Central so you just need to add dependency in your favorite build tool as shown below.

underscore.string - String manipulation helpers for javascript


Javascript lacks complete string manipulation operations. This is an attempt to fill that gap. List of build-in methods can be found for example from Dive Into JavaScript. Originally started as an Underscore.js extension but is a full standalone library nowadays.Upgrading from 2.x to 3.x? Please read the changelog.

Guitar - A Cross-Platform String and Regular Expression Library written in Swift.


This library seeks to add common string manipulation functions, including common regular expression capabilities, that are needed in both mobile and server-side development, but are missing in Swift's Standard Library. The full documentation can be found at http://www.sabintsev.com/Guitar/.

pyxl - A Python extension for writing structured and reusable inline HTML.


At Cove, where Pyxl was developed, we found that using templates was getting in the way of quickly building new features. There were the usual issues of remembering to escape data to prevent XSS holes, avoiding invalid markup and deciphering cryptic stack traces. More importantly, our templates were getting hard to manage and understand which made iterating on our product more work than should be necessary.Existing templating systems do support things like logic and reusable modules - but they a

underscore.string - String manipulation extensions for Underscore.js javascript library.


String manipulation extensions for Underscore.js javascript library.


Stringy - A PHP string manipulation library with multibyte support


A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM.Refer to the 1.x branch or 2.x branch for older documentation.

s.el - The long lost Emacs string manipulation library.


The long lost Emacs string manipulation library. Or you can just dump s.el in your load path somewhere.

Fuzzy string matching algorithm in C# and LINQ


Fuzzy matching strings. Find out how similar two string is, and find the best fuzzy matching string from a string table. Given a string (strA) and a big string table. Find the likeness or similarity of the string in the string table. Using C# and LINQ

mmmagic - An async libmagic binding for node.js for detecting content types by data inspection


An async libmagic binding for node.js for detecting content types by data inspection.detectFile(< String >path, < Function >callback) - (void) - Inspects the file pointed at by path. The callback receives two arguments: an < Error > object in case of error (null otherwise), and a < String > containing the result of the inspection.

StringDefs


C# and VB.NET are great languages but they lack the highly abstracted string processing routines. Other contemporary scripting languages like perl, python has good support for string processing. StringDefs allows developers to write powerful string processing in .NET.

string.js - Extra JavaScript string methods.


string.js, or simply S is a lightweight (< 5 kb minified and gzipped) JavaScript library for the browser or for Node.js that provides extra String methods. Originally, it modified the String prototype. But I quickly learned that in JavaScript, this is considered poor practice.Personally, I prefer the cleanliness of the way code looks when it appears to be native methods. i.e. when you modify native JavaScript prototypes. However, if any app dependency required string.js, then the app's string prototype would be modified in every module. This could be troublesome. So I settled on creating a wrapper a la jQuery style. For those of you prototype hatin' fools, there is the method extendPrototype().

string_score - JavaScript string ranking 0 for no match upto 1 for perfect


Simply include one of the string score JavaScript files and call the .score() method on any string. ** IE 7 fails (stop running this script message) with 4000 iterations of the benchmark test. All other browsers tested survived this test, and in fact survive a larger number of iterations. The benchmark that is causing IE to choke is: 4000 iterations of 446 character string scoring a 70 character match.

autolink-js - Tiny little tool to find URLs in a string of text and hyperlink them


autolink-js is a small (about half a kilobyte), simple, and tested JavaScript tool that takes a string of text, finds URLs within it, and hyperlinks them. I recently needed to find and hyperlink URLs in user-submitted text and was surprised to find that doing what seemed like such a simple task wasn't already a Solved Problem. Different regex solutions led to different unwanted side effects, and other utilities were far, far more complex and feature rich than I needed.

constant C++ string


The project is a modern and effective implementation of an immutable string class for C++. The string uses optimizations not quite applicable for mutable string classes, provides cheap creation and copy, expression templates for concatenation.

leveldb - LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values


LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.LevelDB library documentation is online and bundled with the source code.

busboy - A streaming parser for HTML form data for node.js


A node.js module for parsing incoming HTML form data.file(< string >fieldname, < ReadableStream >stream, < string >filename, < string >transferEncoding, < string >mimeType) - Emitted for each new file form field found. transferEncoding contains the 'Content-Transfer-Encoding' value for the file stream. mimeType contains the 'Content-Type' value for the file stream.

pystring - C++ functions matching the interface and behavior of python string methods with std::string


C++ functions matching the interface and behavior of python string methods with std::string

solidity-stringutils - Basic string utilities for Solidity


Functionality in this library is largely implemented using an abstraction called a 'slice'. A slice represents a part of a string - anything from the entire string to a single character, or even no characters at all (a 0-length slice). Since a slice only has to specify an offset and a length, copying and manipulating slices is a lot less expensive than copying and manipulating the strings they reference. To further reduce gas costs, most functions on slice that need to return a slice modify the original one instead of allocating a new one; for instance, s.split(".") will return the text up to the first '.', modifying s to only contain the remainder of the string after the '.'. In situations where you do not want to modify the original slice, you can make a copy first with .copy(), for example: s.copy().split("."). Try and avoid using this idiom in loops; since Solidity has no memory management, it will result in allocating many short-lived slices that are later discarded.