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

@hooked74/highlight

v1.0.3

Published

Wrap text nodes in span with highlight class

Downloads

8

Readme

Build Status npm License Module Size

Table of contents

Overview

This library is designed to highlight text. Using it, you can go through all text nodes (from the start node to the final node) and wrap them in a span with the desired class.

Install

npm install @hooked74/highlight

Usage

import Highlight from "@hooked74/highlight";

const hl = new Highlight();
// wrap the range from window.getSelection()
// return the identifier of this highlight
const id = hl.fromSelect();

// remove highlight
hl.remove(id);

API

hl.fromSelect([options])

  • options <{id: string, className: string}> id - Identifier of this highlight, which can be used instead of generated. className - class to be used for highlighting. id, className are optional, as options.
  • Returns: <string> Identifier of this highlight.

Wrap the range from window.getSelection().

hl.fromRange(range[, options])

  • range <window.Range> Range to be wrapped.
  • options <{id: string, className: string}> id - Identifier of this highlight, which can be used instead of generated. className - class to be used for highlighting. id, className are optional, as options.
  • Returns: <string> Identifier of this highlight.

Wrap the passed range.

hl.fromNodes(startNode, endNode[, startOffset, endOffset, options])

  • startNode <Node> Range start node.
  • endNode <Node> Range end node.
  • startOffset <number> Start node offset.
  • endOffset <number> End node offset.
  • options <{id: string, className: string}> id - Identifier of this highlight, which can be used instead of generated. className - class to be used for highlighting. id, className are optional, as options.
  • Returns: <string> Identifier of this highlight.

Wrap a range of start node and end node.

hl.remove(id)

  • id <string> Identifier of this highlight.
  • Returns: <void>

Remove highlight.

Development

You can run some built-in commands:

npm run storybook

This command allows you to run a storybook in development mode. By default, it will be launched on http://localhost:9002. The port can be configured in the .env file. Storybook is an open source tool for developing UI components in isolation for React, Vue, and Angular. It makes building stunning UIs organized and efficient.

npm run build

Builds the app for production. Your app is ready to be deployed.

npm run test:watch

Runs the test watcher in an interactive mode. By default, runs tests related to files changed since the last commit.

npm run test:browser:open

Runs tests using cypress. Defaults to port 9002. The port can be configured in the .env file.
To run the tests, you need a running server with the base url specified in .env in the variable CYPRESS_BASE_URL.

npm run test:browser

Runs tests using cypress. Defaults to port 9002. The port can be configured in the .env file. Also on the same port a storybook will be launched over which testing will be carried out.