magic-string - Manipulate strings like a wizard

  •        6

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

Dependencies:

vlq : ^0.2.2

Tags
Implementation
License
Platform

   




Related Projects

Twine - String manipulation, leveled up!

  •    PHP

Twine is a simple string manipulation library with an expressive, fluent syntax. Like this project? Keep me caffeinated by making a donation.

strman-java - A Java 8 string manipulation library.

  •    Java

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.

strman - 🏗A Javascript string manipulation library.

  •    Javascript

A Javascript string manipulation library. Want to contribute? Follow these recommendations.

underscore.string - String manipulation helpers for javascript

  •    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.

  •    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/.


stringr - A fresh approach to string manipulation in R

  •    R

Strings are not glamorous, high-profile components of R, but they do play a big role in many data cleaning and preparation tasks. The stringr package provide a cohesive set of functions designed to make working with strings as easy as possible. If you’re not familiar with strings, the best place to start is the chapter on strings in R for Data Science. stringr is built on top of stringi, which uses the ICU C library to provide fast, correct implementations of common string manipulations. stringr focusses on the most important and commonly used string manipulation functions whereas stringi provides a comprehensive set covering almost anything you can imagine. If you find that stringr is missing a function that you need, try looking in stringi. Both packages share similar conventions, so once you’ve mastered stringr, you should find stringi similarly easy to use.

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

  •    Python

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

left-pad - :arrow_left: String left pad

  •    Javascript

NOTE: The third argument should be a single char. However the module doesn't throw an error if you supply more than one chars. See #28. NOTE: Characters having code points outside of BMP plan are considered a two distinct characters. See #58.

SimpleText - A simple spannable string helper

  •    Java

This libary aims to simplify the creation of spannable string.

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

  •    Javascript

String manipulation extensions for Underscore.js javascript library.

Stringy - A PHP string manipulation library with multibyte support

  •    PHP

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.

  •    Emacs

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

  •    C++

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.

Marshal - Marshaling the typeless wild west of [String: Any]

  •    Swift

In Swift, we all deal with JSON, plists, and various forms of [String: Any]. Marshal believes you don't need a Ph.D. in monads or magic mirrors to deal with these in an expressive and type safe way. Marshal will help you write declarative, performant, error handled code using the power of Protocol Oriented Programming™. Unmarshaling is the process of taking an intermediary data format (the marshaled object) and tranforming it into a local representation. Think of marshaling as serialization and unmarshaling as deserialization, or coding and decoding, respectively.

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.

  •    Javascript

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

  •    Javascript

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.

android-RuntimePermissions

  •    Java

This sample shows runtime permissions available in Android M and above. It shows how to check and request permissions at runtime, handle backwards compatibility using the support library and how to declare optional permissions for M-devices only. Android M introduced runtime permissions. Applications targeting M and above need to request their permissions at runtime. All permissions still need to be declared in the AndroidManifest. However, when accessing APIs that require a permission, the Activity or Fragment has to verify that the permission has been granted or request the missing permissions using calls through the support library. Permissions are checked through ActivityCompat#checkSelfPermission(Context, String) or ContextCompat#checkSelfPermission(Context, String). Permission are requested through ActivityCompat#requestPermissions(Activity, String[], int), and the response received in a callback to ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[]). Applications can provide an additional rational for the use of permissions after calling ActivityCompat#shouldShowRequestPermissionRationale(Activity,String). This call will return true if the application should provide the user with more context on why the requested permissions is needed, for example if the permission request has been denied before.

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

  •    Javascript

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.