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

node-jsdifflib

v1.1.4

Published

A diff library to compare text differences between two texts.

Downloads

193

Readme

node-jsdifflib

A diff library to compare text differences between two texts.

This is a fork of cemerick/jsdifflib which has been adapted to render the HTML on the server.

Installation

npm install node-jsdifflib

Overview

jsdifflib is a Javascript library that provides:

  1. A partial reimplementation of Python’s difflib module (specifically, the SequenceMatcher class)
  2. A visual diff view generator, that offers side-by-side as well as inline formatting of file data

API

diff(baseText, newText[, options])

options

  • baseTextName: [string] the title to be displayed above the base text listing in the diff view [default="Base Text"]
  • newTextName: [string] the title to be displayed above the new text listing in the diff view [default="New Text"]
  • contextSize: [int] the number of lines of context to show around differences; by default, all lines are shown
  • inline: [boolean] if false, a side-by-side diff view is generated (default); if true, an inline diff view is generated
  • colgroup: [object/boolean] whether to add colgroup tag to table [default = false]
    • th: [int] The width (%) of th elements (lines) [default=5]
    • td: [int] The width (%) of td elements (content) [default=45]

Style

jsdifflib comes with a ready to use CSS file (assets/jsdifflib.css) or you can use a custom one.

Example

const http = require("http");
const diff = require('node-jsdifflib');

const baseFile = "console.log(5);"
const newFile = "\"use strict\";\nconsole.log(5);";

http.createServer(function(req, res){ 
  
    if (req.url === '/favicon.ico') {
      res.writeHead(200, {'Content-Type': 'image/x-icon'} );
      return res.end();
    }

    var output = diff(baseFile, newFile);

    res.writeHead(200, {'Content-Type': 'text/html'});

    res.end(`<html>
      <head>
        <link rel="stylesheet" href="https://cdn.rawgit.com/marcosc90/node-jsdifflib/8838a6401c6933ca3faa1085bc1ec9b8174a6db8/assets/jsdifflib.css" />
      </head>
      <body>
        ${output}
      </body>
    </html>`);

}).listen(8081, function(){
  console.log("Server started at: http://localhost:8081");
});

License

BSD