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

optics

v0.1.0

Published

🕶 diffing strings with expert vision

Downloads

43

Readme

optics

🕶 diffing strings with expert vision

Npm Version Build Status Coverage Status Dependency Status devDependency Status npm npm

TOC

Installation

npm install optics --save

Usage

const Optics = require('optics');

const source = `
  hello world

  how are you?

  what is up?
`

const patch = `
  hello world

  you are who?

  what is up?
`

const _diff = new Optics(source, patch)

Given an Optics instance you can now do the following to view it.

  • splitDiff
  • combinedDiff
  • diff

diff

diff takes the following arguments passed an object { isCondensed = false, padding = 4 }

arguments
  • isCondensed (boolean): this controls if the diff output is trimmed of unnecessary text that hasn't chnaged or not.
  • padding (integer): this is used if isCondensed is set to true to control how much of that unnecessary is preserved in the output.
returns
  • combined (string): a combined view of both removed and added values to the string
  • removed (string): only outputs the removed values and the original values of the diff
  • added (string): only outputs the added values and the original values of the diff
  • totalLines (integer): the total number of lines (the max value between patch and source in order to get an even output)
  • maxLineLength (integer): the longest string value
Usage
const _diff = new Optics(source, patch);

_diff.diff({ isCondensed: true, padding: 7 })

splitDiff

takes the same arguments that diff does.

Usage
const _diff = new Optics(source, patch);

_diff.splitDiff({ isCondensed: true, padding: 7 });

outputs (ansii colors will output if your output supports it)

[0]                         | [0]                            
[1]            hello world  | [1]            hello world     
[2]                         | [2]                            
[3] -          how are you? | [3] +          you are who?
[4]                         | [4]                            
[5]            what is up?  | [5]            what is up?     
[6]                         | [6]                            

combinedDiff

takes the same arguments that diff does.

Usage
const _diff = new Optics(source, patch);

_diff.combinedDiff({ isCondensed: true, padding: 7 });

outputs (ansii colors will output if your output supports it)

[0]    
[1]            hello world
[2]    
[3] -          how are you?
[3] +          you are who?
[4]    
[5]            what is up?
[6]