├── .editorconfig ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── lib ├── index.js └── util.js ├── logo.png ├── package.json ├── register.js └── test ├── fixture.json ├── index.js └── mocha.opts /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | max_line_length = 80 13 | indent_brace_style = 1TBS 14 | spaces_around_operators = true 15 | quote_type = auto 16 | 17 | [package.json] 18 | indent_style = space 19 | indent_size = 2 20 | 21 | [*.md] 22 | trim_trailing_whitespace = false 23 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | # Check for updates to GitHub Actions every weekday 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | with: 18 | token: ${{ secrets.GITHUB_TOKEN }} 19 | - name: Setup Node.js 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: lts/* 23 | - name: Install 24 | run: npm install --no-package-lock 25 | - name: Test 26 | run: npm test 27 | - name: Report 28 | run: mkdir -p coverage && npx c8 report --reporter=text-lcov > coverage/lcov.info 29 | - name: Coverage 30 | uses: coverallsapp/github-action@main 31 | with: 32 | github-token: ${{ secrets.GITHUB_TOKEN }} 33 | - name: Release 34 | if: ${{ github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'chore(release):') && !startsWith(github.event.head_commit.message, 'docs:') }} 35 | env: 36 | CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GH_TOKEN }} 37 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 38 | run: | 39 | git config --global user.email ${{ secrets.GIT_EMAIL }} 40 | git config --global user.name ${{ secrets.GIT_USERNAME }} 41 | npm run release 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ############################ 2 | # npm 3 | ############################ 4 | node_modules 5 | npm-debug.log 6 | 7 | 8 | ############################ 9 | # tmp, editor & OS files 10 | ############################ 11 | .tmp 12 | *.swo 13 | *.swp 14 | *.swn 15 | *.swm 16 | .DS_STORE 17 | *# 18 | *~ 19 | .idea 20 | nbproject 21 | .nyc_output 22 | 23 | 24 | ############################ 25 | # Tests 26 | ############################ 27 | testApp 28 | coverage 29 | 30 | 31 | ############################ 32 | # Other 33 | ############################ 34 | .node_history 35 | .envrc 36 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | unsafe-perm=true 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### 2.2.21 (2023-10-24) 6 | 7 | ### 2.2.20 (2023-09-05) 8 | 9 | ### 2.2.19 (2023-09-05) 10 | 11 | ### 2.2.18 (2022-05-17) 12 | 13 | ### 2.2.17 (2022-04-11) 14 | 15 | ### 2.2.16 (2022-04-01) 16 | 17 | ### 2.2.15 (2022-03-17) 18 | 19 | ### [2.2.14](https://github.com/kikobeats/json-future/compare/v2.2.13...v2.2.14) (2021-09-07) 20 | 21 | ### [2.2.13](https://github.com/kikobeats/json-future/compare/v2.2.12...v2.2.13) (2021-01-19) 22 | 23 | ### [2.2.12](https://github.com/kikobeats/json-future/compare/v2.2.11...v2.2.12) (2020-08-24) 24 | 25 | ### [2.2.11](https://github.com/kikobeats/json-future/compare/v2.2.10...v2.2.11) (2020-04-17) 26 | 27 | ### [2.2.10](https://github.com/kikobeats/json-future/compare/v2.2.9...v2.2.10) (2020-02-24) 28 | 29 | ### [2.2.9](https://github.com/kikobeats/json-future/compare/v2.2.8...v2.2.9) (2020-02-10) 30 | 31 | ### [2.2.8](https://github.com/kikobeats/json-future/compare/v2.2.7...v2.2.8) (2020-01-20) 32 | 33 | ### [2.2.7](https://github.com/kikobeats/json-future/compare/v2.2.6...v2.2.7) (2019-07-11) 34 | 35 | 36 | ### Build System 37 | 38 | * use fast-safe-stringify instead of json-stringify-safe ([123fd4a](https://github.com/kikobeats/json-future/commit/123fd4a)) 39 | 40 | 41 | 42 | ### [2.2.6](https://github.com/kikobeats/json-future/compare/v2.2.5...v2.2.6) (2019-07-02) 43 | 44 | 45 | ### Bug Fixes 46 | 47 | * **package:** update parse-json to version 5.0.0 ([079dcd9](https://github.com/kikobeats/json-future/commit/079dcd9)) 48 | 49 | 50 | 51 | ### [2.2.5](https://github.com/kikobeats/json-future/compare/v2.2.4...v2.2.5) (2019-06-23) 52 | 53 | 54 | ### Build System 55 | 56 | * ignore credentials ([c68132d](https://github.com/kikobeats/json-future/commit/c68132d)) 57 | * remove bot from authors ([70b21bd](https://github.com/kikobeats/json-future/commit/70b21bd)) 58 | * update scripts ([73d766f](https://github.com/kikobeats/json-future/commit/73d766f)) 59 | 60 | 61 | 62 | ### [2.2.4](https://github.com/kikobeats/json-future/compare/v2.2.3...v2.2.4) (2019-06-23) 63 | 64 | 65 | ### Bug Fixes 66 | 67 | * **package:** update async to version 3.1.0 ([e4fe67c](https://github.com/kikobeats/json-future/commit/e4fe67c)) 68 | 69 | 70 | 71 | ### [2.2.3](https://github.com/kikobeats/json-future/compare/v2.2.2...v2.2.3) (2019-06-19) 72 | 73 | 74 | ### Build System 75 | 76 | * update travis ([7bef99b](https://github.com/kikobeats/json-future/commit/7bef99b)) 77 | 78 | 79 | 80 | ### [2.2.2](https://github.com/kikobeats/json-future/compare/v2.2.1...v2.2.2) (2019-06-12) 81 | 82 | 83 | ### Bug Fixes 84 | 85 | * **package:** update load-json-file to version 6.1.0 ([4546e3f](https://github.com/kikobeats/json-future/commit/4546e3f)) 86 | 87 | 88 | 89 | ### [2.2.1](https://github.com/kikobeats/json-future/compare/v2.1.10...v2.2.1) (2019-05-27) 90 | 91 | 92 | 93 | ## 2.2.0 (2019-05-27) 94 | 95 | 96 | ### Bug Fixes 97 | 98 | * **package:** update async to version 3.0.1 ([f0975ef](https://github.com/kikobeats/json-future/commit/f0975ef)) 99 | 100 | 101 | ### Build System 102 | 103 | * update release message ([78facef](https://github.com/kikobeats/json-future/commit/78facef)) 104 | 105 | 106 | 107 | 108 | # 2.2.0 (2019-05-27) 109 | 110 | * build: update release message ([78facef](https://github.com/kikobeats/json-future/commit/78facef)) 111 | * fix(package): update async to version 3.0.1 ([f0975ef](https://github.com/kikobeats/json-future/commit/f0975ef)) 112 | 113 | 114 | 115 | # Changelog 116 | 117 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 118 | 119 | ### [2.1.10](https://github.com/kikobeats/json-future/compare/v2.1.9...v2.1.10) (2019-05-25) 120 | 121 | 122 | ### Bug Fixes 123 | 124 | * **package:** update write-json-file to version 4.1.0 ([d845721](https://github.com/kikobeats/json-future/commit/d845721)) 125 | 126 | 127 | 128 | ### [2.1.9](https://github.com/kikobeats/json-future/compare/v2.1.8...v2.1.9) (2019-05-21) 129 | 130 | 131 | ### Bug Fixes 132 | 133 | * **package:** update write-json-file to version 4.0.0 ([61f2dac](https://github.com/kikobeats/json-future/commit/61f2dac)) 134 | 135 | 136 | 137 | ### [2.1.8](https://github.com/kikobeats/json-future/compare/v2.1.7...v2.1.8) (2019-05-20) 138 | 139 | 140 | ### Build System 141 | 142 | * change git-authors-cli position ([52f496c](https://github.com/kikobeats/json-future/commit/52f496c)) 143 | 144 | 145 | 146 | ## [2.1.7](https://github.com/kikobeats/json-future/compare/v2.1.6...v2.1.7) (2019-04-27) 147 | 148 | 149 | ### Bug Fixes 150 | 151 | * **package:** update load-json-file to version 6.0.0 ([605106d](https://github.com/kikobeats/json-future/commit/605106d)) 152 | 153 | 154 | 155 | ## [2.1.6](https://github.com/kikobeats/json-future/compare/v2.1.5...v2.1.6) (2019-04-18) 156 | 157 | 158 | 159 | 160 | ## [2.1.5](https://github.com/kikobeats/json-future/compare/v2.1.4...v2.1.5) (2019-04-06) 161 | 162 | 163 | ### Bug Fixes 164 | 165 | * **package:** update load-json-file to version 5.3.0 ([3388654](https://github.com/kikobeats/json-future/commit/3388654)) 166 | * **package:** update write-json-file to version 3.2.0 ([1a0c1e5](https://github.com/kikobeats/json-future/commit/1a0c1e5)) 167 | 168 | 169 | 170 | 171 | ## 2.1.4 (2019-02-12) 172 | 173 | 174 | ### Bug Fixes 175 | 176 | * **package:** update load-json-file to version 5.1.0 ([6845f01](https://github.com/kikobeats/json-future/commit/6845f01)) 177 | * **package:** update load-json-file to version 5.2.0 ([100c8c0](https://github.com/kikobeats/json-future/commit/100c8c0)) 178 | * **package:** update write-json-file to version 3.1.0 ([08918b8](https://github.com/kikobeats/json-future/commit/08918b8)) 179 | 180 | 181 | 182 | 183 | ## 2.1.3 (2018-08-28) 184 | 185 | 186 | ### Bug Fixes 187 | 188 | * **package:** update async to version 2.6.0 ([7c91d50](https://github.com/kikobeats/json-future/commit/7c91d50)) 189 | * **package:** update load-json-file to version 3.0.0 ([11ae47c](https://github.com/kikobeats/json-future/commit/11ae47c)) 190 | * **package:** update load-json-file to version 4.0.0 ([0009698](https://github.com/kikobeats/json-future/commit/0009698)) 191 | * **package:** update load-json-file to version 5.0.0 ([0784a5e](https://github.com/kikobeats/json-future/commit/0784a5e)) 192 | * **package:** update parse-json to version 3.0.0 ([f8eccf7](https://github.com/kikobeats/json-future/commit/f8eccf7)) 193 | * **package:** update parse-json to version 4.0.0 ([42f4eaf](https://github.com/kikobeats/json-future/commit/42f4eaf)) 194 | * **package:** update write-json-file to version 2.3.0 ([62740b7](https://github.com/kikobeats/json-future/commit/62740b7)) 195 | * **package:** update write-json-file to version 3.0.0 ([fee0e51](https://github.com/kikobeats/json-future/commit/fee0e51)) 196 | 197 | 198 | 199 | 200 | ## 2.1.2 (2017-07-19) 201 | 202 | 203 | 204 | 205 | ## 2.1.1 (2017-07-18) 206 | 207 | 208 | 209 | 210 | # 2.1.0 (2017-04-16) 211 | 212 | 213 | 214 | 215 | ## 2.0.1 (2016-07-18) 216 | 217 | 218 | 219 | 220 | # 2.0.0 (2016-06-19) 221 | 222 | 223 | 224 | 225 | ## 1.1.5 (2016-01-29) 226 | 227 | 228 | 229 | 230 | ## 2.1.3 (2018-08-28) 231 | 232 | * fix(package): update async to version 2.6.0 ([7c91d50](https://github.com/kikobeats/json-future/commit/7c91d50)) 233 | * fix(package): update load-json-file to version 3.0.0 ([11ae47c](https://github.com/kikobeats/json-future/commit/11ae47c)) 234 | * fix(package): update load-json-file to version 4.0.0 ([0009698](https://github.com/kikobeats/json-future/commit/0009698)) 235 | * fix(package): update load-json-file to version 5.0.0 ([0784a5e](https://github.com/kikobeats/json-future/commit/0784a5e)) 236 | * fix(package): update parse-json to version 3.0.0 ([f8eccf7](https://github.com/kikobeats/json-future/commit/f8eccf7)) 237 | * fix(package): update parse-json to version 4.0.0 ([42f4eaf](https://github.com/kikobeats/json-future/commit/42f4eaf)) 238 | * fix(package): update write-json-file to version 2.3.0 ([62740b7](https://github.com/kikobeats/json-future/commit/62740b7)) 239 | * fix(package): update write-json-file to version 3.0.0 ([fee0e51](https://github.com/kikobeats/json-future/commit/fee0e51)) 240 | * Update package.json ([73a7049](https://github.com/kikobeats/json-future/commit/73a7049)) 241 | * Update README.md ([c8fa6af](https://github.com/kikobeats/json-future/commit/c8fa6af)) 242 | * docs(readme): add Greenkeeper badge ([9937a6e](https://github.com/kikobeats/json-future/commit/9937a6e)) 243 | 244 | 245 | 246 | 247 | ## 2.1.2 (2017-07-19) 248 | 249 | * Update homepage ([c61f5c2](https://github.com/kikobeats/json-future/commit/c61f5c2)) 250 | 251 | 252 | 253 | 254 | ## 2.1.1 (2017-07-18) 255 | 256 | * Update compositor.json ([9ed5947](https://github.com/kikobeats/json-future/commit/9ed5947)) 257 | * Update README.md ([8d53cd6](https://github.com/kikobeats/json-future/commit/8d53cd6)) 258 | * docs(readme): add Greenkeeper badge ([18107e9](https://github.com/kikobeats/json-future/commit/18107e9)) 259 | * chore(package): update dependencies ([def90ac](https://github.com/kikobeats/json-future/commit/def90ac)) 260 | 261 | 262 | 263 | 264 | # 2.1.0 (2017-04-16) 265 | 266 | * Fix tests ([1b4717c](https://github.com/kikobeats/json-future/commit/1b4717c)) 267 | * Refactor ([48abbad](https://github.com/kikobeats/json-future/commit/48abbad)) 268 | * Refactor tests ([25797b0](https://github.com/kikobeats/json-future/commit/25797b0)) 269 | * Remove unnecessary ([4449377](https://github.com/kikobeats/json-future/commit/4449377)) 270 | * Remove unnnecessary ([840d14a](https://github.com/kikobeats/json-future/commit/840d14a)) 271 | * Update compositor.json ([7b27b0e](https://github.com/kikobeats/json-future/commit/7b27b0e)) 272 | * Update compositor.json ([430b25a](https://github.com/kikobeats/json-future/commit/430b25a)) 273 | * Update docs ([dca7f5c](https://github.com/kikobeats/json-future/commit/dca7f5c)) 274 | * Update logo ([cd78ded](https://github.com/kikobeats/json-future/commit/cd78ded)) 275 | * Update README.md ([f5b6ba2](https://github.com/kikobeats/json-future/commit/f5b6ba2)) 276 | * Update README.md ([ff95bf3](https://github.com/kikobeats/json-future/commit/ff95bf3)) 277 | * Update README.md ([c3c4c3a](https://github.com/kikobeats/json-future/commit/c3c4c3a)) 278 | * Update travis builds ([c8848e4](https://github.com/kikobeats/json-future/commit/c8848e4)) 279 | * chore(package): update async to version 2.1.1 ([b33d83f](https://github.com/kikobeats/json-future/commit/b33d83f)) 280 | 281 | 282 | 283 | 284 | ## 2.0.1 (2016-07-18) 285 | 286 | * Add sliced dep ([e4c3279](https://github.com/kikobeats/json-future/commit/e4c3279)) 287 | * Avoid transpiling ([45b2ce9](https://github.com/kikobeats/json-future/commit/45b2ce9)) 288 | * Extract common ([9553254](https://github.com/kikobeats/json-future/commit/9553254)) 289 | * Refactor export ([b85fd09](https://github.com/kikobeats/json-future/commit/b85fd09)) 290 | * Tweaks ([20e5517](https://github.com/kikobeats/json-future/commit/20e5517)) 291 | 292 | 293 | 294 | 295 | # 2.0.0 (2016-06-19) 296 | 297 | * Drop bower ([89c5f09](https://github.com/kikobeats/json-future/commit/89c5f09)) 298 | * Refactor scaffold ([94d00fc](https://github.com/kikobeats/json-future/commit/94d00fc)) 299 | * Release 1.1.6 ([0cbbd6e](https://github.com/kikobeats/json-future/commit/0cbbd6e)) 300 | * Update deps ([5edf2de](https://github.com/kikobeats/json-future/commit/5edf2de)) 301 | 302 | 303 | 304 | 305 | ## 1.1.6 (2016-06-19) 306 | 307 | * Drop bower ([89c5f09](https://github.com/kikobeats/json-future/commit/89c5f09)) 308 | * Refactor scaffold ([94d00fc](https://github.com/kikobeats/json-future/commit/94d00fc)) 309 | * Update deps ([5edf2de](https://github.com/kikobeats/json-future/commit/5edf2de)) 310 | 311 | 312 | 313 | 314 | ## 1.1.5 (2016-01-29) 315 | 316 | 317 | * No more fake async ([15a785b](https://github.com/kikobeats/json-future/commit/15a785b)) 318 | * Update variable name ([267e3dc](https://github.com/kikobeats/json-future/commit/267e3dc)) 319 | 320 | 321 | 322 | 323 | ## 1.1.4 (2016-01-29) 324 | 325 | 326 | * Fix dependencies ([b102590](https://github.com/kikobeats/json-future/commit/b102590)) 327 | * Release 1.1.4 ([e7c3531](https://github.com/kikobeats/json-future/commit/e7c3531)) 328 | 329 | 330 | 331 | 332 | ## 1.1.3 (2016-01-28) 333 | 334 | 335 | * Little refactor ([799bdeb](https://github.com/kikobeats/json-future/commit/799bdeb)) 336 | * Release 1.1.3 ([2b5333f](https://github.com/kikobeats/json-future/commit/2b5333f)) 337 | * add clean script ([2be34e7](https://github.com/kikobeats/json-future/commit/2be34e7)) 338 | * update scripts ([b9fe0b9](https://github.com/kikobeats/json-future/commit/b9fe0b9)) 339 | 340 | 341 | 342 | 343 | ## 1.1.2 (2015-11-20) 344 | 345 | 346 | * 1.1.2 releases ([16deefd](https://github.com/kikobeats/json-future/commit/16deefd)) 347 | * Update README.md ([90804f8](https://github.com/kikobeats/json-future/commit/90804f8)) 348 | * deleted unnecessary dependency ([d31cb6f](https://github.com/kikobeats/json-future/commit/d31cb6f)) 349 | * updated bumped config ([c689e24](https://github.com/kikobeats/json-future/commit/c689e24)) 350 | * updated travis builds ([24116c9](https://github.com/kikobeats/json-future/commit/24116c9)) 351 | 352 | 353 | 354 | 355 | ## 1.1.1 (2015-10-27) 356 | 357 | 358 | * 1.1.1 releases ([ea52a83](https://github.com/kikobeats/json-future/commit/ea52a83)) 359 | * Update README.md ([b9df73a](https://github.com/kikobeats/json-future/commit/b9df73a)) 360 | * fixed ensureAsync ([19f50c7](https://github.com/kikobeats/json-future/commit/19f50c7)) 361 | 362 | 363 | 364 | 365 | # 1.1.0 (2015-10-25) 366 | 367 | 368 | * 1.1.0 releases ([ff27976](https://github.com/kikobeats/json-future/commit/ff27976)) 369 | * Added /register file ([9892186](https://github.com/kikobeats/json-future/commit/9892186)) 370 | * unnecessary function level ([2ea52e8](https://github.com/kikobeats/json-future/commit/2ea52e8)) 371 | * updated documentation ([d8fe4b4](https://github.com/kikobeats/json-future/commit/d8fe4b4)) 372 | 373 | 374 | 375 | 376 | ## 1.0.3 (2015-10-24) 377 | 378 | 379 | * 1.0.3 releases ([7efa9db](https://github.com/kikobeats/json-future/commit/7efa9db)) 380 | * parse coffee globally for generate browser version ([c66c93f](https://github.com/kikobeats/json-future/commit/c66c93f)) 381 | * unified async and sync error codes ([525b461](https://github.com/kikobeats/json-future/commit/525b461)) 382 | 383 | 384 | 385 | 386 | ## 1.0.2 (2015-10-20) 387 | 388 | 389 | * 1.0.2 releases ([f397285](https://github.com/kikobeats/json-future/commit/f397285)) 390 | * Added .parseAsync Buffer test ([f0e17b8](https://github.com/kikobeats/json-future/commit/f0e17b8)) 391 | 392 | 393 | 394 | 395 | ## 1.0.1 (2015-10-20) 396 | 397 | 398 | * 1.0.1 releases ([857636d](https://github.com/kikobeats/json-future/commit/857636d)) 399 | * added .parseAsync Buffer support ([0f8963b](https://github.com/kikobeats/json-future/commit/0f8963b)) 400 | 401 | 402 | 403 | 404 | # 1.0.0 (2015-10-16) 405 | 406 | 407 | * 1.0.0 releases ([06be5d4](https://github.com/kikobeats/json-future/commit/06be5d4)) 408 | * Update README.md ([9c721af](https://github.com/kikobeats/json-future/commit/9c721af)) 409 | * Update README.md ([e96e618](https://github.com/kikobeats/json-future/commit/e96e618)) 410 | * Update README.md ([3c94a66](https://github.com/kikobeats/json-future/commit/3c94a66)) 411 | * added documentation and bump config ([ed6f083](https://github.com/kikobeats/json-future/commit/ed6f083)) 412 | * added missing dependency ([77ad193](https://github.com/kikobeats/json-future/commit/77ad193)) 413 | * added missing dependency ([d1a4723](https://github.com/kikobeats/json-future/commit/d1a4723)) 414 | * browser version is not ready ([e09eead](https://github.com/kikobeats/json-future/commit/e09eead)) 415 | * first approach ([ceb68d9](https://github.com/kikobeats/json-future/commit/ceb68d9)) 416 | * moar keywords ([4e56040](https://github.com/kikobeats/json-future/commit/4e56040)) 417 | * rewritten ([a0078cb](https://github.com/kikobeats/json-future/commit/a0078cb)) 418 | * rewritten based in dependencies ([849698f](https://github.com/kikobeats/json-future/commit/849698f)) 419 | * updated description ([bf093e4](https://github.com/kikobeats/json-future/commit/bf093e4)) 420 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2015 Kiko Beats 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSON Future 2 | 3 |

4 | json-future 5 |
6 |
7 |

8 | 9 | ![Last version](https://img.shields.io/github/tag/Kikobeats/json-future.svg?style=flat-square) 10 | [![Build Status](http://img.shields.io/travis/Kikobeats/json-future/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/json-future) 11 | [![NPM Status](http://img.shields.io/npm/dm/json-future.svg?style=flat-square)](https://www.npmjs.org/package/json-future) 12 | 13 | > Modern JSON interface. [propositions for ECMAScript 7](https://github.com/mohsen1/async-json). 14 | 15 | ## Why 16 | 17 | * High level methods for manipulate JSON files. 18 | * Backward compatibility with JSON Object in Node/Browser. 19 | * Async support (callback/promise) based on [ECMAScript proposal](https://github.com/mohsen1/async-json). 20 | 21 | JSON Future is based into a set of cool libraries to handle JSON, but some of this libraries uses promises or callback style. This library adds an extra layer to call these libraries uniformly. 22 | 23 | ## Install 24 | 25 | ```bash 26 | npm install json-future --save 27 | ``` 28 | 29 | ## Usage 30 | 31 | ```js 32 | const jsonFuture = require('json-future') 33 | ``` 34 | 35 | Don't be afraid to replace for the default `JSON` object. The library is specially designed for be compatible and don't break your code: 36 | 37 | ```js 38 | JSON = require('json-future') 39 | ``` 40 | 41 | Also you can do this action using the `register` helper: 42 | 43 | ```js 44 | require('json-future/register') 45 | ``` 46 | 47 | ## API 48 | 49 | In `async` methods, if you don't provide a callback for node style, then the method return a `Promise`. 50 | 51 | ### .stringify(input, [replacer], [space]) 52 | ### .stringifyAsync(input, [replacer], [space], [cb]) 53 | 54 | Creates the `string` version of the input. 55 | 56 | ### .parse(input, [reviver], [filename]) 57 | ### .parseAsync(input, [reviver], [filename], [cb]) 58 | 59 | Creates the `object` version of the input. 60 | 61 | ### .load(filepath) 62 | ### .loadAsync(filepath, [cb]) 63 | 64 | Returns the parsed JSON. 65 | 66 | ### .save(filepath, data, [options]) 67 | ### .saveAsync(filepath, data, [options], [cb]) 68 | 69 | Stringify and write JSON to a file atomically. 70 | 71 | #### options 72 | 73 | ##### indent 74 | 75 | Type: `string`, `number` 76 | Default: `\t` 77 | 78 | Indentation as a string or number of spaces. 79 | Pass in `null` for no formatting. 80 | 81 | ##### sortKeys 82 | 83 | Type: `boolean`, `function` 84 | Default: `false` 85 | 86 | Sort the keys recursively. 87 | Optionally pass in a [`compare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function. 88 | 89 | ##### replacer 90 | 91 | Type: `function` 92 | 93 | Passed into [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter). 94 | 95 | ##### mode 96 | 97 | Type: `number` 98 | Default `438` *(0666 in octal)* 99 | 100 | [Mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file. 101 | 102 | ## License 103 | 104 | MIT © [Kiko Beats](http://kikobeats.com) 105 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const util = require('./util') 4 | const Args = require('args-js') 5 | const sliced = require('sliced') 6 | const nodeify = require('nodeify') 7 | const promise = require('cb2promise') 8 | 9 | const DEFAULTS_OPTS = { 10 | SAVE: { 11 | indent: ' ' 12 | }, 13 | STRINGIFY: { 14 | SPACE: 2 15 | } 16 | } 17 | 18 | function getStringifyParams (params) { 19 | return Args( 20 | [ 21 | { data: Args.OBJECT | Args.Required }, 22 | { replacer: Args.FUNCTION | Args.Optional }, 23 | { 24 | space: Args.INT | Args.Optional, 25 | _default: DEFAULTS_OPTS.STRINGIFY.SPACE 26 | } 27 | ], 28 | params 29 | ) 30 | } 31 | 32 | function stringifyAsync () { 33 | const args = sliced(arguments) 34 | const cb = typeof args[args.length - 1] === 'function' ? args.pop() : null 35 | 36 | const params = getStringifyParams(args) 37 | const data = params.data 38 | const replacer = params.replacer 39 | const space = params.space 40 | 41 | if (!cb) return promise(util.stringifyAsync, data, replacer, space) 42 | return util.stringifyAsync(data, replacer, space, cb) 43 | } 44 | 45 | function stringify () { 46 | const params = getStringifyParams(arguments) 47 | const data = params.data 48 | const replacer = params.replacer 49 | const space = params.space 50 | 51 | return util.stringify(data, replacer, space) 52 | } 53 | 54 | function parseAsync () { 55 | const args = sliced(arguments) 56 | const cb = typeof args[args.length - 1] === 'function' ? args.pop() : null 57 | 58 | const params = Args( 59 | [ 60 | { data: Args.STRING | Args.Required, _check: data => data.toString() }, 61 | { reviver: Args.FUNCTION | Args.Optional }, 62 | { filename: Args.STRING | Args.Optional } 63 | ], 64 | args 65 | ) 66 | 67 | const data = params.data 68 | const reviver = params.reviver 69 | const filename = params.filename 70 | 71 | if (!cb) return promise(util.parseAsync, data, reviver, filename) 72 | return util.parseAsync(data, reviver, filename, cb) 73 | } 74 | 75 | function loadAsync () { 76 | const params = Args( 77 | [ 78 | { filepath: Args.STRING | Args.Required }, 79 | { cb: Args.FUNCTION | Args.Optional } 80 | ], 81 | arguments 82 | ) 83 | 84 | const filepath = params.filepath 85 | const cb = params.cb 86 | 87 | if (cb) return nodeify(util.loadAsync(filepath), cb) 88 | return util.loadAsync(filepath) 89 | } 90 | 91 | function load () { 92 | const params = Args([{ filepath: Args.STRING | Args.Required }], arguments) 93 | 94 | const filepath = params.filepath 95 | 96 | return util.load(filepath) 97 | } 98 | 99 | function saveAsync () { 100 | const params = Args( 101 | [ 102 | { filepath: Args.STRING | Args.Required }, 103 | { data: Args.OBJECT | Args.Required }, 104 | { opts: Args.OBJECT | Args.Optional, _default: DEFAULTS_OPTS.SAVE }, 105 | { cb: Args.FUNCTION | Args.Optional } 106 | ], 107 | arguments 108 | ) 109 | 110 | const filepath = params.filepath 111 | const data = params.data 112 | const opts = params.opts 113 | const cb = params.cb 114 | 115 | if (cb) return nodeify(util.saveAsync(filepath, data, opts), cb) 116 | return util.saveAsync(filepath, data, opts) 117 | } 118 | 119 | function save () { 120 | const params = Args( 121 | [ 122 | { filepath: Args.STRING | Args.Required }, 123 | { data: Args.OBJECT | Args.Required }, 124 | { opts: Args.OBJECT | Args.Optional, _default: DEFAULTS_OPTS.SAVE } 125 | ], 126 | arguments 127 | ) 128 | 129 | const filepath = params.filepath 130 | const data = params.data 131 | const opts = params.opts 132 | 133 | return util.save(filepath, data, opts) 134 | } 135 | 136 | module.exports = { 137 | stringifyAsync: stringifyAsync, 138 | stringify: stringify, 139 | parseAsync: parseAsync, 140 | parse: util.parse, 141 | loadAsync: loadAsync, 142 | load: load, 143 | saveAsync: saveAsync, 144 | save: save 145 | } 146 | -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const parse = require('parse-json') 4 | const asyncify = require('async/asyncify') 5 | const loadJsonFile = require('load-json-file') 6 | const writeJsonFile = require('write-json-file') 7 | const safeStringify = require('fast-safe-stringify') 8 | 9 | module.exports = { 10 | stringify: safeStringify, 11 | stringifyAsync: asyncify(safeStringify), 12 | parse: parse, 13 | parseAsync: asyncify(parse), 14 | load: loadJsonFile.sync, 15 | loadAsync: loadJsonFile, 16 | save: writeJsonFile.sync, 17 | saveAsync: writeJsonFile 18 | } 19 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kikobeats/json-future/4030dbacfc2b88988a8e1cab989b62337feae4f5/logo.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "json-future", 3 | "description": "Unbelievable and Modern JSON interface.", 4 | "homepage": "https://nicedoc.io/kikobeats/json-future", 5 | "version": "2.2.21", 6 | "main": "lib", 7 | "author": { 8 | "email": "josefrancisco.verdu@gmail.com", 9 | "name": "Kiko Beats", 10 | "url": "https://github.com/Kikobeats" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/kikobeats/json-future.git" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/Kikobeats/json-future/issues" 18 | }, 19 | "keywords": [ 20 | "ES6", 21 | "ES7", 22 | "JSON", 23 | "async", 24 | "circular", 25 | "future", 26 | "interface", 27 | "load", 28 | "parse", 29 | "save", 30 | "stable", 31 | "stringify", 32 | "write" 33 | ], 34 | "dependencies": { 35 | "args-js": "~0.10.12", 36 | "async": "~3.2.0", 37 | "cb2promise": "~1.1.1", 38 | "fast-safe-stringify": "~2.1.0", 39 | "load-json-file": "~6.2.0", 40 | "nodeify": "~1.0.1", 41 | "parse-json": "~5.2.0", 42 | "sliced": "~1.0.1", 43 | "write-json-file": "~4.3.0" 44 | }, 45 | "devDependencies": { 46 | "@commitlint/cli": "latest", 47 | "@commitlint/config-conventional": "latest", 48 | "@ksmithut/prettier-standard": "latest", 49 | "c8": "latest", 50 | "ci-publish": "latest", 51 | "conventional-github-releaser": "latest", 52 | "finepack": "latest", 53 | "git-authors-cli": "latest", 54 | "mocha": "latest", 55 | "nano-staged": "latest", 56 | "npm-check-updates": "latest", 57 | "should": "latest", 58 | "simple-git-hooks": "latest", 59 | "standard": "latest", 60 | "standard-markdown": "latest", 61 | "standard-version": "latest" 62 | }, 63 | "engines": { 64 | "node": ">= 4" 65 | }, 66 | "files": [ 67 | "lib", 68 | "register.js" 69 | ], 70 | "scripts": { 71 | "clean": "rm -rf node_modules", 72 | "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true", 73 | "coverage": "nyc report --reporter=text-lcov | coveralls", 74 | "lint": "standard lib", 75 | "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)", 76 | "prerelease": "npm run update:check && npm run contributors", 77 | "pretest": "npm run lint", 78 | "preversion": "git-authors-cli && git add package.json", 79 | "release": "standard-version -a", 80 | "release:github": "conventional-github-releaser -p angular", 81 | "release:tags": "git push --follow-tags origin HEAD:master", 82 | "test": "c8 mocha", 83 | "update": "ncu -u", 84 | "update:check": "ncu -- --error-level 2" 85 | }, 86 | "license": "MIT", 87 | "commitlint": { 88 | "extends": [ 89 | "@commitlint/config-conventional" 90 | ] 91 | }, 92 | "nano-staged": { 93 | "package.json": [ 94 | "finepack" 95 | ] 96 | }, 97 | "simple-git-hooks": { 98 | "commit-msg": "npx commitlint --edit", 99 | "pre-commit": "npx nano-staged" 100 | }, 101 | "standard": { 102 | "globals": [ 103 | "after", 104 | "describe", 105 | "it" 106 | ] 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /register.js: -------------------------------------------------------------------------------- 1 | ;(window || global).JSON = require('./lib') 2 | -------------------------------------------------------------------------------- /test/fixture.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "bar" 3 | } 4 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const should = require('should') 4 | const path = require('path') 5 | const fs = require('fs') 6 | 7 | const jsonFuture = require('..') 8 | 9 | const FIXTURES = { 10 | string: '{\n "foo": "bar"\n}', 11 | object: { 12 | foo: 'bar' 13 | }, 14 | path: path.join(process.cwd(), 'test', 'fixture.json'), 15 | path2: path.join(process.cwd(), 'test', 'fixture2.json') 16 | } 17 | 18 | describe('JSON Future ::', function () { 19 | after(function (done) { 20 | return fs.unlink(FIXTURES.path2, done) 21 | }) 22 | 23 | describe('sync', function () { 24 | it('.parse', function () { 25 | const json = jsonFuture.parse(FIXTURES.string) 26 | should(json.foo).be.equal(FIXTURES.object.foo) 27 | }) 28 | 29 | it('.stringify', function () { 30 | const string = jsonFuture.stringify(FIXTURES.object) 31 | should(string).be.equal(FIXTURES.string) 32 | }) 33 | 34 | it('.load', function () { 35 | const json = jsonFuture.load(FIXTURES.path) 36 | should(json.foo).be.equal(FIXTURES.object.foo) 37 | }) 38 | 39 | it('.save', function () { 40 | jsonFuture.save(FIXTURES.path2, { hello: 'world' }) 41 | const json = jsonFuture.load(FIXTURES.path2) 42 | should(json.hello).be.equal('world') 43 | }) 44 | }) 45 | 46 | describe('async', function () { 47 | describe('.parseAsync', function () { 48 | describe('promise', function () { 49 | ;[ 50 | ['String', FIXTURES.string], 51 | ['Buffer', Buffer.from(FIXTURES.string)] 52 | ].forEach(function (pair) { 53 | const type = pair[0] 54 | const input = pair[1] 55 | 56 | it(type, function (done) { 57 | jsonFuture 58 | .parseAsync(input) 59 | .then(function (json) { 60 | should(json.foo).be.equal(FIXTURES.object.foo) 61 | done() 62 | }) 63 | .catch(done) 64 | }) 65 | }) 66 | }) 67 | 68 | describe('callback', function () { 69 | ;[ 70 | ['String', FIXTURES.string], 71 | ['Buffer', Buffer.from(FIXTURES.string)] 72 | ].forEach(function (pair) { 73 | const type = pair[0] 74 | const input = pair[1] 75 | 76 | it(type, function (done) { 77 | jsonFuture.parseAsync(input, function (err, data) { 78 | should(data.foo).be.equal(FIXTURES.object.foo) 79 | done(err) 80 | }) 81 | }) 82 | }) 83 | }) 84 | }) 85 | 86 | describe('.stringifyAsync', function () { 87 | it('callback', function (done) { 88 | jsonFuture 89 | .stringifyAsync(FIXTURES.object) 90 | .then(function (string) { 91 | should(string).be.equal(FIXTURES.string) 92 | done() 93 | }) 94 | .catch(done) 95 | }) 96 | 97 | it('callback', function (done) { 98 | jsonFuture.stringifyAsync(FIXTURES.object, function (err, string) { 99 | should(string).be.equal(FIXTURES.string) 100 | done(err) 101 | }) 102 | }) 103 | }) 104 | 105 | describe('.loadAsync', function () { 106 | it('promise', function (done) { 107 | jsonFuture 108 | .loadAsync(FIXTURES.path) 109 | .then(function (json) { 110 | should(json.foo).be.equal(FIXTURES.object.foo) 111 | done() 112 | }) 113 | .catch(done) 114 | }) 115 | 116 | it('callback', function (done) { 117 | jsonFuture.loadAsync(FIXTURES.path, function (err, json) { 118 | should(json.foo).be.equal(FIXTURES.object.foo) 119 | done(err) 120 | }) 121 | }) 122 | }) 123 | 124 | describe('.saveAsync', function () { 125 | it('promise', function (done) { 126 | jsonFuture 127 | .saveAsync(FIXTURES.path2, { hello: 'world2' }) 128 | .then(() => jsonFuture.loadAsync(FIXTURES.path2)) 129 | .then(json => { 130 | should(json.hello).be.equal('world2') 131 | done() 132 | }) 133 | .catch(done) 134 | }) 135 | 136 | it('callback', function (done) { 137 | jsonFuture.saveAsync( 138 | FIXTURES.path2, 139 | { 140 | hello: 'world2' 141 | }, 142 | function (err) { 143 | if (err) return done(err) 144 | jsonFuture.loadAsync(FIXTURES.path2, function (err, json) { 145 | should(json.hello).be.equal('world2') 146 | done(err) 147 | }) 148 | } 149 | ) 150 | }) 151 | }) 152 | }) 153 | }) 154 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --bail 2 | --require should 3 | --reporter spec 4 | --timeout 120000 5 | --slow 300 6 | --------------------------------------------------------------------------------