Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
5 changes: 2 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ jobs:
node-version: 'lts/*'
cache: 'npm'
- run: npm ci
- run: npm run format-check
- run: npm run lint
working-directory: ./packages/jsondiffpatch
- run: npm run build
working-directory: ./packages/jsondiffpatch
- run: npm run lint
- run: npm run type-check
- run: npm run test
working-directory: ./packages/jsondiffpatch
- run: npm run start
Expand Down
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

28 changes: 28 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedImports": "error",
"noUnusedVariables": "error",
"useHookAtTopLevel": "error"
},
"style": {
"useCollapsedElseIf": "error",
"useShorthandArrayType": "error",
"useForOf": "error"
},
"suspicious": {
"noEmptyBlockStatements": "error"
}
}
},
"files": {
"ignore": ["node_modules", "dist", "build", "lib", "coverage"]
}
}
299 changes: 153 additions & 146 deletions demos/console-demo/demo.ts
Original file line number Diff line number Diff line change
@@ -1,169 +1,176 @@
import * as consoleFormatter from 'jsondiffpatch/formatters/console';
import * as jsondiffpatch from 'jsondiffpatch/with-text-diffs';
import * as consoleFormatter from "jsondiffpatch/formatters/console";
import * as jsondiffpatch from "jsondiffpatch/with-text-diffs";

const instance = jsondiffpatch.create({
objectHash: function (obj) {
const objRecord = obj as Record<string, string>;
return (
objRecord._id ||
objRecord.id ||
objRecord.name ||
JSON.stringify(objRecord)
);
},
objectHash: (obj) => {
const objRecord = obj as Record<string, string>;
return (
objRecord._id ||
objRecord.id ||
objRecord.name ||
JSON.stringify(objRecord)
);
},
});

