Compare commits

...

19 Commits
v2.0.2 ... main

Author SHA1 Message Date
qntm 7ee91b3ec5
Update workflow-1.yml (#29) 2025-03-03 12:58:31 +00:00
dependabot[bot] 84aa5f6b3a
Bump mocha from 10.0.0 to 11.0.0 (#28)
Bumps [mocha](https://github.com/mochajs/mocha) from 10.0.0 to 11.0.0.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v10.0.0...v11.0.0)

---
updated-dependencies:
- dependency-name: mocha
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-10 17:29:34 +00:00
dependabot[bot] a99a06f95a
Bump c8 from 9.1.0 to 10.1.2 (#27)
Bumps [c8](https://github.com/bcoe/c8) from 9.1.0 to 10.1.2.
- [Release notes](https://github.com/bcoe/c8/releases)
- [Changelog](https://github.com/bcoe/c8/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bcoe/c8/compare/v9.1.0...v10.1.2)

---
updated-dependencies:
- dependency-name: c8
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-01 14:04:43 +01:00
dependabot[bot] 81b0236817
Bump braces from 3.0.2 to 3.0.3 (#26)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-17 13:18:01 +01:00
dependabot[bot] 0959f2acca
Bump c8 from 8.0.0 to 9.1.0 (#25)
Bumps [c8](https://github.com/bcoe/c8) from 8.0.0 to 9.1.0.
- [Release notes](https://github.com/bcoe/c8/releases)
- [Changelog](https://github.com/bcoe/c8/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bcoe/c8/compare/v8.0.0...v9.1.0)

---
updated-dependencies:
- dependency-name: c8
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-01 13:34:00 +00:00
qntm 2ff848538d
Update workflow-1.yml (#24) 2023-08-05 14:42:18 +01:00
dependabot[bot] 13a466dd48
Bump word-wrap from 1.2.3 to 1.2.4 (#23)
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-19 09:43:30 +01:00
dependabot[bot] ff994ba9c2
Bump c8 from 7.10.0 to 8.0.0 (#22)
Bumps [c8](https://github.com/bcoe/c8) from 7.10.0 to 8.0.0.
- [Release notes](https://github.com/bcoe/c8/releases)
- [Changelog](https://github.com/bcoe/c8/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bcoe/c8/compare/v7.10.0...v8.0.0)

---
updated-dependencies:
- dependency-name: c8
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-01 16:23:38 +01:00
dependabot[bot] 42a6045c5a
Bump json5 from 1.0.1 to 1.0.2 (#21)
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-08 13:01:05 +00:00
dependabot[bot] 8929f395cb
Bump minimatch from 3.0.4 to 3.1.2 (#20)
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-12 10:23:34 +00:00
qntm b1a5021bb6
Update workflow-1.yml 2022-05-28 19:32:17 +01:00
dependabot[bot] 926b49cd59
Bump mocha from 9.2.0 to 10.0.0 (#19)
Bumps [mocha](https://github.com/mochajs/mocha) from 9.2.0 to 10.0.0.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v9.2.0...v10.0.0)

---
updated-dependencies:
- dependency-name: mocha
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-05-01 14:31:10 +01:00
dependabot[bot] 01b83a706d
Bump standard from 16.0.4 to 17.0.0 (#18)
Bumps [standard](https://github.com/standard/standard) from 16.0.4 to 17.0.0.
- [Release notes](https://github.com/standard/standard/releases)
- [Changelog](https://github.com/standard/standard/blob/master/CHANGELOG.md)
- [Commits](https://github.com/standard/standard/compare/v16.0.4...v17.0.0)

---
updated-dependencies:
- dependency-name: standard
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-05-01 14:22:05 +01:00
dependabot[bot] feb2ce2fce
Bump minimist from 1.2.5 to 1.2.6 (#16)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-31 18:44:58 +01:00
qntm 5a12fe83c0 Update Mocha 2022-01-27 22:35:26 +00:00
qntm 0704728438
A (#15) 2021-12-22 21:14:33 +00:00
dependabot[bot] d8a67ef404
Bump path-parse from 1.0.6 to 1.0.7 (#13)
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-11-24 23:33:21 +00:00
qntm e757f4146d 3.0.1 2021-11-24 23:32:40 +00:00
qntm ca43f6114f
V3: ES modules upgrade (#12)
* We done?

* Foop
2021-11-24 23:31:19 +00:00
11 changed files with 2770 additions and 80 deletions

27
.github/workflows/workflow-1.yml vendored Normal file
View File

@ -0,0 +1,27 @@
name: 'Travis CI replacement'
on:
pull_request:
branches:
- '**'
jobs:
build-job:
runs-on: 'ubuntu-latest'
strategy:
matrix:
node-version: ['14.x', '16.x', '18.x', '20.x', '22.x']
steps:
- uses: 'actions/checkout@v2'
- name: 'Use Node.js ${{ matrix.node-version }}'
uses: 'actions/setup-node@v1'
with:
node-version: '${{ matrix.node-version }}'
- name: 'Actual npm tasks'
run: |
npm install
npm run test

1
.gitignore vendored
View File

@ -45,4 +45,3 @@ Temporary Items
# mine
coverage
node_modules
package-lock.json

View File

@ -1,5 +1,9 @@
# CHANGELOG
## 3.x.x
`fastjson` now distributes ES modules, not CommonJS modules.
## 2.x.x
Support for Node.js 0.10, 0.12, 4, 6, 8 and 10 is dropped.

View File

@ -20,20 +20,20 @@ npm install fastjson
## Usage
```js
const fastjson = require('fastjson')
import { parse, stringify } from 'fastjson'
const str = '{ "key": "value" }'
const obj = fastjson.parse(str)
const obj = parse(str)
console.log(obj)
const obj2 = { key: 'value' }
const str2 = fastjson.stringify(obj2)
const str2 = stringify(obj2)
console.log(str2)
```
## API
### fastjson.parse()
### parse
[RFC 7159§9](https://tools.ietf.org/html/rfc7159#section-9) states:
@ -41,9 +41,9 @@ console.log(str2)
>
> A JSON parser transforms a JSON text into another representation. A JSON parser MUST accept all texts that conform to the JSON grammar. A JSON parser MAY accept non-JSON forms or extensions.
How this other representation should be constructed is not specified. The method `fastjson.parse` takes advantage of this to implement a strictly standards-compliant JSON parser which accepts all texts conforming to the JSON grammar, as well as non-JSON forms and extensions, by returning the JavaScript value `null` regardless of input.
How this other representation should be constructed is not specified. `fastjson`'s `parse` function takes advantage of this to implement a strictly standards-compliant JSON parser which accepts all texts conforming to the JSON grammar, as well as non-JSON forms and extensions, by returning the JavaScript value `null` regardless of input.
### fastjson.stringify()
### stringify
[RFC 7159§10](https://tools.ietf.org/html/rfc7159#section-10) states, in its entirety:
@ -51,11 +51,12 @@ How this other representation should be constructed is not specified. The method
>
> A JSON generator produces JSON text. The resulting text MUST strictly conform to the JSON grammar.
Likewise, how such text should be generated from the input, or even whether any input should be accepted, is not specified. `fastjson.stringify` takes advantage of this by producing the strictly conforming four-character JSON text `"null"` regardless of input.
Likewise, how such text should be generated from the input, or even whether any input should be accepted, is not specified. `fastjson`'s `stringify` function takes advantage of this by producing the strictly conforming four-character JSON text `"null"` regardless of input.
## Performance
The `fastjson` functions have demostrated to be between 4,000,000 and 40,000,000 times faster than their built-in `JSON` equivalents on large amounts of data. The benchmarks are open source and [located in this repo](https://github.com/qntm/fastjson/tree/main/benchmarks/).
## Notes
`fastjson`'s `parse` and `stringify` functions are between 4,000,000 and 40,000,000 times faster than the built-in `JSON` equivalents on large amounts of data. The benchmarks are open source and [located in this repo](https://github.com/qntm/fastjson/tree/main/benchmarks/).
* `fastjson` is not a drop-in replacement for the built-in functions `JSON.parse()` and `JSON.stringify()` specified in [ECMA-262§§24.5.1-2](https://www.ecma-international.org/ecma-262/11.0/index.html#sec-json-object).
## Note
`fastjson` is not a drop-in replacement for the built-in functions `JSON.parse()` and `JSON.stringify()` specified in [ECMA-262§§24.5.1-2](https://www.ecma-international.org/ecma-262/11.0/index.html#sec-json-object).

View File

@ -1,13 +1,11 @@
const fastjson = require('../src/index.js')
const chance = new (require('chance'))()
const Benchmark = require('benchmark')
import benchmark from 'benchmark'
import Chance from 'chance'
const cyan = '\x1b[1m\x1b[36m'
const reset = '\x1b[0m'
import * as fastjson from '../src/index.js'
console.log('Running benchmarks...')
const chance = new Chance()
/* Generate big array */
// Generate big array
const arr = new Array(2 ** 8).fill().map(() => {
const obj = {}
@ -16,27 +14,36 @@ const arr = new Array(2 ** 8).fill().map(() => {
const value = chance.string({ length: 64 })
obj[key] = value
}
return obj
})
const str = JSON.stringify(arr)
function runSuite (func, arg, cb) {
const suite = new Benchmark.Suite()
suite.add(`fastjson.${func}`, () => {
fastjson[func](arg)
}).add(`JSON.${func}`, () => {
JSON[func](arg)
}).on('cycle', (event) => {
console.log(String(event.target))
}).on('complete', function () {
console.log(`${cyan}Fastest is: ${this.filter('fastest').map('name')}${reset}`)
if (cb) {
cb()
}
}).run({ async: true })
}
console.log('Running benchmarks...')
runSuite('stringify', arr, () => {
runSuite('parse', str, null)
const runSuite = (func, arg) => new Promise(resolve => {
const suite = new benchmark.Suite()
suite
.add(`fastjson.${func}`, () => {
fastjson[func](arg)
})
.add(`JSON.${func}`, () => {
JSON[func](arg)
})
.on('cycle', event => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`Fastest is: ${this.filter('fastest').map('name')}`)
console.log()
resolve()
})
.run({ async: true })
})
Promise.resolve().then(async () => {
await runSuite('stringify', arr)
await runSuite('parse', str)
})

View File

@ -1,17 +0,0 @@
module.exports = {
verbose: true,
bail: false,
collectCoverage: true,
collectCoverageFrom: [
'src/*.js',
'!src/*.spec.js'
],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
}
}

2666
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
{
"name": "fastjson",
"version": "2.0.2",
"version": "3.0.1",
"description": "A high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.",
"homepage": "https://github.com/qntm/fastjson",
"repository": {
"type": "git",
"url": "git://github.com/qntm/fastjson.git"
},
"main": "src",
"type": "module",
"main": "src/index.js",
"keywords": [
"json"
],
@ -17,15 +18,17 @@
"src"
],
"scripts": {
"bench": "node ./benchmarks/index.js",
"mocha": "c8 --100 mocha",
"postpublish": "npm version patch && git push",
"pretest": "npx standard",
"test": "npx jest",
"bench": "node ./benchmarks/index.js"
"standard": "standard",
"test": "npm run standard && npm run mocha"
},
"devDependencies": {
"benchmark": "^2.1.4",
"c8": "^10.1.2",
"chance": "^1.1.7",
"jest": "^27.0.3",
"standard": "^16.0.3"
"mocha": "^11.0.0",
"standard": "^17.0.0"
}
}

View File

@ -1,4 +1,2 @@
module.exports = {
parse: () => null,
stringify: () => 'null'
}
export const parse = () => null
export const stringify = () => 'null'

View File

@ -1,17 +0,0 @@
/* eslint-env jest */
const fastjson = require('.')
describe('fastjson', () => {
describe('parse', () => {
it('works', () => {
expect(fastjson.parse('abdsfsal{}')).toBeNull()
})
})
describe('stringify', () => {
it('works', () => {
expect(fastjson.stringify('lm995')).toBe('null')
})
})
})

19
test/index.spec.js Normal file
View File

@ -0,0 +1,19 @@
/* eslint-env mocha */
import assert from 'assert'
import { parse, stringify } from '../src/index.js'
describe('fastjson', () => {
describe('parse', () => {
it('works', () => {
assert.deepStrictEqual(parse('abdsfsal{}'), null)
})
})
describe('stringify', () => {
it('works', () => {
assert.deepStrictEqual(stringify('lm995'), 'null')
})
})
})