npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

muggle-string

v0.4.1

Published

This library aims to provide codegen helpers and data structure for Vue language plugin API v1.x that does not depend on Volar runtime.

Downloads

8,705,525

Readme

This library aims to provide codegen helpers and data structure for Vue language plugin API v1.x that does not depend on Volar runtime.

Why "Muggle"?

A better situation is Volar can use magic-string on the Vue plugin API, but currently can't do this easily.

This solution is just for Vue language plugin API v1.x and planned to be deprecate in v2.

Usage

The example is base-on magic-string readme.

<script>problems = 99</script>

<more-script lang="js">console.log( answer )</more-script>
import {
	toString,
	replace,
} from 'muggle-string';

/** @type {import('@volar/vue-language-core').VueLanguagePlugin} */
const plugin = () => {
	return {
		name: 'example-vue-language-plugin',
		version: 1,
		resolveEmbeddedFile(fileName, sfc, embeddedFile) {
			if (embeddedFile.fileName.replace(fileName, '').match(/^\.(js|ts|jsx|tsx)$/)) {

				const s = embeddedFile.content;
				toString(s); // 'problems = 99'

				replace(s, 'problems', 'answer');
				toString(s); // 'answer = 99'

				replace(s, '99', '42');
				toString(s); // 'answer = 42'

				// add string by Array method directly
				s.unshift('var ');
				s.push(';');
				toString(s); // 'var answer = 42;'

				for (const block of sfc.customBlocks) {
					if (block.type === 'more-script') {
						s.push([
							block.content, // text to add
							block.name, // source
							0, // content offset in source
							{
								// language capabilities to enable in this segment
								hover: true,
								references: true,
								definition: true,
								diagnostic: true,
								rename: true,
								completion: true,
								semanticTokens: true,
							},
						]);
						toString(s); // 'var answer = 42;console.log( answer )'
					}
				}
			}
		}
	};
};
module.exports = plugin;