interface Data {
name: string;
summary: string;
surface?: number;
timezone: number[];
demographics: { population: number; largestCities: string[] };
languages: string[];
countries: {
name: string;
capital?: string;
independence?: Date;
population?: number;
}[];
spanishName?: string;
interface Continent {
name: string;
summary: string;
surface?: number;
timezone: [number, number];
demographics: { population: number; largestCities: string[] };
languages: string[];
countries: Country[];
spanishName?: string;
}

const data: Data = {
name: 'South America',
summary:
'South America (Spanish: América del Sur, Sudamérica or Suramérica;' +
' Portuguese: América do Sul; Quechua and Aymara: Urin Awya Yala;' +
' Guarani: Ñembyamérika; Dutch: Zuid-Amerika; French: Amérique du Sud)' +
' is a continent situated in the Western Hemisphere, mostly in the' +
' Southern Hemisphere, with a relatively small portion in the Northern' +
' Hemisphere. The continent is also considered a subcontinent of the' +
' Americas.[2][3] It is bordered on the west by the Pacific Ocean and' +
' on the north and east by the Atlantic Ocean; North America and the' +
' Caribbean Sea lie to the northwest. It includes twelve countries: ' +
'Argentina, Bolivia, Brazil, Chile, Colombia, Ecuador, Guyana, Paraguay' +
', Peru, Suriname, Uruguay, and Venezuela. The South American nations' +
' that border the Caribbean Sea—including Colombia, Venezuela, Guyana,' +
' Suriname, as well as French Guiana, which is an overseas region of' +
' France—are also known as Caribbean South America. South America has' +
' an area of 17,840,000 square kilometers (6,890,000 sq mi).' +
' Its population as of 2005 has been estimated at more than 371,090,000.' +
' South America ranks fourth in area (after Asia, Africa, and' +
' North America) and fifth in population (after Asia, Africa,' +
' Europe, and North America). The word America was coined in 1507 by' +
' cartographers Martin Waldseemüller and Matthias Ringmann, after' +
' Amerigo Vespucci, who was the first European to suggest that the' +
' lands newly discovered by Europeans were not India, but a New World' +
' unknown to Europeans.',
interface Country {
name: string;
capital?: string;
independence?: Date;
population?: number;
}

const data: Continent = {
name: "South America",
summary:
"South America (Spanish: América del Sur, Sudamérica or Suramérica;" +
" Portuguese: América do Sul; Quechua and Aymara: Urin Awya Yala;" +
" Guarani: Ñembyamérika; Dutch: Zuid-Amerika; French: Amérique du Sud)" +
" is a continent situated in the Western Hemisphere, mostly in the" +
" Southern Hemisphere, with a relatively small portion in the Northern" +
" Hemisphere. The continent is also considered a subcontinent of the" +
" Americas.[2][3] It is bordered on the west by the Pacific Ocean and" +
" on the north and east by the Atlantic Ocean; North America and the" +
" Caribbean Sea lie to the northwest. It includes twelve countries: " +
"Argentina, Bolivia, Brazil, Chile, Colombia, Ecuador, Guyana, Paraguay" +
", Peru, Suriname, Uruguay, and Venezuela. The South American nations" +
" that border the Caribbean Sea—including Colombia, Venezuela, Guyana," +
" Suriname, as well as French Guiana, which is an overseas region of" +
" France—are also known as Caribbean South America. South America has" +
" an area of 17,840,000 square kilometers (6,890,000 sq mi)." +
" Its population as of 2005 has been estimated at more than 371,090,000." +
" South America ranks fourth in area (after Asia, Africa, and" +
" North America) and fifth in population (after Asia, Africa," +
" Europe, and North America). The word America was coined in 1507 by" +
" cartographers Martin Waldseemüller and Matthias Ringmann, after" +
" Amerigo Vespucci, who was the first European to suggest that the" +
" lands newly discovered by Europeans were not India, but a New World" +
" unknown to Europeans.",

surface: 17840000,
timezone: [-4, -2],
demographics: {
population: 385742554,
largestCities: [
'São Paulo',
'Buenos Aires',
'Rio de Janeiro',
'Lima',
'Bogotá',
],
},
languages: [
'spanish',
'portuguese',
'english',
'dutch',
'french',
'quechua',
'guaraní',
'aimara',
'mapudungun',
],
countries: [
{
name: 'Argentina',
capital: 'Buenos Aires',
independence: new Date(1816, 6, 9),
},
{
name: 'Bolivia',
capital: 'La Paz',
independence: new Date(1825, 7, 6),
},
{
name: 'Brazil',
capital: 'Brasilia',
independence: new Date(1822, 8, 7),
},
{
name: 'Chile',
capital: 'Santiago',
independence: new Date(1818, 1, 12),
},
{
name: 'Colombia',
capital: 'Bogotá',
independence: new Date(1810, 6, 20),
},
{
name: 'Ecuador',
capital: 'Quito',
independence: new Date(1809, 7, 10),
},
{
name: 'Guyana',
capital: 'Georgetown',
independence: new Date(1966, 4, 26),
},
{
name: 'Paraguay',
capital: 'Asunción',
independence: new Date(1811, 4, 14),
},
{
name: 'Peru',
capital: 'Lima',
independence: new Date(1821, 6, 28),
},
{
name: 'Suriname',
capital: 'Paramaribo',
independence: new Date(1975, 10, 25),
},
{
name: 'Uruguay',
capital: 'Montevideo',
independence: new Date(1825, 7, 25),
},
{
name: 'Venezuela',
capital: 'Caracas',
independence: new Date(1811, 6, 5),
},
],
surface: 17840000,
timezone: [-4, -2],
demographics: {
population: 385742554,
largestCities: [
"São Paulo",
"Buenos Aires",
"Rio de Janeiro",
"Lima",
"Bogotá",
],
},
languages: [
"spanish",
"portuguese",
"english",
"dutch",
"french",
"quechua",
"guaraní",
"aimara",
"mapudungun",
],
countries: [
{
name: "Argentina",
capital: "Buenos Aires",
independence: new Date(1816, 6, 9),
},
{
name: "Bolivia",
capital: "La Paz",
independence: new Date(1825, 7, 6),
},
{
name: "Brazil",
capital: "Brasilia",
independence: new Date(1822, 8, 7),
},
{
name: "Chile",
capital: "Santiago",
independence: new Date(1818, 1, 12),
},
{
name: "Colombia",
capital: "Bogotá",
independence: new Date(1810, 6, 20),
},
{
name: "Ecuador",
capital: "Quito",
independence: new Date(1809, 7, 10),
},
{
name: "Guyana",
capital: "Georgetown",
independence: new Date(1966, 4, 26),
},
{
name: "Paraguay",
capital: "Asunción",
independence: new Date(1811, 4, 14),
},
{
name: "Peru",
capital: "Lima",
independence: new Date(1821, 6, 28),
},
{
name: "Suriname",
capital: "Paramaribo",
independence: new Date(1975, 10, 25),
},
{
name: "Uruguay",
capital: "Montevideo",
independence: new Date(1825, 7, 25),
},
{
name: "Venezuela",
capital: "Caracas",
independence: new Date(1811, 6, 5),
},
],
};

const left = JSON.parse(JSON.stringify(data), jsondiffpatch.dateReviver);

data.summary = data.summary
.replace('Brazil', 'Brasil')
.replace('also known as', 'a.k.a.');
data.languages[2] = 'inglés';
.replace("Brazil", "Brasil")
.replace("also known as", "a.k.a.");
data.languages[2] = "inglés";
data.countries.pop();
data.countries.pop();
data.countries[0].capital = 'Rawson';
const firstCountry = data.countries[0];
if (firstCountry) {
firstCountry.capital = "Rawson";
}
data.countries.push({
name: 'Antártida',
name: "Antártida",
});

// modify and move
data.countries[4].population = 42888594;
data.countries.splice(11, 0, data.countries.splice(4, 1)[0]);

data.countries.splice(2, 0, data.countries.splice(7, 1)[0]);
if (data.countries[4]) {
data.countries[4].population = 42888594;
}
data.countries.splice(11, 0, data.countries.splice(4, 1)[0] as Country);
data.countries.splice(2, 0, data.countries.splice(7, 1)[0] as Country);

// biome-ignore lint/performance/noDelete: allowed for demo purposes
delete data.surface;
data.spanishName = 'Sudamérica';
data.spanishName = "Sudamérica";
data.demographics.population += 2342;

const right = data;
Expand Down
Loading