Skip to content

Instantly share code, notes, and snippets.

@Sy1v4in
Created January 28, 2020 18:05
Show Gist options
  • Save Sy1v4in/23db427474ac9ea4e25b0e11e95888c1 to your computer and use it in GitHub Desktop.
Save Sy1v4in/23db427474ac9ea4e25b0e11e95888c1 to your computer and use it in GitHub Desktop.
Piece of code showing how to use diffJson. Could be used to redefine a better tap extension…
import * as Diff from 'diff'
import colors from 'colors/safe'
const diff = Diff.diffJson(postedData, expectedConversationManagerModel)
diff.forEach(part => {
const color = part.added ? 'green' : part.removed ? 'red' : 'grey'
process.stderr.write(colors[color](part.value))
})
console.log()
@Sy1v4in
Copy link
Author

Sy1v4in commented Jan 29, 2020

Need to install the diff and colors libraries, for instance

yarn add diff colors --exact

and types for typescript users

yarn add @types/diff @types/colors --dev --exact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment