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

jselection

v0.1.12

Published

extended '''Selection''' class allows selecting by content and index

Downloads

2

Readme

jSelection

Extended Selection series allows selecting by content and index

NPM version

Installation

   npm install jselection --save
   bower install jselection  --save

Usage

  • with <script>(in browser)
<script type="application/javascript" src="node_modules/jselection/dist/jSelection.browser.js"></script>
  • with import(in Typescript / ES6)
import {XWindow, XSelection} from "jSelection";
// XWindow.from(...);
import * as jSelection from "jSelection";
// jSelection.XWindow.from(...);
  • with require
const jSelection = require("jSelection");

API

XWindow: Extended Window class

XWindow.from

create instance from a html Element(a XWindow instance is created and returned)

public static from(root: Element = document.body): XWindow;
  • create XWindow from element with ID body
let xWindow = XWindow.from(document.querySelector('#body'));

XWindow.select

select by content and index (a XSelection instance is created and returned)

public select(opt_text?: string, opt_nth: number = 1, opt_select: boolean = false): XSelection;
  • select the 5th hello (create XSelection instance from the 5th hello)
let xSelection = xWindow.select("hello", 5);
  • select by Mouse (create XSelection instance from the Mouse selected text)
let xSelection = xWindow.select();

XSelection: Extended Selection class

XSelection.getTextNodes

get Text Nodes of the XSelection

public getTextNodes(): Array<XText>;
interface XText extends Text {...}

XSelection.getOccurrence

get the Occurrence of the selected text from XSelection instance

public getOccurrence(): Occurrence;

interface Occurrence {
    nth: number; //the content is the `nth` occurrence
    position: number; //the content starts at `position`
}

Example

<html lang="en">
<head>
    <script type="application/javascript" src="dist/jSelection.browser.js"></script>
    <script type="application/javascript" src="bower_components/jQuery/dist/jquery.min.js"></script>
    <style type="text/css">
        .markup {
            background-color: yellowgreen;
        }
    </style>
</head>
<body>
text start: 
<div id="body">
    this is a test
    <span>this is a test</span>
    this is a test
    <p> this is a test </p>
    this is a test
</div>
text end: 
<script type="application/javascript">
    var xWindow = jSelection.XWindow.from(document.querySelector("#body"));
    var xSelection = xWindow.select("test", 5);
    var nodes = xSelection.getTextNodes();
    console.log(nodes);
    var markup = $(nodes).wrapAll("<span class='markup'/>");
</script>
</body>
</html>