@robinpath/diff
0.1.1Node.jsPublicText and data diffing: line, word, character, object, and array diffs with unified output
Diff
Text and data diffing: line, word, character, object, and array diffs with unified output
Package: @robinpath/diff | Category: Utility | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the diff module when you need to:
- Diff two strings line by line -- Use
diff.linesto perform this operation - Diff two strings character by character -- Use
diff.charsto perform this operation - Diff two strings word by word -- Use
diff.wordsto perform this operation - Diff two objects -- Use
diff.objectsto perform this operation - Diff two arrays -- Use
diff.arraysto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
lines | Diff two strings line by line | Array of {type, value} |
chars | Diff two strings character by character | Array of {type, value} |
words | Diff two strings word by word | Array of {type, value} |
objects | Diff two objects | Array of {path, type, oldValue?, newValue?} |
arrays | Diff two arrays | {added, removed, common} |
patch | Apply a line diff to produce the new string | Patched string |
unified | Generate unified diff format (like git diff) | Unified diff string |
isEqual | Deep equality check | True if deeply equal |
stats | Get diff statistics from a diff result | {additions, deletions, unchanged} |
Functions
lines
Diff two strings line by line
Module: diff | Returns: array -- Array of {type, value}
diff.lines $old $new
| Parameter | Type | Required | Description |
|---|---|---|---|
a | string | Yes | Original text |
b | string | Yes | Modified text |
chars
Diff two strings character by character
Module: diff | Returns: array -- Array of {type, value}
diff.chars "cat" "car"
| Parameter | Type | Required | Description |
|---|---|---|---|
a | string | Yes | Original |
b | string | Yes | Modified |
words
Diff two strings word by word
Module: diff | Returns: array -- Array of {type, value}
diff.words $old $new
| Parameter | Type | Required | Description |
|---|---|---|---|
a | string | Yes | Original |
b | string | Yes | Modified |
objects
Diff two objects
Module: diff | Returns: array -- Array of {path, type, oldValue?, newValue?}
diff.objects $obj1 $obj2
| Parameter | Type | Required | Description |
|---|---|---|---|
a | object | Yes | Original object |
b | object | Yes | Modified object |
arrays
Diff two arrays
Module: diff | Returns: object -- {added, removed, common}
diff.arrays $arr1 $arr2
| Parameter | Type | Required | Description |
|---|---|---|---|
a | array | Yes | Original array |
b | array | Yes | Modified array |
patch
Apply a line diff to produce the new string
Module: diff | Returns: string -- Patched string
diff.patch $lineDiff
| Parameter | Type | Required | Description |
|---|---|---|---|
diff | array | Yes | Diff result from lines() |
unified
Generate unified diff format (like git diff)
Module: diff | Returns: string -- Unified diff string
diff.unified $old $new
| Parameter | Type | Required | Description |
|---|---|---|---|
a | string | Yes | Original text |
b | string | Yes | Modified text |
isEqual
Deep equality check
Module: diff | Returns: boolean -- True if deeply equal
diff.isEqual $a $b
| Parameter | Type | Required | Description |
|---|---|---|---|
a | any | Yes | First value |
b | any | Yes | Second value |
stats
Get diff statistics from a diff result
Module: diff | Returns: object -- {additions, deletions, unchanged}
diff.stats $lineDiff
| Parameter | Type | Required | Description |
|---|---|---|---|
diff | array | Yes | Diff result |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (standard errors) | Check function parameters and authentication |
@desc "Lines and validate result"
do
set $result as diff.lines $old $new
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. Multi-step Diff workflow
Chain multiple diff operations together.
@desc "Lines, chars, and more"
do
set $r_lines as diff.lines $old $new
set $r_chars as diff.chars "cat" "car"
set $r_words as diff.words $old $new
print "All operations complete"
enddo
2. Safe lines with validation
Check results before proceeding.
@desc "Lines and validate result"
do
set $result as diff.lines $old $new
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.1 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/diff
