1. vue-sfc-descriptor-to-string
Convert SFCDescriptor to source
vue-sfc-descriptor-to-string
Package: vue-sfc-descriptor-to-string
Created by: psalaets
Last modified: Thu, 11 Apr 2024 19:08:08 GMT
Version: 3.0.1
License: MIT
Downloads: 165,124
Repository: https://github.com/psalaets/vue-sfc-descriptor-to-string

Install

npm install vue-sfc-descriptor-to-string
yarn add vue-sfc-descriptor-to-string

vue-sfc-descriptor-to-string

Convert SFCDescriptor to source

Install

npm install vue-sfc-descriptor-to-string

Usage

 // parse an sfc
const compiler = require('vue-template-compiler');
const sfcDescriptor = compiler.parseComponent(sfcSource);

// convert sfc descriptor back to source
const toString = require('vue-sfc-descriptor-to-string');
const result = toString(sfcDescriptor);

result == sfcSource // => true, but see caveats below

API

 const toString = require('vue-sfc-descriptor-to-string');

toString(SFCDescriptor, options)

SFCDescriptor

Object that looks like an SFCDescriptor

options

Optional object, defaults to {}

options.indents

Optional object that can have a property for each sfc block name (e.g. template). Values are the number of spaces to indent that block's content.

Defaults to

 {
  template: 0,
  script: 0,
  style: 0
}

Caveats

This module isn't a true inverse of compiler.parseComponent() because it doesn't always produce the exact same sfc compared to what was parsed. It assumes the parsed sfc

  • ends with a single newline
  • has a single space before each attribute on <script>, <template>, <style>
  • other stuff

License

MIT

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code