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

hashii

v1.3.0

Published

Easily parse hashtags from entire forms or a single field without any of the headache.

Downloads

7

Readme

 _    _           _____ _    _ _____ _____ 
| |  | |   /\    / ____| |  | |_   _|_   _|
| |__| |  /  \  | (___ | |__| | | |   | |  
|  __  | / /\ \  \___ \|  __  | | |   | |  
| |  | |/ ____ \ ____) | |  | |_| |_ _| |_ 
|_|  |_/_/    \_\_____/|_|  |_|_____|_____|

~ Hashii ~

Easily parse and format hashtags. No dependencies, no headaches.

Installation

npm install hashii

Using Hashii

Getting Hashii up and running is simple, the only requirement is that you pass the constructor an object containing the name of your custom Hashii attribute, using the 'ref' object property (element reference).


var Hashii = require('hashii');

var languages = new Hashii({ref: 'languages'});

Now just set your custom Hashii key onto the HTML element (form, textarea, input) that you would like to scrape for hashtags and you're good to go!


<!--
  Hashi attribute syntax
  hashii:[key name]
  ex: hashii:posts, hashii:comments, hashii:blog...
-->

<form hashii:languages>
    <input type="text" />
    <input type="text" />
    <textarea></textarea>
</form>

Getting Your Hashtags

Once you are ready to consume the collected hashtags, just call the $tags() method on your Hashii variable and your tags will be returned to you in your desired format.

// <form hashii:languages>/ ... /</form>

var languages = new Hashii({ref: 'languages'});

languages.$tags();

/* Default return format */
["PHP", "Ruby", "Python"]

By default, Hashii will return a single array of the parsed hashtags without the '#' symbol. Below are the configuarable defaults for your Hashii instance.

Defaults

var defaults = {
    ref: '', // *required
    format: '[]',
    includeHash: false
};

Alternative Configuration Options

If you would like to receive JSON ('{}') rather than an array ('[]'), all you need to do is pass a few options to the Hashii constructor to override the above defaults.

/* Expect a JSON object with the '#' symbol included this time */
var languages = new Hashii({
    ref: 'languages',
    format: '{}',
    includeHash: true
});

/* result */
{"0":"#PHP","1":"#Ruby","2":"#Python"}

Hooking Onto Elements

There are two ways that you can use Hashii. The first way is to hook the hashii:[key name] attribute onto your entire form within the tag like the example below. This method will gather hashtags from every input and/or textarea within that form.

<!-- Scrapes every input/textarea within this form -->
<form hashii:languages>
    <input type="text" />
    <input type="text" />
    <textarea></textarea>
</form>

The second way Hashii can be used is to place the hashii:[key name] onto a single field whether inside a form or just an input field on it's own like so:

<!-- Will only parse this field for hashtags -->
<input name="languages" type="text" hashii:languages />

Reference Methods

Hashii offers a few methods to call on that can return configuration information about your Hashii instance for your reference or any other use.

/* Examples */

// Cache the element synced with your instance
var elem = lang.$element();

// Inspect your instances configuration, etc...
console.log(lang.$settings());
  • .$element() // returns DOM element hashii:[key name] is on
  • .$defaults() // returns Hashii default object for reference
  • .$settings() // returns your instance configuration

Versioning

This repo uses SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.txt file for details