### Install daff Library (Command Line) Source: https://github.com/paulfitz/daff/blob/master/README.md Installs the daff library globally for use as a command-line utility in Node.js, Python, Ruby, and PHP environments. ```shell npm install daff -g # node/javascript pip install daff # python gem install daff # ruby composer require paulfitz/daff-php # php ``` -------------------------------- ### Command Line Usage Examples Source: https://context7.com/paulfitz/daff/llms.txt Provides a comprehensive set of command-line examples for using DAFF. This includes basic file comparison, outputting diffs to files, generating HTML, using color output, performing three-way diffs, applying patches, merging with conflict detection, filtering changes, setting context, specifying primary keys, ignoring columns, handling different input/output formats (CSV, TSV, SQLite, JSON), and Git integration. ```bash # Compare two CSV files daff data1.csv data2.csv # Output diff to file daff --output diff.csv data1.csv data2.csv # Generate HTML output daff --output diff.html data1.csv data2.csv # Colored terminal output daff --color data1.csv data2.csv # Three-way diff with common ancestor daff parent.csv local.csv remote.csv # Apply patch daff patch --output result.csv original.csv changes.csv # Merge with conflict detection daff merge --output merged.csv parent.csv local.csv remote.csv # Show only specific change types daff --act update data1.csv data2.csv # Set context rows daff --context 3 data1.csv data2.csv # Specify primary key daff --id ProductID data1.csv data2.csv # Ignore columns daff --ignore Timestamp data1.csv data2.csv # Different file formats daff --input-format sqlite --output-format json db1.sqlite db2.sqlite # Compare TSV files daff data1.tsv data2.tsv # Open diff in browser daff --www data1.csv data2.csv # Git integration - setup as diff/merge driver for CSV files daff git csv ``` -------------------------------- ### CMake: Define Library and Executable Targets Source: https://github.com/paulfitz/daff/blob/master/packaging/cpp_recipe/coopyhx/CMakeLists.txt Configures the build process by locating source and header files, defining a shared library 'coopyhx_core', and an executable 'coopyhx_test'. It also specifies include directories and links necessary system libraries. ```cmake file(GLOB_RECURSE folder_headers include/*.h) file(GLOB_RECURSE folder_sources src/*.cpp) set(BUILD_SHARED_LIBS ON) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}) add_library(coopyhx_core ${folder_headers} ${folder_sources}) target_link_libraries(coopyhx_core pthread dl) add_executable(coopyhx_test main.cpp) target_link_libraries(coopyhx_test coopyhx_core) ``` -------------------------------- ### Publish GPG Key to Server (Bash) Source: https://github.com/paulfitz/daff/blob/master/RELEASE.md This command uploads your GPG public key to a public key server, making it accessible for others to verify your signatures. Replace `` with your actual GPG key ID. ```bash gpg --keyserver keyserver.ubuntu.com --send-keys ``` -------------------------------- ### Basic daff Command Line Usage Source: https://github.com/paulfitz/daff/blob/master/README.md Demonstrates basic command-line usage of daff for comparing two CSV files and producing a diff output. It also shows options for outputting to HTML and applying patches. ```shell daff a.csv b.csv daff [--color] [--no-color] [--output OUTPUT.csv] a.csv b.csv daff [--output OUTPUT.html] a.csv b.csv daff [--www] a.csv b.csv daff parent.csv a.csv b.csv daff --input-format sqlite a.db b.db daff patch [--inplace] a.csv patch.csv daff merge [--inplace] parent.csv a.csv b.csv daff trim [--output OUTPUT.csv] source.csv daff render [--output OUTPUT.html] diff.csv daff copy in.csv out.tsv daff in.csv daff git daff version ``` -------------------------------- ### Full Release and Deploy with Maven (Bash) Source: https://github.com/paulfitz/daff/blob/master/RELEASE.md This Maven command executes the complete release process, including staging, signing, and deploying artifacts to the configured remote repositories like Maven Central. This is the final step in publishing your project. ```bash mvn jreleaser:full-release ``` -------------------------------- ### Verify Release Configuration with Maven (Bash) Source: https://github.com/paulfitz/daff/blob/master/RELEASE.md This Maven command verifies the JReleaser configuration for the release process. It checks if all necessary settings and credentials are correctly set up before proceeding with publishing. ```bash mvn jreleaser:config ``` -------------------------------- ### CMake: Configure Project and Add Definitions Source: https://github.com/paulfitz/daff/blob/master/packaging/cpp_recipe/coopyhx/CMakeLists.txt Initializes the CMake project and sets preprocessor definitions for the build. These definitions are crucial for conditional compilation within the C++ source code, such as enabling specific features or targeting different platforms. ```cmake cmake_minimum_required(VERSION 2.8) project(coopyhx) add_definitions(-DHX_LINUX -DHXCPP_VISIT_ALLOCS -Dhaxe3 -DHXCPP_FORCE_OBJ_MAP) ``` -------------------------------- ### Configure JReleaser for Maven Central Publishing (Bash) Source: https://github.com/paulfitz/daff/blob/master/RELEASE.md This configuration file sets up essential credentials and keys required by JReleaser to publish artifacts to Maven Central. It includes Nexus 2 credentials, GPG key details, and a GitHub token. Ensure all placeholder values are replaced with your actual credentials. ```bash JRELEASER_NEXUS2_USERNAME= JRELEASER_NEXUS2_PASSWORD= JRELEASER_GPG_PASSPHRASE= JRELEASER_GPG_PUBLIC_KEY=/path/to/public.gpg JRELEASER_GPG_SECRET_KEY=/path/to/private.gpg JRELEASER_GITHUB_TOKEN= ``` -------------------------------- ### CMake Build Configuration for Haxe C++ Project Source: https://github.com/paulfitz/daff/blob/master/packaging/cpp_recipe/CMakeLists.txt This snippet outlines the core CMake configuration for the project. It sets the minimum CMake version, project name, and defines variables for source directories. It also includes logic for handling different Haxe versions and conditionally including main.cpp. ```cmake cmake_minimum_required(VERSION 2.8) project(coopyhx) # add_definitions(-DHXCPP_DEBUG=1 -DHXCPP_STACK_TRACE=1) set(REPLACE_MAIN TRUE) set(CGEN ${CMAKE_SOURCE_DIR}/../../cpp_pack) #include_directories(${CGEN}/include) # definitions are haxe version dependent - see: # /usr/lib/haxe/lib/hxcpp/x,x,x/build-tool/common-defines.xml ##########################################333 ## Haxe 2.10.2 #set(HX_BASE /usr/lib/haxe/lib/hxcpp/2,10,2) #add_definitions(-DHXCPP_VISIT_ALLOCS -Dhaxe_210) ##########################################333 ## Haxe 3.0.0 ##set(HX_BASE /usr/lib/haxe/lib/hxcpp/3,0,2) ##add_definitions(-DHX_LINUX=1 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS=1 -Dhaxe3=1 -Dhaxe_ver="3.") ##########################################333 ## Haxe 3.1 set(HX_BASE $ENV{HOME}/scm/hxcpp) add_definitions(-DHX_LINUX=1 -DHXCPP_VISIT_ALLOCS=1 -Dhaxe3=1 -Dhaxe_ver="3.") # -DHXCPP_DEBUG=1 -DHXCPP_VISIT_ALLOCS=1) if (NOT REPLACE_MAIN) set_property(SOURCE ${CGEN}/src/__main__.cpp APPEND PROPERTY COMPILE_DEFINITIONS HX_DECLARE_MAIN=1) endif () # include_directories(${HX_BASE}/include/) #add_definitions(-DHXCPP_DEBUG) add_definitions(-include unistd.h) # getpid not found otherwise # add_definitions(-m32) # pointer stored as 32-bit integer in haxe code file(GLOB folder_source ${CGEN}/src/*.cpp) file(GLOB folder_source_coopy ${CGEN}/src/coopy/*.cpp) file(GLOB folder_source_haxe ${CGEN}/src/haxe/*.cpp) file(GLOB folder_source_haxe_ds ${CGEN}/src/haxe/ds/*.cpp) file(GLOB folder_source_haxe_io ${CGEN}/src/haxe/io/*.cpp) file(GLOB folder_source_sys_io ${CGEN}/src/sys/io/*.cpp) file(GLOB folder_source_cpp ${CGEN}/src/cpp/*.cpp) # this will have to be # removed, it loads a neko library for hxcpp3; or maybe -Dstatic_link can # be enough, need to investigate... file(GLOB_RECURSE folder_header ${CGEN}/include/*.h) file(GLOB hx_source ${HX_BASE}/src/*.cpp) list(REMOVE_ITEM hx_source ${HX_BASE}/src/ExampleMain.cpp) file(GLOB hx_source2 ${HX_BASE}/src/hx/*.cpp) list(REMOVE_ITEM hx_source2 ${HX_BASE}/src/hx/NekoAPI.cpp) list(REMOVE_ITEM hx_source2 ${HX_BASE}/src/hx/RunLibs.cpp) list(REMOVE_ITEM hx_source2 ${HX_BASE}/src/hx/Scriptable.cpp) list(REMOVE_ITEM hx_source2 ${HX_BASE}/src/hx/CppiaBuiltin.cpp) list(REMOVE_ITEM hx_source2 ${HX_BASE}/src/hx/Cppia.cpp) if (REPLACE_MAIN) list(REMOVE_ITEM folder_source ${CGEN}/src/__main__.cpp) # list(REMOVE_ITEM folder_source ${CGEN}/src/__boot__.cpp) list(REMOVE_ITEM folder_source ${CGEN}/src/Sys.cpp) list(APPEND folder_source ${CMAKE_SOURCE_DIR}/main.cpp) endif () link_libraries(pthread dl) set(all_sources ${folder_source} ${folder_source_coopy} ${folder_source_haxe} ${folder_source_haxe_ds} ${folder_source_haxe_io} ${folder_source_sys_io} ${folder_source_cpp} ${folder_source_cpp} ${folder_header} ${hx_source} ${hx_source2} ${CGEN}/src/haxe/Log.cpp) ``` -------------------------------- ### Advanced daff Diff Options Source: https://github.com/paulfitz/daff/blob/master/README.md Details advanced command-line options for the `daff diff` command, including filtering by change type, handling unchanged rows/columns, colorization, context, primary keys, ignoring columns, and input/output formats. ```shell daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv --act ACT: show only a certain kind of change (update, insert, delete, column) --all: do not prune unchanged rows or columns --all-rows: do not prune unchanged rows --all-columns: do not prune unchanged columns --color: highlight changes with terminal colors (default in terminals) --context NUM: show NUM rows of context (0=none) --context-columns NUM: show NUM columns of context (0=none) --fail-if-diff: return status is 0 if equal, 1 if different, 2 if problem --id: specify column to use as primary key (repeat for multi-column key) --ignore: specify column to ignore completely (can repeat) --index: include row/columns numbers from original tables --input-format [csv|tsv|ssv|psv|json|sqlite]: set format to expect for input --eol [crlf|lf|cr|auto]: separator between rows of csv output. --no-color: make sure terminal colors are not used --ordered: assume row order is meaningful (default for CSV) --output-format [csv|tsv|ssv|psv|json|copy|html]: set format for output --padding [dense|sparse|smart]: set padding method for aligning columns --table NAME: compare the named table, used with SQL sources. If name changes, use 'n1:n2' --unordered: assume row order is meaningless (default for json formats) -w / --ignore-whitespace: ignore changes in leading/trailing whitespace -i / --ignore-case: ignore differences in case ``` -------------------------------- ### Export GPG Keys (Bash) Source: https://github.com/paulfitz/daff/blob/master/RELEASE.md These commands export your GPG public and private keys into armored file formats. This is necessary for JReleaser to access and use your keys for signing artifacts. Replace `username@email-host` with your GPG key's associated email and username. ```bash gpg --output public.gpg --armor --export username@email-host gpg --output private.gpg --armor --export-secret-key username@email-host ``` -------------------------------- ### Generate and Highlight Table Differences in Javascript Source: https://github.com/paulfitz/daff/blob/master/README.md Shows how to create a diff from a computed alignment and highlight the changes into a new table. This process uses daff.CompareFlags for customization and daff.TableDiff to apply the highlighting. ```javascript const data_diff = []; const table_diff = new daff.TableView(data_diff); const flags = new daff.CompareFlags(); const highlighter = new daff.TableDiff(alignment,flags); highlighter.hilite(table_diff); // The diff is now in data_diff in highlighter format: // [ [ '!', '', '+++', '' ], // [ '@@', 'Country', 'Code', 'Capital' ], // [ '+', 'Ireland', 'ie', 'Dublin' ], // [ '+', 'France', 'fr', 'Paris' ], // [ '->', 'Spain', 'es', 'Barcelona->Madrid' ], // [ '+++', 'Germany', 'de', 'Berlin' ] ] ``` -------------------------------- ### Stage Artifacts Locally with Maven (Bash) Source: https://github.com/paulfitz/daff/blob/master/RELEASE.md This Maven command, using the 'publication' profile, stages all build artifacts to a local directory. This is a preliminary step before deploying to remote repositories, allowing for local inspection. ```bash mvn -Ppublication ``` -------------------------------- ### Configure Comparison Flags (JavaScript) Source: https://context7.com/paulfitz/daff/llms.txt Customizes the data comparison behavior using `daff.CompareFlags`. Options include setting primary keys, controlling the display of unchanged rows, defining context rows, ignoring specific columns or differences (whitespace, case), and filtering change types. The output is a diff table and summary statistics. ```javascript const daff = require('daff'); const table1 = new daff.TableView([ ['Name','Age','City','Country'], ['Alice','30','NYC','USA'], ['Bob','25','LA','USA'], ['Charlie','28','Chicago','USA'] ]); const table2 = new daff.TableView([ ['Name','Age','City','Country'], ['Alice','31','NYC','USA'], ['Bob','25','SF','USA'], ['David','35','Boston','USA'] ]); // Configure flags const flags = new daff.CompareFlags(); // Specify primary key column(s) flags.addPrimaryKey('Name'); // Show all rows, not just changed ones flags.show_unchanged = true; // Set context rows around changes flags.unchanged_context = 2; // Ignore specific columns flags.ignoreColumn('Country'); // Ignore whitespace differences flags.ignore_whitespace = true; // Ignore case differences flags.ignore_case = true; // Filter to show only specific change types flags.filter('insert', true); // Show inserts flags.filter('delete', true); // Show deletes flags.filter('update', true); // Show updates // Compare with flags const alignment = daff.compareTables(table1, table2, flags).align(); const diff = []; new daff.TableDiff(alignment, flags).hilite(new daff.TableView(diff)); console.log('Configured diff:', diff); // Get diff summary statistics const td = new daff.TableDiff(alignment, flags); td.hilite(new daff.TableView([])); const summary = td.getSummary(); console.log('Changes:', { row_inserts: summary.row_inserts, row_deletes: summary.row_deletes, row_updates: summary.row_updates, col_inserts: summary.col_inserts, col_deletes: summary.col_deletes, different: summary.different }); ``` -------------------------------- ### Apply Differences as a Patch in Javascript Source: https://github.com/paulfitz/daff/blob/master/README.md Demonstrates how to apply a generated diff as a patch to an existing table. The daff.HighlightPatch class modifies the original table in place, making it equal to the target table after the patch is applied. ```javascript const patcher = new daff.HighlightPatch(table1,table_diff); patcher.apply(); // table1 should now equal table2 ``` -------------------------------- ### Python API Usage for Data Analysis Source: https://context7.com/paulfitz/daff/llms.txt Demonstrates how to use the DAFF library in Python for comparing tabular data. It covers creating tables, generating diffs, rendering them as HTML, and applying patches to update data. This is suitable for data analysis workflows. ```python import daff # Create tables data1 = [ ['Country','Capital'], ['Ireland','Dublin'], ['France','Paris'], ['Spain','Barcelona'] ] data2 = [ ['Country','Code','Capital'], ['Ireland','ie','Dublin'], ['France','fr','Paris'], ['Spain','es','Madrid'], ['Germany','de','Berlin'] ] # Wrap in PythonTableView table1 = daff.PythonTableView(data1) table2 = daff.PythonTableView(data2) # Generate diff alignment = daff.Coopy.compareTables(table1, table2).align() data_diff = [] table_diff = daff.PythonTableView(data_diff) flags = daff.CompareFlags() highlighter = daff.TableDiff(alignment, flags) highlighter.hilite(table_diff) # Render as HTML diff2html = daff.DiffRender() diff2html.render(table_diff) html_output = diff2html.html() print(html_output) # Apply patch patcher = daff.HighlightPatch(table1, table_diff) patcher.apply() # table1 now equals table2 ``` -------------------------------- ### CMake File Copying and Configuration Source: https://github.com/paulfitz/daff/blob/master/packaging/cpp_recipe/CMakeLists.txt This CMake snippet iterates through discovered source and header files, copying them to a build directory while maintaining their relative paths. It also copies specific project files and configures the include path for generated headers. ```cmake foreach(f ${all_sources}) set(done FALSE) string(REGEX MATCH "^${CGEN}/(.*)" match ${f}) if (match) string(REGEX REPLACE "^${CGEN}/" "" match ${match}) message(STATUS "Looking at ${f} -> ${match}") set (done TRUE) endif() if (NOT match) string(REGEX MATCH "^${HX_BASE}/(.*)" match ${f}) if (match) string(REGEX REPLACE "^${HX_BASE}/" "" match ${match}) message(STATUS "Looking at ${f} -> ${match}") set (done TRUE) endif() endif() if (NOT done) message(STATUS "PENDING ${f}") else () message(STATUS "MATCH ${match}") set(oname ${CMAKE_BINARY_DIR}/coopyhx/${match}) get_filename_component(dname ${oname} PATH) file(MAKE_DIRECTORY ${dname}) configure_file(${f} ${oname} COPYONLY) endif() endforeach() file(GLOB_RECURSE hx_headers RELATIVE ${HX_BASE} ${HX_BASE}/include/*.h) file(GLOB_RECURSE hx_headers2 RELATIVE ${HX_BASE} ${HX_BASE}/src/hx/*.h) foreach (f ${hx_headers} ${hx_headers2}) set(oname ${CMAKE_BINARY_DIR}/coopyhx/${f}) get_filename_component(dname ${oname} PATH) file(MAKE_DIRECTORY ${dname}) configure_file(${HX_BASE}/${f} ${oname} COPYONLY) endforeach() foreach (f CMakeLists.txt coopyhx.i example.rb fix_for_swig.sh fix_for_swig1.pl coopyhx.h coopyhx_obj.h) configure_file(coopyhx/${f} ${CMAKE_BINARY_DIR}/coopyhx/ COPYONLY) endforeach () configure_file(main.cpp ${CMAKE_BINARY_DIR}/coopyhx/ COPYONLY) include_directories(${CMAKE_BINARY_DIR}/coopyhx/include) add_executable(test_coopy ${all_sources}) ``` -------------------------------- ### Create and Compare Tables in Javascript Source: https://github.com/paulfitz/daff/blob/master/README.md Demonstrates how to create daff TableView objects from JavaScript arrays and then compare them to generate an alignment. This is the first step in identifying differences between two tables. ```javascript const data1 = [ ['Country','Capital'], ['Ireland','Dublin'], ['France','Paris'], ['Spain','Barcelona'] ]; const data2 = [ ['Country','Code','Capital'], ['Ireland','ie','Dublin'], ['France','fr','Paris'], ['Spain','es','Madrid'], ['Germany','de','Berlin'] ]; const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); const alignment = daff.compareTables(table1,table2).align(); ``` -------------------------------- ### CMake: Conditional Ruby Interface Build with SWIG Source: https://github.com/paulfitz/daff/blob/master/packaging/cpp_recipe/coopyhx/CMakeLists.txt This snippet handles the conditional compilation of a Ruby interface using SWIG. It checks a build flag, finds the SWIG executable and Ruby development files, and configures SWIG to generate the necessary bindings. ```cmake set(CREATE_RUBY FALSE CACHE BOOL "Do you want to create the Ruby interface") if (CREATE_RUBY) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) message(STATUS "${SWIG_USE_FILE}") set_source_files_properties(coopyhx.i PROPERTIES CPLUSPLUS ON) endif () if (CREATE_RUBY) find_package(Ruby REQUIRED) set(CMAKE_SWIG_FLAGS "-Wall;-module;coopyhx") include_directories(${RUBY_INCLUDE_PATH}) swig_add_module(coopyhx ruby coopyhx.i) swig_link_libraries(coopyhx ${RUBY_LIBRARY}) set_target_properties(coopyhx PROPERTIES PREFIX "") target_link_libraries(coopyhx coopyhx_core) endif (CREATE_RUBY) ``` -------------------------------- ### Generate HTML Diff Visualization Source: https://context7.com/paulfitz/daff/llms.txt This endpoint demonstrates how to render a table diff into an HTML format, complete with CSS styling for a visually appealing representation of the differences. ```APIDOC ## Generate HTML Diff Visualization ### Description Renders a table diff into an HTML string with optional CSS styling, providing a human-readable visualization of differences. ### Method N/A (This is a library function, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```javascript const daff = require('daff'); const data1 = [ ['Name','Age','City'], ['Alice','30','NYC'], ['Bob','25','LA'] ]; const data2 = [ ['Name','Age','City'], ['Alice','31','NYC'], ['Bob','25','SF'], ['Charlie','28','Chicago'] ]; const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); // Method 1: Direct HTML generation const html = daff.Coopy.diffAsHtml(table1, table2); // Method 2: Manual rendering with options const alignment = daff.compareTables(table1, table2).align(); const data_diff = []; const table_diff = new daff.TableView(data_diff); const flags = new daff.CompareFlags(); const td = new daff.TableDiff(alignment, flags); td.hilite(table_diff); const diff2html = new daff.DiffRender(); diff2html.usePrettyArrows(true); // Use Unicode arrows diff2html.render(table_diff); const table_diff_html = diff2html.html(); const css = diff2html.sampleCss(); console.log(table_diff_html); ``` ### Response #### Success Response (HTML Output) - **html** (string) - An HTML string representing the diff visualization. - **css** (string) - A CSS string for styling the HTML output. #### Response Example ```html
NameAgeCity
Alice30 -> 31NYC
Bob25LA -> SF
Charlie28Chicago
/* Example CSS output */ .diff-table { border-collapse: collapse; } .diff-table th, .diff-table td { padding: 5px; border: 1px solid #ccc; } .diff-table .added { background-color: #e6ffed; } .diff-table .deleted { background-color: #ffe6e6; } .diff-table .changed { color: #a00; } ``` ``` -------------------------------- ### Configure daff for Git (Shell) Source: https://github.com/paulfitz/daff/blob/master/README.md Instructions for configuring daff as a diff and merge handler for CSV files within a Git repository. This enhances Git's understanding of tabular data. ```shell daff git csv ``` -------------------------------- ### Compare Two Tables and Generate Diff Source: https://context7.com/paulfitz/daff/llms.txt This endpoint allows you to compare two versions of a table and generate a diff table that highlights the differences. It supports various output formats and can identify structural changes. ```APIDOC ## Compare Two Tables and Generate Diff ### Description Compares two versions of a table and produces a diff table, highlighting structural and content differences. ### Method N/A (This is a library function, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```javascript const daff = require('daff'); const data1 = [ ['Country','Capital'], ['Ireland','Dublin'], ['France','Paris'], ['Spain','Barcelona'] ]; const data2 = [ ['Country','Code','Capital'], ['Ireland','ie','Dublin'], ['France','fr','Paris'], ['Spain','es','Madrid'], ['Germany','de','Berlin'] ]; const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); const alignment = daff.compareTables(table1, table2).align(); const data_diff = []; const table_diff = new daff.TableView(data_diff); const flags = new daff.CompareFlags(); const highlighter = new daff.TableDiff(alignment, flags); highlighter.hilite(table_diff); console.log(data_diff); ``` ### Response #### Success Response (Output Data Structure) - **data_diff** (Array>) - A 2D array representing the diff table. Each inner array represents a row with special markers indicating changes: - `!` for schema changes - `@@` for headers - `+++` for added rows - `---` for deleted rows - `->` for updated cells (old_value->new_value) #### Response Example ```json [ [ '!', '', '+++', '' ], [ '@@', 'Country', 'Code', 'Capital' ], [ '+', 'Ireland', 'ie', 'Dublin' ], [ '+', 'France', 'fr', 'Paris' ], [ '->', 'Spain', 'es', 'Barcelona->Madrid' ], [ '+++', 'Germany', 'de', 'Berlin' ] ] ``` ``` -------------------------------- ### daff Render HTML Options Source: https://github.com/paulfitz/daff/blob/master/README.md Outlines command-line options for the `daff render` command, used to generate HTML diffs from CSV diff files. Options include specifying CSS, generating fragments, and controlling character encoding. ```shell daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv --css CSS.css: generate a suitable css file to go with the html --fragment: generate just a html fragment rather than a page --plain: do not use fancy utf8 characters to make arrows prettier --unquote: do not quote html characters in html diffs --www: send output to a browser ``` -------------------------------- ### Compare Tables and Generate Diff (JavaScript) Source: https://context7.com/paulfitz/daff/llms.txt Compares two tables and generates a diff highlighting differences in rows and columns. It uses daff's TableView and CompareFlags to process and align table data, outputting a highlighted diff. Dependencies include the 'daff' library. ```javascript const daff = require('daff'); const data1 = [ ['Country','Capital'], ['Ireland','Dublin'], ['France','Paris'], ['Spain','Barcelona'] ]; const data2 = [ ['Country','Code','Capital'], ['Ireland','ie','Dublin'], ['France','fr','Paris'], ['Spain','es','Madrid'], ['Germany','de','Berlin'] ]; // Wrap data in TableView const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); // Compare tables and generate alignment const alignment = daff.compareTables(table1, table2).align(); // Create output table for diff const data_diff = []; const table_diff = new daff.TableView(data_diff); // Generate highlighted diff const flags = new daff.CompareFlags(); const highlighter = new daff.TableDiff(alignment, flags); highlighter.hilite(table_diff); // Result in data_diff: // [ [ '!', '', '+++', '' ], // [ '@@', 'Country', 'Code', 'Capital' ], // [ '+', 'Ireland', 'ie', 'Dublin' ], // [ '+', 'France', 'fr', 'Paris' ], // [ '->', 'Spain', 'es', 'Barcelona->Madrid' ], // [ '+++', 'Germany', 'de', 'Berlin' ] ] console.log(data_diff); ``` -------------------------------- ### Work with JSON Tables using Daff Source: https://context7.com/paulfitz/daff/llms.txt This snippet demonstrates how to parse JSON-formatted tabular data into daff tables and generate a diff. It handles both standard JSON objects and NDJSON formats, allowing for comparison of datasets. ```javascript const daff = require('daff'); const fs = require('fs'); // JSON table format const json1 = { sheet: { columns: ['Name', 'Age', 'City'], rows: [ ['Alice', 30, 'NYC'], ['Bob', 25, 'LA'] ] } }; const json2 = { sheet: { columns: ['Name', 'Age', 'City'], rows: [ ['Alice', 31, 'NYC'], ['Charlie', 28, 'Chicago'] ] } }; // Parse JSON to tables const table1 = daff.Coopy.tablify(json1); const table2 = daff.Coopy.tablify(json2); // Generate diff const flags = new daff.CompareFlags(); flags.ordered = false; // JSON tables are typically unordered flags.allow_nested_cells = true; // Support nested JSON structures const diff_table = daff.Coopy.diff(table1, table2, flags); console.log('JSON diff complete'); // Alternative: NDJSON (newline-delimited JSON) // Each row is a separate JSON object const ndjson1 = `{"Name":"Alice","Age":30,"City":"NYC"} {"Name":"Bob","Age":25,"City":"LA"}`; const ndjson2 = `{"Name":"Alice","Age":31,"City":"NYC"} {"Name":"Charlie","Age":28,"City":"Chicago"}`; // Parse and compare NDJSON // (requires writing to files and using CLI or implementing parser) ``` -------------------------------- ### Include daff Library in Web Page (HTML) Source: https://github.com/paulfitz/daff/blob/master/README.md Includes the daff library from a CDN for use in web pages. This allows client-side JavaScript to utilize daff's table comparison functionalities. ```html ``` -------------------------------- ### Render Table Differences to HTML in Javascript Source: https://github.com/paulfitz/daff/blob/master/README.md Converts the highlighted table differences into an HTML table format for easy visualization. The daff.DiffRender class handles this conversion, providing an HTML string output. ```javascript const diff2html = new daff.DiffRender(); diff2html.render(table_diff); const table_diff_html = diff2html.html(); ``` -------------------------------- ### Generate HTML Diff Visualization (JavaScript) Source: https://context7.com/paulfitz/daff/llms.txt Renders a table difference as an HTML visualization with optional CSS styling. This snippet shows two methods: direct HTML generation using `diffAsHtml` and manual rendering with customization options for arrows and CSS. It requires the 'daff' library. ```javascript const daff = require('daff'); const data1 = [ ['Name','Age','City'], ['Alice','30','NYC'], ['Bob','25','LA'] ]; const data2 = [ ['Name','Age','City'], ['Alice','31','NYC'], ['Bob','25','SF'], ['Charlie','28','Chicago'] ]; const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); // Method 1: Direct HTML generation const html = daff.Coopy.diffAsHtml(table1, table2); // Method 2: Manual rendering with options const alignment = daff.compareTables(table1, table2).align(); const data_diff = []; const table_diff = new daff.TableView(data_diff); const flags = new daff.CompareFlags(); const td = new daff.TableDiff(alignment, flags); td.hilite(table_diff); const diff2html = new daff.DiffRender(); diff2html.usePrettyArrows(true); // Use Unicode arrows diff2html.render(table_diff); const table_diff_html = diff2html.html(); const css = diff2html.sampleCss(); // Write to file or serve console.log(table_diff_html); ``` -------------------------------- ### Import daff Library in Node.js (JavaScript) Source: https://github.com/paulfitz/daff/blob/master/README.md Imports the daff library into a Node.js environment for server-side JavaScript applications. This enables programmatic access to daff's diffing and patching capabilities. ```javascript var daff = require('daff'); ``` -------------------------------- ### Generate Colored Terminal Output using Daff Source: https://context7.com/paulfitz/daff/llms.txt This snippet shows how to generate ANSI-colored diffs for terminal display using the daff library. It takes two tables as input and outputs a string with ANSI escape codes for color formatting. ```javascript const daff = require('daff'); const data1 = [ ['Product','Price'], ['Widget','10.00'], ['Gadget','20.00'] ]; const data2 = [ ['Product','Price'], ['Widget','12.00'], ['Gadget','20.00'], ['Doohickey','15.00'] ]; const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); // Generate ANSI colored output const flags = new daff.CompareFlags(); flags.terminal_format = "ansi"; // Force ANSI colors const ansi_output = daff.Coopy.diffAsAnsi(table1, table2, flags); // Print to terminal with colors console.log(ansi_output); // The output includes: // - Green background for additions (+++, +) // - Red background for deletions (---) // - Blue background for modifications (->) // - Gray background for schema changes (!) ``` -------------------------------- ### Apply Patch to Table Source: https://context7.com/paulfitz/daff/llms.txt This endpoint allows you to apply a previously generated diff (patch) to an existing table, modifying it to reflect the changes specified in the patch. ```APIDOC ## Apply Patch to Table ### Description Applies a diff (patch) to an existing table, modifying it in place according to the patch instructions. ### Method N/A (This is a library function, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```javascript const daff = require('daff'); // Original table const original = [ ['Product','Price','Stock'], ['Widget','10.00','100'], ['Gadget','20.00','50'] ]; // Patch table (previously generated diff) const patch = [ ['!','','',''], ['@@','Product','Price','Stock'], ['->','Widget','10.00->12.00','100'], ['+++','Doohickey','15.00','75'] ]; const table_original = new daff.TableView(original); const table_patch = new daff.TableView(patch); // Apply patch const patcher = new daff.HighlightPatch(table_original, table_patch); const success = patcher.apply(); // original now contains the updated data console.log('Patch applied:', success); console.log('Updated table:', original); ``` ### Response #### Success Response (Apply Status) - **success** (boolean) - `true` if the patch was applied successfully, `false` otherwise. - **original** (Array>) - The modified original table data. #### Response Example ```json { "success": true, "original": [ ["Product","Price","Stock"], ["Widget","12.00","100"], ["Gadget","20.00","50"], ["Doohickey","15.00","75"] ] } ``` ``` -------------------------------- ### Three-Way Diff with Common Ancestor (JavaScript) Source: https://context7.com/paulfitz/daff/llms.txt Compares two tables (local and remote) against a common ancestor (parent) to identify differences. This is useful for understanding changes in a version control scenario. It utilizes the `daff.compareTables3` function and `daff.TableDiff` for highlighting differences. ```javascript const daff = require('daff'); // Parent version (common ancestor) const parent = [ ['ID','Name','Score'], ['1','Alice','85'], ['2','Bob','90'] ]; // Local version (your changes) const local = [ ['ID','Name','Score'], ['1','Alice','87'], // You changed Alice's score ['2','Bob','90'] ]; // Remote version (their changes) const remote = [ ['ID','Name','Score'], ['1','Alice','85'], ['2','Bob','92'] // They changed Bob's score ]; const table_parent = new daff.TableView(parent); const table_local = new daff.TableView(local); const table_remote = new daff.TableView(remote); // Three-way comparison const alignment = daff.compareTables3(table_parent, table_local, table_remote).align(); const data_diff = []; const table_diff = new daff.TableView(data_diff); const flags = new daff.CompareFlags(); const td = new daff.TableDiff(alignment, flags); td.hilite(table_diff); // Shows changes from parent to remote that should be applied to local console.log('Three-way diff:', data_diff); ``` -------------------------------- ### Apply Patch to Table (JavaScript) Source: https://context7.com/paulfitz/daff/llms.txt Applies a previously generated diff (patch) to modify an original table. This function takes a table representing the patch and applies its changes (updates, additions) to the target table. It returns a boolean indicating success. Requires the 'daff' library. ```javascript const daff = require('daff'); // Original table const original = [ ['Product','Price','Stock'], ['Widget','10.00','100'], ['Gadget','20.00','50'] ]; // Patch table (previously generated diff) const patch = [ ['!','','',''], ['@@','Product','Price','Stock'], ['->','Widget','10.00->12.00','100'], ['+++','Doohickey','15.00','75'] ]; const table_original = new daff.TableView(original); const table_patch = new daff.TableView(patch); // Apply patch const patcher = new daff.HighlightPatch(table_original, table_patch); const success = patcher.apply(); // original now contains: // [['Product','Price','Stock'], // ['Widget','12.00','100'], // ['Gadget','20.00','50'], // ['Doohickey','15.00','75']] console.log('Patch applied:', success); console.log('Updated table:', original); ``` -------------------------------- ### Render Diff with Custom Cell Builder using Daff Source: https://context7.com/paulfitz/daff/llms.txt This snippet illustrates how to customize diff cell generation and formatting using daff's CellBuilder. It specifically uses the NestedCellBuilder to produce structured output for modified cells, representing changes as objects with 'before' and 'after' properties. ```javascript const daff = require('daff'); const data1 = [['A','B'],[1,2],[3,4]]; const data2 = [['A','B'],[1,5],[3,4],[6,7]]; const table1 = new daff.TableView(data1); const table2 = new daff.TableView(data2); const alignment = daff.compareTables(table1, table2).align(); const diff = []; const table_diff = new daff.TableView(diff); const flags = new daff.CompareFlags(); flags.allow_nested_cells = true; // Enable nested cell format const td = new daff.TableDiff(alignment, flags); // Use nested cell builder for structured output const builder = new daff.NestedCellBuilder(); td.setCellBuilder(builder); td.hilite(table_diff); // Nested format gives {before: "2", after: "5"} instead of "2->5" console.log('Nested diff:', diff); // Access diff summary const summary = td.getSummary(); console.log('Summary:', { different: summary.different, row_count_initial: summary.row_count_initial, row_count_final: summary.row_count_final, row_updates: summary.row_updates, row_inserts: summary.row_inserts }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.