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

text-split

v0.0.1

Published

Text wrapping for type animations.

Downloads

5

Readme

text-split

text-split on Travis text-split on NPM text-split Downloads on NPM Standard JavaScript Style

Text wrapping for type animations.

Install

$ npm install text-split --save

Why?

To address some prior art:

  • Lettering.js - dependent on jQuery
  • charming
    • less straightforward (child nodes are recursed through for text content)
    • less flexible (mandatory class and aria attributes are added, no per piece callback)

With only 1 method and 4 options, text-split offers the most control via the smallest API surface area.

Getting Started

import splitter from 'text-split'

// a target node is required
const target = document.querySelector('.heading')

// pass in the target node
// get back the newly created nodes wrapping the target text (in an array)
const created = splitter(target)

Read more about options below to handle more complex use cases.

Options

All options have defaults, as shown here:

const defaults = {
  a11y = true,
  delimeter = 'letter',
  each = null,
  element = 'span'
}

Each option is explained in further detail below:

a11y

Enable (default) or disable setting of aria attributes on parent and created child nodes.

splitter(target, { a11y: false })

delimeter

Either letter (default) or word, indicating how to break up the target text before wrapping it.

splitter(target, { delimeter: 'word' })

each

A function that, if it exists, is called and passed:

  • the created node, with appropriate textContent
  • the 0-based node index (relative to the other created nodes)
  • the DocumentFragment that stores the nodes created (thus far)

This is the ~~fun part~~ escape hatch.

splitter(target, {
  each: (node, index, frag) => {
    // add a class based on the index
    node.classList.add(`number-${index}`)

    // add a transition delay based on the index
    node.style.transitionDelay = `${index * .05}s`
  }
})

element

A tag name that is used to create the wrapper element for each piece of the text after it is split using the delimeter.

const divs = splitter(target, { element: 'div' })

License

MIT. © 2018 Michael Cavalea