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

insecable

v1.0.2

Published

Aims at adding non-breaking spaces where relevant in an HTML string

Downloads

150

Readme

Insecable

Build Status

Insecable is a module that aims at adding non-breaking spaces where relevant in an HTML string.

Its name comes from the french name "Espace insécable" that means non-breaking space.

Installation

To add insecable to your project run

npm install --save insecable

Usage

Ruleset

The patching operation is driven by one or more set of rules. There are so far 3 types of possible replacements:

  • leading that aims at replacing a leading space (e.g <space>!, <space>» )
  • trailing that aims at replacing a trailing space (e.g ,<space> «<space>)
  • nested that aims at replacing the space after the opening symbol and the space before the closing symbol (e.g –<space>some text<space>–)

Example ruleset: French punctuation marks

const {insecable} = require('insecable');

// French punctuation marks ruleset Cherry picked from
// https://github.com/morgaan/insecable/blob/master/src/rulesets/fr-FR.js.
const ruleset = {
	'&#8239;': {
		leading: [
			'!', ';', '?'
		]
	},
	'&#160;': {
		leading: [
			'»', ':'
		],
		trailing: [
			'«'
		],
		nested: [
			'–'
		]
	}
};

const input = `
		Ça alors !
		Je ne l'avais jamais vu ; ces espaces me semblent bizarres.
		Exemple : le deux-points qui se dit parfois double point.
		« Bonjour ! »
		Il ne faut pas confondre le tiret d'incise et le trait d'union – qui est nettement plus court – même si l'erreur est fréquente.
	`;

const patchedInput = insecable(input, ruleset);

// patchedInput should now be equal to:
//
// Ça alors&#8239;!
// Je ne l'avais jamais vu&#8239;; ces espaces me semblent bizarres.
// Exemple&#160;: le deux-points qui se dit parfois double point.
// «&#160;Bonjour&#8239;!&#160;»
// Il ne faut pas confondre le tiret d'incise et le trait d'union –&#160;qui est nettement plus court&#160;– même si l'erreur est fréquente.

Contributing to insecable

Contributions are always welcome. Before contributing please search the issue tracker; your issue may have already been discussed or fixed in master. To contribute, clone , commit your changes, & send a pull request.

Contribute rulesets

This module is architectured in a way that rulesets can be extended and/or contributed.

Please make sure to always:

  • Check the ./src/rulesets/fr-FR.js, ./src/rulesets/fr-FR.test.js and ./src/rulesets/index.js to get a grip on how this all work together.
  • Give your source as comment in the ruleset's file.
  • Provide test file with 100 percent code coverage.

So far this repository only contains rules for the French language, and more precisely for the french punctuation marks. There is much more that can be added, at least for the french language according to the book: Lexique des règles typographiques en usage à l'Imprimerie nationale, 5th edition, Paris, 2002. ISBN 2-7433-0482-0., for instance for dates, measure/military units... This may come in future releases, but feel free to contribute this may then be quicker ;).

Coding Guidelines

In addition to the following guidelines, please follow the conventions already established in the code.

  • Spacing: Use one tab for indentation. No spaces.

  • Naming: Keep variable & method names concise & descriptive. Variable names index, array, & error are preferable to i, arr, & e.

  • Quotes: Single-quoted strings are preferred to double-quoted strings; however, please use a double-quoted string if the value contains a single-quote character to avoid unnecessary escaping.

  • Comments: Please use concise comments to annotate significant additions, & JSDoc-style comments for functions.