Socket
Socket
Sign inDemoInstall

muggle-string

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    muggle-string

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


Version published
Maintainers
1
Install size
4.32 kB
Created

Readme

Source

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,
  overwrite, // not yet support
} from 'muggle-string';

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

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

        overwrite(s, 0, 8, 'answer'); // not yet support
        toString(s); // 'answer = 99'

        overwrite(s, 11, 13, '42'); // not yet support
        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
              {
                 // langauge 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;

FAQs

Last updated on 29 Sep 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc