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

@nightingale-elements/nightingale-textarea-sequence

v5.3.2

Published

[![Published on NPM](https://img.shields.io/npm/v/@nightingale-elements/nightingale-textarea-sequence.svg)](https://www.npmjs.com/package/@nightingale-elements/nightingale-textarea-sequence)

Downloads

30

Readme

nightingale-textarea-sequence

Published on NPM

A custom element that creates a formatted text box to capture sequences. It uses QuillJS to format the content of the text box.

Usage

<nightingale-textarea-sequence
  id="track"
  min-sequence-length="5"
  width="800"
  height="400"
></nightingale-textarea-sequence>

API reference

Attributes

alphabet?: 'protein'|'dna'|string (default: 'protein')

Either a string explicitly listing the valid characters in the sequence or one of the predefined alphabets:

  • "protein": "ACDEFGHIKLMNPQRSTVWY "
  • "dna": "AGTCN "

case-sensitive?: boolean (default: false)

Indicates if the checks against the alphabet should consider the sequence casing

single?: boolean (default: false)

Indicates if the textarea should only allow a single sequence

disable-header-check?: boolean (default: false)

Indicates if the checks against the alphabet should consider the absence of the header. This will only make sense if the attribute single is also true, if it's not, the value of the error headerCheckRequiredForMultipleSequences will be true.

min-sequence-length?: number (default: 1)

Defines the minimum number of amino or nucleic acids required in the textarea

inner-style?: string (default: '')

Inline CSS style for the main container. Please note that the container's height and width should not be set using inner-style but with the height and width attributes (see Usage)

sequence: string [Read Only]

The current value of the textarea.

errors [Read Only]

The current value of the error report. In the shape of an object, where the keys are the type of error, and their values are booleans indicating if the current text has that error.

Usage example:

{
  hasInvalidCharacters: false,
  missingFirstHeader: false,
  multipleSequences: false,
  tooShort: true, // The current sequence is too short
  headerCheckRequiredForMultipleSequences: false,
}

quill

We use quill to apply the formatting of the textarea. The object related to it, is exposed in this parameter. See the Quill API documentation for more details of what can you do with this object.

formatSequence

A formatting function to use in the cleanUp() method. It should add desired spaces a line splits.

The signature of the function should be:

type FormatSequenceFunction = (
  sequence: string,
  options?: Record<string, unknown>,
) => string;

By default, improves the readability by folding sequences to have a maximum of 50 characters per line, and add a space every 10 characters.

Note: This parameter can be overwritten, so you can define such format. For example, to avoid any formatting you can pass the identity function:

document.getElementByID("textareaID").formatSequence = (x) => {
  return x;
};

Methods

cleanUp()

This method tries to clean up the current sequence in the textarea, in the following way:

  • Adds a generated header to the sequence in case is missing
  • Removes any character that is not included in the current alphabet
  • Trims lines and get rid of spaces
  • If the attribute single is true, it will keep the first sequence and remove the rest.
  • Executes the formatSequence function to include spaces and line lengths.

Events

error-change

Is dispatched when there is a change in the reported errors. Includes the errors object in the details.

Usage example:

element.addEventListener("error-change", (e) => {
  console.log(e.detail.errors);
});

Quill Events

As mentioned before, we use quill, and its instance is exposed in the parameter quill. Quill emits several events, that you could also use. See the Quill API documentation for more details.

Usage example:

element.quill.on("text-change", (e) => {
  console.log(element.sequence);
});

Exposed functions

The following functions can be used without having to load the web component:

formatSequence(sequence, options={block: 10, line: 50})

Splits a string into lines of length line with blocks of block length separated by white spaces.

parameters:

  • sequence: type: string
  • options: type {block: number, line: number}

Returns:

  • string

Usage example:

import { formatSequence } from "textarea-sequence";
const seq = "XXXXXXXXXXXXXXX";
formatSequence(seq, 4, 8); // 'XXXX XXXX\nXXXX XXX'
formatSequence(seq, 2, 8); // 'XX XX XX XX\nXX XX XX X'
formatSequence(seq, 5, 10); // 'XXXXX XXXXX\nXXXXX'

cleanUpText(text,alphabet = alphabets.protein, caseSensitive = false, removeComments = true, single = true, format = formatSequence)

Takes a sequence and transform it, applying the following heuristics:

  • removes any character not in the alphabet
  • generates a header if the sequence does not already have one
  • formats the sequence using the specified function. Default: blocks of 10 characters separated with a white space and lines of 50 characters
  • if case_sensitive is true, case mismatches are removed
  • if removeComments is true, lines starting with ; are removed
  • if single is true, the first sequence is retained and the subsequent are removed

When all of those things are executed, the string is formatted with the function format().

Parameters:

  • text: type: string
  • alphabet: type: string default: "ACDEFGHIKLMNPQRSTVWY "
  • caseSensitive: type: boolean default: false
  • removeComments: type: boolean default: true
  • single: type: boolean default: true
  • format: type: function default: formatSequence