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

dialog-differ

v2.0.0

Published

Dialog differ

Downloads

38

Readme

Dialog differ

WORK IN PROGRESS

An application for diffing two dialogs against each other.

Uses Google Chrome's Puppeteer to take screenshots and ImageDiff to compare screenshots.

A collaboration with Starak.

Required

  • Node 6+

Use

npm install dialog-differ

const DialogDiffer = require( 'dialog-differ' );

const suite = { // see 'Suite' structure
    options: {
        sizes: [
            { width: 460, height: 350 },
            { width: 320, height: 150 }
        ],
        originalVersion: '1.0.1',
        currentVersion: '1.0.2'        
    },
    original: [
        {
            id: 'first',
            version: '1.0.1',
            url: 'http://example.com/1.0.1/dialog-first.html'
        },
        {
            id: 'second',
            version: '1.0.1',
            url: 'http://example.com/1.0.1/dialog-second.html'
        }
    ],
    current: [
        {
            id: 'first',
            version: '1.0.2',
            url: 'http://example.com/1.0.2/dialog-first.html'
        },
        {
            id: 'second',
            version: '1.0.2',
            url: 'http://example.com/1.0.2/dialog-second.html'
        }
    ]
};

// create dialog differ
const dialogDiffer = new DialogDiffer();

// init dialog differ
await dialogDiffer.initDialogDiffer( { databaseArgs: `${__dirname}/database.json` } ); // store database in database.json

// diff suite
const suiteResult = await dialogDiffer.diff( suite ); // see 'SuiteResult' structure

Methods

constructor

| Property | Type | Description | | --- | --- | --- | | [databaseLayer] | AbstractDatabaseLayer | Database layer. Default LowDbDatabaseLayer. | | [logLevel] | String | Log level. Default error. |

const dialogDiffer = new DialogDiffer( {
    databaseLayer = null,
    logLevel = null,
} )

initDialogDiffer

Returns Promise<void>

Method to initialize dialog differ. Used to send arguments to database layer.

| Property | Type | Description | | --- | --- | --- | | [databaseArgs] | any | Database arguments. See AbstractDatabaseLayer~initDB. |

// store database in database.json when using LowDbDatabaseLayer
await dialogDiffer.initDialogDiffer( { databaseArgs: `${__dirname}/database.json` } );

diff

Returns Promise<DialogDiffer.SuiteResult>

Diffs original dialogs with current dialogs.

| Property | Type | Description | | --- | --- | --- | | suite | DialogDiffer.Suite | Suite. See AbstractDatabaseLayer~initDB. |

const suiteResult = await dialogDiffer.diff( suite );

getSuiteResult

Returns Promise<DialogDiffer.SuiteResult>

Get running or finished DialogDiffer.SuiteResult from database.

| Property | Type | Description | | --- | --- | --- | | suiteId | String | Suite id |

const suiteResult = await dialogDiffer.getSuiteResult( suiteId );

getLastSuiteResults

Returns Promise<Array<DialogDiffer.SuiteResult>>

Get list of latest running or finished DialogDiffer.SuiteResult from database.

const suiteResults = await dialogDiffer.getLastSuiteResults();

deleteDialogs

Returns Promise<Boolean>

Delete all DialogDiffer.DialogScreenshots for Dialogs matching dialogId from database.

| Property | Type | Description | | --- | --- | --- | | dialogId | String | Dialog id |

await dialogDiffer.deleteDialogs( dialogId );

deleteSuiteResult

Returns Promise<Boolean>

Delete DialogDiffer.SuiteResult for suiteId from database.

| Property | Type | Description | | --- | --- | --- | | suiteId | String | Suite id |

await dialogDiffer.deleteSuiteResult( suiteId );

Structure

Input

Suite

| Property | Type | Description | | --- | --- | --- | | options | DialogDiffer.Options | Suite options | | original | Array<DialogDiffer.Dialog> | Original dialogs | | current | Array<DialogDiffer.Dialog> | Current dialogs |

Suite Options

| Property | Type | Description | Example | | --- | --- | --- | --- | | sizes | Array<{ width: Number, height: Number }> | Sizes | [ { width: 460, height: 350 } ] | | originalVersion | String | Original version | 1.0.1 | | currentVersion | String | Current version | 1.0.2| | [isForceSnap] | Boolean | Force snap | false| | [isForceDiff] | Boolean | Force diff | false|

Suite Dialog

| Property | Type | Description | Example | | --- | --- | --- | --- | | version | String | Dialog version | 1.0.1 | | id | String | Dialog id | first | | url | String | Dialog URL | http://example.com/1.0.1/dialog-first.html | | [hash] | String | URL hash | #hash | | [waitForSelector] | String | Wait for selector | body.active | | [timeout] | Number | Timeout before taking snap (ms) | 250 | | [crop] | String | Selector to use for cropping screenshot | #container | | [resize] | Function(defaultWidth, defaultHeight): { width: Number, height: Number } | Function evaluated by Puppeteer which returns the new size to use for screenshot | function() { var container = document.querySelector('#container'); return { width: container.scrollWidth, height: container.scrollHeight }; } |

Result

Suite Result

| Property | Type | Description | Example | | --- | --- | --- | --- | | options | DialogDiffer.Options | Suite options | | results | Array<DialogDiffer.DialogsResult> | Dialog results | [ DialogDiffer.DialogsResult, ... ] |

Suite Dialogs Result

| Property | Type | Description | Example | | --- | --- | --- | --- | | dialogId | String | Dialog id | first | | original | DialogDiffer.DialogResult | Original dialog | { id: 'first', version: '1.0.1', url: ..., screenshots: [ ... ] } | | current | DialogDiffer.DialogResult | Current dialog | { id: 'first', version: '1.0.2', url: ..., screenshots: [ ... ] } | | originalVersion | String | Original version | 1.0.1 | | currentVersion | String | Current version | 1.0.2 | | result | DifferConstant | Diff result | changed | | differ | Array<DialogDiffer.DialogResultDiff> | Dialogs diffs | [ { index: 0, result: 'changed', base64: 'data:image/png;base64,...' } ] |

Suite Dialog Result

Extends Suite Dialog

| Property | Type | Description | Example | | --- | --- | --- | --- | | screenshots | Array<base64: String, width: String, height: String> | Dialog screenshots | [ { base64: 'data:image/png;base64,...', width: 460, height: 350 } ] | | [error] | { code: String, message: String } | Error when creating screenshot | { code: 'snap-dialog-from-browser-error', message: 'Could not snap dialog url \'http://example.com/1.0.1/dialog-first.html\'' } |

Suite Dialog Result Diff

| Property | Type | Description | Example | | --- | --- | --- | --- | | index | Number | Index | 0 | | result | DifferConstant | Diff result | identical | | base64 | String | Diff image | data:image/png;base64,... |

Suite Error

Extends JS Error

| Property | Type | Description | Example | | --- | --- | --- | --- | | message | String | Error message | Unexpected error | | code | ErrorConstants | Error code | unexpected-error | | args | Object | Error arguments | { dialogId: 'one' } |

Constants

Error Constants

See ErrorConstants

| Property | Type | Description | | --- | --- | --- | | unexpected-error | String | Unexpected error |

TODO More errors

Differ Constants

| Property | Type | Description | | --- | --- | --- | | identical | String | Identical dialog/screenshot | | changed | String | Changed dialog/screenshot | | new | String | New dialog/screenshot | | deleted | String | Deleted dialog/screenshot |

Logger Constants

| Property | Type | Description | | --- | --- | --- | | none | String | No logging | | debug | String | Log, info and error logging | | info | String | Info and error logging | | error | String | Error logging |

Tests

  • npm install
  • npm test

Build

  • npm run dist

Todo

  • Examples