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

esc-fmt-same-string-edges

v0.3.0

Published

Format 2 strings, human readable, easy compare, highlight beginning/middle/end (if applicable) same/different parts, algorithm/function, visualize/highlight, match unchanged context. Fast and minimal, zero dependencies, supply your own formatting function

Downloads

267

Readme

esc-fmt-same-string-edges

Format 2 strings, human readable, easy compare, highlight beginning/middle/end (if applicable) same/different parts, algorithm/function, visualize/highlight, match unchanged context. Fast and minimal, zero dependencies, supply your own formatting functions, cli, terminal, html, React, xml.

Installation

  1. npm install --save esc-fmt-same-string-edges

Example usage

import format from 'esc-fmt-same-string-edges';
import colors from 'colors';

const old = 'Hello World';
const new = 'H3110 W0r1d';
const [ fmtdOld, fmtdNew ] = format(old, new, colors.green, colors.red);
console.log('fmtdOld', fmtdOld);
console.log('fmtdNew', fmtdNew);

Demo CLI

import format from 'esc-fmt-same-string-edges';
import colors from 'colors';

const demo2 = (a, b) => console.log(`${format(a, b, colors.green, colors.red                ).join('\n')}\n`);
const demo3 = (a, b) => console.log(`${format(a, b, colors.green, colors.red, colors.magenta).join('\n')}\n`);

demo2('/foo/bar/baz/qux.txt', '/foo/bar/daz/qux.txt');
demo3('/foo/bar/baz/qux.txt', '/foo/bar/daz/qux.txt');
demo3('/foo/bar/baz/baz/qux.txt', '/foo/bar/baz/qux.txt');
demo3('/foo/bar/baz/qux.txt', '/foo/bar/baz/baz/qux.txt');
demo3('/foo/bar/baz/qux.txt', '/xyz/bar/baz/qux.txt');
demo3('/foo/bar.txt', '#foo/bar.txt');
demo3('/foo/bar/baz/qux.txt', '/zoo/bar/baz/qux.txt');
demo3('/foo/bar/baz/qux.txt', '/zoo/bar/baz/qux.xml');
demo2('Hello World', 'H3110 W0r1d');
demo3('Hello World', 'H3110 W0r1d');

image

Demo HTML

import format from 'esc-fmt-same-string-edges';

// html example - make your own HTML, XML, React, etc
const fmtHtmlSameF = s => `<span class='same'>${s}</span>`;
const fmtHtmlDiffF = s => `<span class='diff'>${s}</span>`;
const demoH = (a, b) => console.log(`${format(a, b, fmtHtmlSameF, fmtHtmlDiffF).join('\n')}\n`);

console.log('/foo/bar/baz.txt\n/foo/xyz/baz.zip\nFormat as HTML');

demoH('/foo/bar/baz.txt', '/foo/xyz/baz.zip');

image

Format HTML - CLI example (you could also format HTML with HTML or whatever)

// format the HTML
import colors from 'colors';

console.log('HTML difference hard to see?');
const [ fmtdOldHtml, fmtdNewHtml ] = format('/foo/bar/baz.txt', '/foo/xyz/baz.zip', fmtHtmlSameF, fmtHtmlDiffF);
const demo2 = (a, b) => console.log(`${format(a, b, colors.green, colors.red).join('\n')}\n`);
demo2(fmtdOldHtml, fmtdNewHtml);

image

What it does

If your strings are the same length then every character can be formatted according to your same/different formatting function. (with as little formatting as possible)

If your strings are different lengths then the parts of the start and end (respectively) that are the same will be formatted as such and the middle that is different will be formatted as such. (the different part can also be at the beginning or end of the strings)

Say thanks

Star the repo https://github.com/softwarecreations/esc-fmt-same-string-edges

PR's or issues

Welcome

License

MIT