Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@designbycosmic/cosmic-unwidower

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@designbycosmic/cosmic-unwidower

Utilities for removing widows from text

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

cosmic-unWidower

Utilities for removing widows.

Import unWidower or unWidower.unWidowerClient from this package to remove widows client side, or pass html through unWidowerTextOnly to remove directly.


unWidowerClient

Use this to process client-side. Inexpensive and small, but still costs something.

Params

  • minWords Number the minimum number of words before apply the algo, default

Params for three word widow removal, all words must be at most this long

  • maxLastWordLength
  • maxPenultWordLength
  • maxAntepenultWordLength

Params for two word widow removal, if words are too long for three word widow removal, all words must be at most this long

  • maxLastWordLengthTwo
  • maxPenultWordLengthTwo

Examples

Basic Example

Using the default export.

import unWidower from "cosmic-unwidower";

unWidower();
React example

This will when the component is rendered with some parameters set.

import React, {useEffect} from "react";
import { unWidowerClient } from "cosmic-unwidower";

export default () => {

  useEffect(() => {
    unWidowerClient(5, 6, 5, 4, 11, 9);
  }, []);

  ...

}

unWidowerHtmlString

Use this to process in a function independent of client, useful for SSR.

Params

  • html a string of html code
  • minWords the minimum number of words before apply the algo

Params for three word widow removal, all words must be at most this long

  • maxLastWordLength
  • maxPenultWordLength
  • maxAntepenultWordLength

Params for two word widow removal, if words are too long for three word widow removal, all words must be at most this long

  • maxLastWordLengthTwo
  • maxPenultWordLengthTwo

Example

React Example

This creates a component that returns a div containing unWidowed html, independent of client, useful for SSR.

import React from "react";
import { unWidowerHtmlString } from "cosmic-unwidower";

export default (html) => {

  const content = unWidowerHtmlString(html, 5, 6, 5, 4, 11, 9);

  return <div dangerouslySetInnerHTML={{__html: content}} />;

}

unWidowerText

Use this to process a single string of text in a function independent of client, useful for SSR.

Params

  • text a text string
  • minWords the minimum number of words before apply the algo

Params for three word widow removal, all words must be at most this long

  • maxLastWordLength
  • maxPenultWordLength
  • maxAntepenultWordLength

Params for two word widow removal, if words are too long for three word widow removal, all words must be at most this long

  • maxLastWordLengthTwo
  • maxPenultWordLengthTwo

Example

React Example

This creates a component that returns a div containing an unWidowed text string.

import React from "react";
import { unWidowerClientText } from "cosmic-unwidower";

export default (text) => {

  const content = unWidowerText(text, 5, 6, 5, 4, 11, 9);

  return <p>{content}</p>;

}

FAQs

Package last updated on 04 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc