Compare commits

..

28 Commits
v2.0.0 ... 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
qntm b6450a80a9
Delete .travis.yml 2021-08-31 22:09:08 +01:00
qntm c9ccb9d6b7
Update dependabot.yml 2021-08-31 22:02:49 +01:00
dependabot[bot] af388a2673
Bump jest from 26.6.3 to 27.0.3 (#11)
Bumps [jest](https://github.com/facebook/jest) from 26.6.3 to 27.0.3.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/compare/v26.6.3...v27.0.3)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-31 10:59:35 +01:00
qntm 44ed7de089
Create LICENSE.txt 2021-05-17 20:03:51 +01:00
qntm d743846a53 2.0.2 2021-05-05 19:34:03 +01:00
Álvaro Torralba 694f0f5211
Add benchmarks (#10)
* Add benchmarks

* Fix typo

* Made requested changes.

* Removed package-lock.json
* Added npm run script for benchmarks
* Fixed issues detected by Standard JS
* Deleted duplicated file
2021-05-05 19:33:31 +01:00
qntm 6578b5ebb4
Update README.md 2021-01-11 21:22:54 +00:00
qntm 9358c3c17c
Update README.md 2021-01-11 21:21:43 +00:00
qntm fa33744093 2.0.1 2021-01-03 03:15:14 +00:00
13 changed files with 2826 additions and 69 deletions

View File

@ -1,6 +1,11 @@
version: 2 version: 2
updates: updates:
- package-ecosystem: "npm" - package-ecosystem: 'npm'
directory: "/" directory: '/'
schedule: schedule:
interval: "weekly" interval: 'monthly'
ignore:
- dependency-name: '*'
update-types:
- 'version-update:semver-minor'
- 'version-update:semver-patch'

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

View File

@ -1,4 +0,0 @@
language: node_js
node_js:
- 12
- 14

View File

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

21
LICENSE.txt Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 qntm
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.

View File

@ -20,43 +20,43 @@ npm install fastjson
## Usage ## Usage
```js ```js
var fastjson = require('fastjson'); import { parse, stringify } from 'fastjson'
var str = '{"key":"value"}'; const str = '{ "key": "value" }'
var obj = fastjson.parse(str); const obj = parse(str)
console.log(obj); console.log(obj)
var obj2 = {key: 'value'}; const obj2 = { key: 'value' }
var str2 = fastjson.stringify(obj2); const str2 = stringify(obj2)
console.log(str2); console.log(str2)
``` ```
## API ## API
### fastjson.parse() ### parse
[RFC 7159§9](https://tools.ietf.org/html/rfc7159#section-9) states: [RFC 7159§9](https://tools.ietf.org/html/rfc7159#section-9) states:
> `9.` Parsers > 9. Parsers
> >
> 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. > 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: [RFC 7159§10](https://tools.ietf.org/html/rfc7159#section-10) states, in its entirety:
> `10.` Generators > 10. Generators
>
> A JSON generator produces JSON text. The resulting text MUST strictly conform to the JSON grammar. > 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.
## Notes ## Performance
* `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). `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/).
## Licence ## Note
MIT `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).

49
benchmarks/index.js Normal file
View File

@ -0,0 +1,49 @@
import benchmark from 'benchmark'
import Chance from 'chance'
import * as fastjson from '../src/index.js'
const chance = new Chance()
// Generate big array
const arr = new Array(2 ** 8).fill().map(() => {
const obj = {}
for (let i = 0; i < 2 ** 8; i++) {
const key = chance.string({ length: 16 })
const value = chance.string({ length: 64 })
obj[key] = value
}
return obj
})
const str = JSON.stringify(arr)
console.log('Running benchmarks...')
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", "name": "fastjson",
"version": "2.0.0", "version": "3.0.1",
"description": "A high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.", "description": "A high-performance, standards-compliant JSON serialiser/deserialiser for JavaScript.",
"homepage": "https://github.com/qntm/fastjson", "homepage": "https://github.com/qntm/fastjson",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/qntm/fastjson.git" "url": "git://github.com/qntm/fastjson.git"
}, },
"main": "src", "type": "module",
"main": "src/index.js",
"keywords": [ "keywords": [
"json" "json"
], ],
@ -17,12 +18,17 @@
"src" "src"
], ],
"scripts": { "scripts": {
"bench": "node ./benchmarks/index.js",
"mocha": "c8 --100 mocha",
"postpublish": "npm version patch && git push", "postpublish": "npm version patch && git push",
"pretest": "npx standard", "standard": "standard",
"test": "npx jest" "test": "npm run standard && npm run mocha"
}, },
"devDependencies": { "devDependencies": {
"jest": "^26.6.3", "benchmark": "^2.1.4",
"standard": "^16.0.3" "c8": "^10.1.2",
"chance": "^1.1.7",
"mocha": "^11.0.0",
"standard": "^17.0.0"
} }
} }

View File

@ -1,4 +1,2 @@
module.exports = { export const parse = () => null
parse: () => null, export const stringify = () => 'null'
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')
})
})
})