diff --git a/l10n/index.ts b/l10n/index.ts index 2fa39eaf..9f82f62e 100644 --- a/l10n/index.ts +++ b/l10n/index.ts @@ -15,6 +15,7 @@ import faIR from './fa_IR'; import nbNO from './nb_NO'; import uaUA from './ua_UA'; import csCZ from './cs_CZ'; +import svSE from './sv_SE'; export { esES, @@ -34,4 +35,5 @@ export { nbNO, uaUA, csCZ, + svSE, }; diff --git a/l10n/sv_SE.ts b/l10n/sv_SE.ts index b37dc728..b311220f 100644 --- a/l10n/sv_SE.ts +++ b/l10n/sv_SE.ts @@ -1,22 +1,22 @@ export default { - search: { - placeholder: 'Sök...', - }, - sort: { - sortAsc: 'Sortera kolumn stigande', - sortDesc: 'Sortera kolumn fallande', - }, - pagination: { - previous: 'Föregående', - next: 'Nästa', - navigate: (page, pages) => `Sida ${page} av ${pages}`, - page: (page) => `Sida ${page}`, - showing: 'Visar', - of: 'av', - to: 'till', - results: 'resultat', - }, - loading: 'Laddar...', - noRecordsFound: 'Inga matchande poster hittades', - error: 'Ett fel uppstod vid hämtning av data', - }; + search: { + placeholder: 'Sök...', + }, + sort: { + sortAsc: 'Sortera kolumn stigande', + sortDesc: 'Sortera kolumn fallande', + }, + pagination: { + previous: 'Föregående', + next: 'Nästa', + navigate: (page, pages) => `Sida ${page} av ${pages}`, + page: (page) => `Sida ${page}`, + showing: 'Visar', + of: 'av', + to: 'till', + results: 'resultat', + }, + loading: 'Laddar...', + noRecordsFound: 'Inga matchande poster hittades', + error: 'Ett fel uppstod vid hämtning av data', +}; diff --git a/package-lock.json b/package-lock.json index ff4ea183..d0f1f26e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gridjs", - "version": "6.1.0", + "version": "6.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gridjs", - "version": "6.1.0", + "version": "6.1.1", "license": "MIT", "dependencies": { "preact": "^10.11.3" diff --git a/package.json b/package.json index 400c9506..dcffdee6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gridjs", - "version": "6.1.0", + "version": "6.1.1", "description": "Advanced table plugin", "author": "Afshin Mehrabani ", "license": "MIT", diff --git a/src/util/deepEqual.ts b/src/util/deepEqual.ts index 70a9be25..0450bbdc 100644 --- a/src/util/deepEqual.ts +++ b/src/util/deepEqual.ts @@ -4,6 +4,44 @@ * @param b right object * @returns */ -export function deepEqual(a: A, b: B) { - return JSON.stringify(a) === JSON.stringify(b); +export function deepEqual(obj1: A, obj2: B) { + // If objects are not the same type, return false + if (typeof obj1 !== typeof obj2) { + return false; + } + // If objects are both null or undefined, return true + if (obj1 === null && obj2 === null) { + return true; + } + // If objects are both primitive types, compare them directly + if (typeof obj1 !== 'object') { + // eslint-disable-next-line + // @ts-ignore + return obj1 === obj2; + } + // If objects are arrays, compare their elements recursively + if (Array.isArray(obj1) && Array.isArray(obj2)) { + if (obj1.length !== obj2.length) { + return false; + } + for (let i = 0; i < obj1.length; i++) { + if (!deepEqual(obj1[i], obj2[i])) { + return false; + } + } + return true; + } + // If objects are both objects, compare their properties recursively + const keys1 = Object.keys(obj1); + const keys2 = Object.keys(obj2); + if (keys1.length !== keys2.length) { + return false; + } + for (const key of keys1) { + // eslint-disable-next-line no-prototype-builtins + if (!obj2.hasOwnProperty(key) || !deepEqual(obj1[key], obj2[key])) { + return false; + } + } + return true; } diff --git a/tests/jest/util/deepEqual.test.ts b/tests/jest/util/deepEqual.test.ts new file mode 100644 index 00000000..960ec253 --- /dev/null +++ b/tests/jest/util/deepEqual.test.ts @@ -0,0 +1,34 @@ +import { deepEqual } from '../../../src/util/deepEqual'; + +describe('deepEqual', () => { + it('should return true when objects are the same', () => { + const result = deepEqual({ a: 42 }, { a: 42 }); + expect(result).toBeTrue(); + }); + + it('should return false when objects are not the same', () => { + const result = deepEqual({ b: 42 }, { a: 42 }); + expect(result).toBeFalse(); + }); + + it('should return true when nested objects are the same', () => { + const result = deepEqual({ a: 42, c: { a: 24 } }, { a: 42, c: { a: 24 } }); + expect(result).toBeTrue(); + }); + + it('should return false when nested objects not are the same', () => { + const result = deepEqual({ a: 42, c: { x: 24 } }, { a: 42, c: { a: 24 } }); + expect(result).toBeFalse(); + }); + + it('should return false when objects have functions', () => { + const result = deepEqual({ a: 42, c: jest.fn() }, { a: 42, c: jest.fn() }); + expect(result).toBeFalse(); + }); + + it('should return true when objects have same functions', () => { + const fn = jest.fn(); + const result = deepEqual({ a: 42, c: fn }, { a: 42, c: fn }); + expect(result).toBeTrue(); + }); +});