-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
23,141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ deserializers | |
elisp | ||
estree | ||
exonum | ||
flatpack | ||
gimu | ||
globby | ||
globstar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"config" | ||
], | ||
"author": "Jason Dent <[email protected]>", | ||
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-config#readme", | ||
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-config-lib#readme", | ||
"license": "MIT", | ||
"type": "module", | ||
"sideEffects": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
import { findMatchingFileTypes } from '@cspell/filetypes'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { fromJSON, toJSON } from './index.ts'; | ||
|
||
const urlFileList = new URL('../fixtures/fileList.txt', import.meta.url); | ||
|
||
describe('dehydrate', async () => { | ||
test.each` | ||
data | ||
${undefined} | ||
${'string'} | ||
${1} | ||
${1.1} | ||
${null} | ||
${true} | ||
${false} | ||
${[]} | ||
${[1, 2]} | ||
${['a', 'b', 'a', 'b']} | ||
${{}} | ||
${{ a: 1 }} | ||
${{ a: { b: 1 } }} | ||
${{ a: { a: 'a', b: 42 } }} | ||
${{ a: [1] }} | ||
`('dehydrate/hydrate $data', ({ data }) => { | ||
const v = toJSON(data); | ||
expect(fromJSON(v)).toEqual(data); | ||
}); | ||
|
||
const biMaxSafe = BigInt(Number.MAX_SAFE_INTEGER); | ||
|
||
test.each` | ||
data | options | ||
${undefined} | ${undefined} | ||
${'string'} | ${undefined} | ||
${1} | ${undefined} | ||
${1.1} | ${undefined} | ||
${null} | ${undefined} | ||
${true} | ${undefined} | ||
${false} | ${undefined} | ||
${[]} | ${undefined} | ||
${[1, 2]} | ${undefined} | ||
${['apple', 'banana', 'apple', 'banana', 'apple', 'pineapple']} | ${undefined} | ||
${new Set(['apple', 'banana', 'pineapple'])} | ${undefined} | ||
${new Map([['apple', 1], ['banana', 2], ['pineapple', 3]])} | ${undefined} | ||
${{}} | ${undefined} | ||
${[{}, {}, {}]} | ${undefined} | ||
${{ a: 1 }} | ${undefined} | ||
${{ a: { b: 1 } }} | ${undefined} | ||
${{ a: { a: 'a', b: 42 } }} | ${undefined} | ||
${{ a: [1] }} | ${undefined} | ||
${{ values: ['apple', 'banana', 'pineapple'], set: new Set(['apple', 'banana', 'pineapple']) }} | ${undefined} | ||
${[{ a: 'a', b: 'b' }, { a: 'c', b: 'd' }, { b: 'b', a: 'a' }, ['a', 'b'], ['c', 'd']]} | ${undefined} | ||
${[{ a: 'a', b: 'b' }, { a: 'a', b: 'b' }, { a: 'a', b: 'b' }, { a: 'a', b: 'b' }]} | ${{ dedupe: false }} | ||
${sampleNestedData()} | ${undefined} | ||
${sampleRepeatedStrings()} | ${undefined} | ||
${/[\p{L}\p{M}]+/gu} | ${undefined} | ||
${[/[\p{L}\p{M}]+/gu, /[\p{L}\p{M}]+/gu, /[\p{Lu}\p{M}]+/gu]} | ${undefined} | ||
${[new Date('2024-01-01'), new Date('2024-01-01'), new Date('2024-01-02')]} | ${undefined} | ||
${[1n, 2n, 1n, 2n, biMaxSafe, -biMaxSafe, biMaxSafe + 1n, -biMaxSafe - 1n]} | ${undefined} | ||
${[Object(1n), Object('hello'), Object(/\w+/g), Object(null), Object([]), Object('hello')]} | ${undefined} | ||
`('dehydrate $data $options', ({ data, options }) => { | ||
const v = toJSON(data, { dedupe: options?.dedupe }); | ||
expect(v).toMatchSnapshot(); | ||
expect(fromJSON(v)).toEqual(data); | ||
expect(fromJSON(JSON.parse(JSON.stringify(v)))).toEqual(data); | ||
}); | ||
|
||
test.each` | ||
name | data | options | ||
${'fileList'} | ${await sampleFileList()} | ${undefined} | ||
${'fileObjects'} | ${await sampleFileListObjects()} | ${undefined} | ||
`('dehydrate $data $options', ({ name, data, options }) => { | ||
const v = toJSON(data, { dedupe: options?.dedupe }); | ||
expect(v).toMatchFileSnapshot(`__snapshots__/${name}.jsonc`); | ||
expect(JSON.stringify(v) + '\n').toMatchFileSnapshot(`__snapshots__/${name}.json`); | ||
expect(JSON.stringify(data) + '\n').toMatchFileSnapshot(`__snapshots__/${name}.data.json`); | ||
expect(fromJSON(v)).toEqual(data); | ||
}); | ||
|
||
test("make sure dedupe doesn't break Sets", () => { | ||
const data = sampleNestedData(); | ||
const value = { ...data, s: new Set(data.n) }; | ||
|
||
const v = toJSON(value, { dedupe: true }); | ||
const hv = fromJSON(v) as typeof value; | ||
expect(hv.s).toEqual(value.s); | ||
expect(hv.n).toEqual(value.n); | ||
}); | ||
|
||
test("make sure dedupe doesn't break Maps", () => { | ||
const data = sampleNestedData(); | ||
const value = { ...data, m: new Map(data.n.map((a) => [a, a])) }; | ||
|
||
const v = toJSON(value, { dedupe: true }); | ||
const hv = fromJSON(v) as typeof value; | ||
expect(hv.m).toEqual(value.m); | ||
expect(hv.n).toEqual(value.n); | ||
}); | ||
}); | ||
|
||
async function sampleFileList() { | ||
const data = await readFile(urlFileList, 'utf8'); | ||
const files = data.split('\n'); | ||
return files; | ||
} | ||
|
||
async function sampleFileListObjects() { | ||
const list = await sampleFileList(); | ||
return list.map((filename) => ({ filename, fileType: getFileType(filename) })); | ||
} | ||
|
||
function getFileType(filename: string) { | ||
const baseName = filename.split('/').slice(-1).join(''); | ||
return findMatchingFileTypes(baseName); | ||
} | ||
|
||
function sampleRepeatedStrings() { | ||
const fruit = ['apple', 'banana', 'apple', 'banana', 'apple', 'pineapple']; | ||
const sentence = 'There is a bit of fruit on the table. Some banana, apple, and pineapple.'; | ||
const joinFruit = fruit.join('-'); | ||
return { | ||
fruit, | ||
joinFruit, | ||
sentence, | ||
}; | ||
} | ||
|
||
function sampleNestedData() { | ||
const a = { a: 'a', b: 'b' }; | ||
const b = { a: 'c', b: 'd' }; | ||
const r = /[\p{L}\p{M}]+/gu; | ||
const n = [a, b, { b: 'b', a: 'a' }, ['a', 'b'], ['c', 'd'], r, { r, rr: new RegExp(r) }]; | ||
const s = new Set(n); | ||
const m = new Map([ | ||
['a', 'a'], | ||
['b', 'b'], | ||
]); | ||
return { | ||
a, | ||
b, | ||
n, | ||
nn: n, | ||
nnn: [...n], | ||
s, | ||
r, | ||
m, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { fromJSON, parse } from './dehydrate.mjs'; | ||
export { stringify, toJSON } from './storage.mjs'; | ||
export * from 'flatpack-json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
## <small>8.14.2 (2024-08-20)</small> | ||
|
||
* chore: Update Integration Test Performance Data (#6126) ([012c897](https://github.com/streetsidesoftware/cspell/commit/012c897)), closes [#6126](https://github.com/streetsidesoftware/cspell/issues/6126) | ||
|
||
## <small>8.14.1 (2024-08-17)</small> | ||
|
||
* fix: Fix publishing ([8a56148](https://github.com/streetsidesoftware/cspell/commit/8a56148)) | ||
|
||
## 8.14.0 (2024-08-17) | ||
|
||
* chore: Update Integration Test Performance Data (#6113) ([c3eb155](https://github.com/streetsidesoftware/cspell/commit/c3eb155)), closes [#6113](https://github.com/streetsidesoftware/cspell/issues/6113) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Jason Dent | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Flatpack JSON | ||
|
||
A library to reduce the size of JSON data by flattening and normalizing the values. | ||
|
||
It is similar to [flatted](https://www.npmjs.com/package/flatted). | ||
|
||
## Install | ||
|
||
```sh | ||
npm install -S flatpack-json | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { parse, stringify } from 'flatpack-json'; | ||
``` |
Oops, something went wrong.