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

output-verbatim

v1.3.0

Published

A js library that allows you to output your messages verbatim, such as in chatting.

Downloads

50

Readme

output-verbatim

A js library that allows you to output your messages verbatim, such as in chatting.

Fuctions

  • Used to output messages in chat to achieve verbatim printout.

The effect is as follows:

output-verbatim

Usage

<template>
  <p v-html="content"></p>
</template>
<script setup>
import OutputVerbatim from 'output-verbatim';
import { ref, onUnmounted } from 'vue';

const content = ref('');
const output = new OutputVerbatim(
  '<b>H</b>ello, <b>W</b>orld!  <b>T</b>he <b>I</b>s <b>O</b>utput <b>V</b>erbatim.',
  {
    speed: 30, // Printing speed per word, 30 milliseconds a word, a cycle
    // Output one word per cycle, rich text will contain labels
    eachRound: function (currText) {
      console.log(currText);
      content.value = currText;
    },
    // Can be used to fix the problem of incorrect tags in Markdown syntax
    complete: function (finalText) {
      console.log(finalText);
      console.log('complete');
    },
  },
);

onUnmounted(() => {
  output.stop();
});
</script>

<style lang="scss">
p {
  letter-spacing: 4px;
  // text-align: center;
  font-size: 1.25rem;
  line-height: 1.5;

  b {
    font-size: 1.125em;
    font-weight: bold;
    background: linear-gradient(180deg, #c191ff 0%, #4584ff 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-left: 6px;

    &:first-child {
      margin-right: 0;
    }
  }
}
</style>

Frequent call scenarios:

<template>
  <p v-html="content"></p>
</template>
<script setup>
import OutputVerbatim from 'output-verbatim';
import { ref, onUnmounted } from 'vue';

const chartText = ref('');

// Encapsulation method for verbatim output
let output = null;
const verbatimOutput = (text, start) => {
  // chartText.value = '';
  let index = 0;
  // Stop previous output
  if (output) {
    output.stop();
  }
  output = new Verbatim(text, {
    speed: 30,
    start: start >= 0 ? start : 0,
    before: (preText) => {
      chartText.value = preText;
    },
    eachRound: (currText) => {
      console.log(currText);
      chartText.value = currText;
    },
    complete: (finalText) => {
      chartText.value = finalText;
    },
    markdown: true,
  })
};

// mock async call
let index = 0;
let content = '';
const timer = setInterval(() => {
  const start = content.length;
  content = content + Array(5).fill(index).join('');
  verbatimOutput(content, start);
  index++;
  if (index > 10) {
    clearInterval(timer);
  }
}, 100);

onUnmounted(() => {
  output.stop();
});

Options

| property | description | type | default | | ------------ | ----------------------------------------------------------------------------------- | -------- | --------- | | speed | Printing speed per word. One word, one cycle. | Number | 30 | | start | Start print begin at the index of the string, default is 0 | Number | 0 | | rich | Whether it is rich text, if so HTML tags are output directly. | Boolean | true | | markdown | Whether the characters are converted to HTML according to markdown syntax. | Boolean | false | | endLineBreak | Whether to add a line break at the end of the string. | Boolean | false | | eachRound | Output one word per cycle, rich text will contain labels | Function | undefined | | before | Callback function before printing starts, can be used for initialization operations | Function | undefined | | complete | Callback function at the end of the print that can be used for cleanup operations | Function | undefined |

Note: Input text can currently support rich text, but only one level, not nested. Such as <b>bold<i>italic</i></b> ,output will be <b>bold<i>italic</b> but not <b>bold<i>italic</i></b> Therefore, the italic effect only takes effect at the end when it is fully printed.

License

MIT