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

subsnip2vsc

v1.0.2

Published

Convert sublime xml snippet files to a VS Code json snippet file

Downloads

17

Readme

Sublime snippets to VS Code CLI

Easily convert sublime xml snippet files to VS Code json snippets.

Quick start

Install locally or globally via a package manager of your choice.

Follow instructions from CLI help page. See example usage below.

subsnip2vsc -h

Conversion example

This tool can convert Sublime xml based snippet files to a VS Code snippets.json file. The tool aims to do 90% of the job with fine-tuning left to you.

dollarsign.sublime-snippet

<snippet>
	<content>
		<![CDATA[\${$0}]]>
	</content>
	<tabTrigger>g</tabTrigger>
	<scope>text.html.gsp</scope>
	<description>${}</description>
</snippet>

gactionsubmit.sublime-snippet

<snippet>
	<content><![CDATA[
<g:actionSubmit value="${1:text}" action="${2:action}" ${3:onclick="${4:jsCode}"} />]]></content>
	<tabTrigger>gactionsubmit</tabTrigger>
	<scope>text.html.gsp</scope>
	<description>Generates a submit button that maps to a specific action</description>
</snippet>

Converted to a single VS Code snippets.json file

{
  "dollarsign": {
    "body": "\\${$0}",
    "description": "${}",
    "prefix": "g"
  },
  "gactionsubmit": {
    "body": "\r\n<g:actionSubmit value=\"${1:text}\" action=\"${2:action}\" ${3:onclick=\"${4:jsCode}\"} >",
    "description": "Generates a submit button that maps to a specific action",
    "prefix": "gactionsubmit"
  }
}

Further, if the body has multiple new lines separated with \r\n it will be split into an array of lines as follows:

{
  "body": [
    "<g:collect in=\"${1:attribute}\" expr=\"${2:expression}\">",
    "\t{3}",
    "<g:collect>"
  ]
}

You can then fine-tune the snippet file further to suit your preferences.

CLI Usage examples

Convert all *.tmSnippet files in snippets folder and print output to screen

subsnip2vsc convert snippets/*.tmSnippet -p

Convert all *.tmSnippet files in current folder to default snippets.json file

subsnip2vsc convert *.sublime-snippet

Convert all .sublime-snippet files in folder and sub-folders of snippets. Send output to my-snippets.json file

subsnip2vsc convert snippets/**/*.sublime-snippet -o my-snippets.json

API usage

Using the API directly, lets you customize various aspects of the internal functionality.

const { convert } = require("subsnip2vsc");
// using the APIlets you pass a single or multiple glob patterns
const patterns = ["**/*.*.sublime-snippet, ../*.tmSnippet"];

// split snippet body text into array of lines
const splitBody = (content) => {
  // custom split body logic
};

// extracts string from element (see xml-js npm package)
const textOf = (elem) => {
  // custom text extraction of element
};

// returns json string for converted entry
export const convertEntry = (entry, options) => {
  // custom convert entry logic
};

const printSnippetEntry = (snippetJson, options) => {
  // custom print file logic
};

const writeResultFile = (jsonStr, options) => {
  // custom write file logic
};

const options = {
  print: true,
  textOf,
  splitBody,
  convertEntry,
  printSnippetEntry,
  writeResultFile,
};
convert(patterns, options);

Dev CLI example

The following example demonstrates how you can call the binary directly in development mode while setting the work directory to a location of your choice (used as relative location for searching, reading and writing files)

npx cross-env .\bin\subsnip2vsc convert sublime-snippets/**/*.sublime-snippet -d C:/Users/xxxx/source/repos/vsc-extensions