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

content-tag

v2.0.1

Published

A rust program that uses a fork of swc to parse and transform Javascript containing the content-tag proposal

Downloads

334,893

Readme

content-tag

content-tag is a preprocessor for JS files that are using the content-tag proposal. This originated with Ember.js' GJS and GTS functionality. You can read more by checking out the original RFC

This preprocessor can be used to transform files using the content-tag spec to standard JS. It is built on top of swc using Rust and is deployed as a wasm package.

Installation

npm install content-tag

Usage

Node (CommonJS)

let { Preprocessor } = require('content-tag');
let p = new Preprocessor();
let output = p.process('<template>Hi</template>');

console.log(output);

Node (ESM)

import { Preprocessor } from 'content-tag';
let p = new Preprocessor();
let output = p.process('<template>Hi</template>');

console.log(output);

Browser (ESM)

import { Preprocessor } from 'content-tag';
let p = new Preprocessor();
let output = p.process('<template>Hi</template>');

console.log(output);

API

Preprocessor

All content-tag public API lives on the Preprocessor object.

Preprocessor.process(src: string, options?: PreprocessorOptions): string;

Parses a given source code string using the content-tag spec into standard JavaScript.

import { Preprocessor } from 'content-tag';
let p = new Preprocessor();
let output = p.process('<template>Hi</template>');

Preprocessor.parse(src: string, options?: PreprocessorOptions): Parsed[];

Parses a given source code string using the content-tag spec into an array of Parsed content tag objects.

import { Preprocessor } from 'content-tag';
let p = new Preprocessor();
let output = p.parse('<template>Hi</template>');

PreprocessorOptions

interface PreprocessorOptions {

  /** Default is `false` */
  inline_source_map?: boolean;

  filename?: string;

}

Parsed

NOTE: All ranges are in bytes, not characters.

interface Parsed {
  /**
   * The type for the content tag.
   *
   * 'expression' corresponds to a tag in an expression position, e.g.
   * ```
   * const HiComponent = <template>Hi</template>;
   * ```
   *
   * 'class-member' corresponds to a tag in a class-member position, e.g.
   * ```
   * export default class HiComponent extends Component {
   *   <template>Hi</template>
   * }
   * ```
   */
  type: "expression" | "class-member";

  /**
   * Currently, only template tags are parsed.
   */
  tagName: "template";

  /** Raw template contents. */
  contents: string;

  /**
   * Byte range of the contents, inclusive of inclusive of the
   * `<template></template>` tags.
   */
  range: {
    start: number;
    end: number;
  };

  /**
   * Byte range of the template contents, not inclusive of the
   * `<template></template>` tags.
   */
  contentRange: {
    start: number;
    end: number;
  };

  /** Byte range of the opening `<template>` tag. */
  startRange: {
    end: number;
    start: number;
  };

  /** Byte range of the closing `</template>` tag. */
  endRange: {
    start: number;
    end: number;
  };
}

Contributing

See the CONTRIBUTING.md file.