Skip to content

Commit 483de4e

Browse files
authored
Merge pull request #18 from aminya/hasNoSlashOrEvenNumberOfSlashes-
2 parents 9a009c0 + 30a6a54 commit 483de4e

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed

Readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Minify JSON files **blazing fast**! Supports Comments. Written in D.
44

5-
60 times faster than jsonminify!
5+
360 times faster than jsonminify!
66

77
[![CI](https://github.com/aminya/minijson/actions/workflows/CI.yml/badge.svg)](https://github.com/aminya/minijson/actions/workflows/CI.yml)
88

@@ -88,9 +88,11 @@ minifyFiles(["file1.json", "file2.json"], true);
8888

8989
### Benchmarks
9090

91+
On AMD Ryzen 7 4800H:
92+
9193
```
9294
❯ node .\benchmark\native-benchmark.mjs
93-
0.977 seconds
95+
0.163 seconds
9496
9597
❯ node .\benchmark\js-benchmark.mjs
9698
58.818 seconds

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@types/node": "16.0.0",
3838
"eslint-config-atomic": "^1.16.1",
3939
"jasmine": "^3.8.0",
40+
"jasmine-spec-reporter": "^7.0.0",
4041
"jsonminify": "^0.4.1",
4142
"mjs-dirname": "^1.0.0",
4243
"parcel": "^2.0.0-beta.3.1",

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/native/lib.d

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ string minifyString(in string jsonString, in bool hasComment = false) @trusted
4646
if (noCommentOrNotInComment)
4747
{
4848
auto leftContextSubstr = match.pre()[prevFrom .. $];
49-
if (leftContextSubstr.length != 0)
49+
const noLeftContext = leftContextSubstr.length == 0;
50+
if (!in_string && !noLeftContext)
5051
{
51-
if (!in_string)
52-
{
53-
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
54-
}
52+
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
53+
}
54+
if (!noLeftContext) {
5555
result ~= leftContextSubstr;
56+
}
5657

57-
if (matchFrontHit == "\"")
58+
if (matchFrontHit == "\"")
59+
{
60+
if (!in_string || noLeftContext || hasNoSlashOrEvenNumberOfSlashes(leftContextSubstr))
5861
{
59-
if (!in_string || hasNoSlashOrEvenNumberOfSlashes(leftContextSubstr))
60-
{
61-
// start of string with ", or unescaped " character found to end string
62-
in_string = !in_string;
63-
}
64-
--from; // include " character in next catch
65-
rightContext = jsonString[from .. $];
62+
// start of string with ", or unescaped " character found to end string
63+
in_string = !in_string;
6664
}
65+
--from; // include " character in next catch
66+
rightContext = jsonString[from .. $];
6767
}
6868
}
6969
// comments

test/helper.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function minifyFixtures(jsonFiles, hasComment) {
3939
minifiedObject = JSON.parse(minifiedString)
4040
} catch (e) {
4141
console.error(`The minified file is not valid for: ${minifiedFile}`)
42-
throw e
42+
return { minifiedString, minifiedObject: {} }
4343
}
4444
return { minifiedString, minifiedObject }
4545
})

test/index-test.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./reporter.mjs"
12
import { minifyFixtures } from "./helper.mjs"
23
import { minifyFiles, minifyString } from "../dist/lib.js"
34
import { standardFiles, withCommentFiles } from "./fixtures.mjs"
@@ -14,7 +15,9 @@ describe("minijson", () => {
1415
const fixtureNum = pathInfo.length
1516
for (let iFixture = 0; iFixture !== fixtureNum; ++iFixture) {
1617
it(pathInfo[iFixture].originalFile, () => {
17-
expect(resultInfo[iFixture].minifiedObject).toEqual(originalInfo[iFixture].originalObject)
18+
const originalObject = originalInfo[iFixture].originalObject
19+
const minifiedObject = resultInfo[iFixture].minifiedObject
20+
expect(minifiedObject).toEqual(originalObject)
1821
})
1922
}
2023

test/reporter.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { SpecReporter } from "jasmine-spec-reporter"
2+
3+
jasmine.getEnv().clearReporters() // remove default reporter logs
4+
jasmine.getEnv().addReporter(
5+
new SpecReporter({
6+
spec: {
7+
displaySuccessful: true,
8+
displayPending: true,
9+
displayFailed: true,
10+
},
11+
})
12+
)

0 commit comments

Comments
 (0)