├── .bumpedrc ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jscsrc ├── .jshintrc ├── .npmignore ├── .npmrc ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── bower.json ├── dist ├── example.html └── json-parse-async.js ├── gulpfile.coffee ├── index.js ├── package.json └── test ├── sample.json ├── test.coffee └── test.sh /.bumpedrc: -------------------------------------------------------------------------------- 1 | files: [ 2 | "package.json" 3 | "bower.json" 4 | ] 5 | plugins: 6 | postrelease: 7 | 'Compile browser version': 8 | plugin: 'bumped-terminal' 9 | command: 'gulp' 10 | 11 | 'Generating CHANGELOG file': 12 | plugin: 'bumped-changelog' 13 | 14 | 'Commit the new version': 15 | plugin: 'bumped-terminal' 16 | command: 'git add . && git commit -m "$newVersion releases"' 17 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | 22 | 23 | ############################ 24 | # Tests 25 | ############################ 26 | testApp 27 | coverage 28 | 29 | 30 | ############################ 31 | # Other 32 | ############################ 33 | .node_history 34 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "disallowSpacesInNamedFunctionExpression": { 4 | "beforeOpeningRoundBrace": true 5 | }, 6 | "disallowSpacesInFunctionExpression": { 7 | "beforeOpeningRoundBrace": true 8 | }, 9 | "disallowSpacesInAnonymousFunctionExpression": { 10 | "beforeOpeningRoundBrace": true 11 | }, 12 | "disallowSpacesInFunctionDeclaration": { 13 | "beforeOpeningRoundBrace": true 14 | }, 15 | "disallowEmptyBlocks": true, 16 | "disallowSpacesInsideArrayBrackets": true, 17 | "disallowSpacesInsideParentheses": true, 18 | "disallowQuotedKeysInObjects": true, 19 | "disallowSpaceAfterObjectKeys": true, 20 | "disallowSpaceAfterPrefixUnaryOperators": true, 21 | "disallowSpaceBeforePostfixUnaryOperators": true, 22 | "disallowSpaceBeforeBinaryOperators": [ 23 | "," 24 | ], 25 | "disallowMixedSpacesAndTabs": true, 26 | "disallowTrailingWhitespace": true, 27 | "excludeFiles": ["node_modules/**"], 28 | "maximumLineLength": 100, 29 | "disallowTrailingComma": true, 30 | "disallowYodaConditions": true, 31 | "disallowKeywords": [ 32 | "with" 33 | ], 34 | "disallowMultipleLineBreaks": true, 35 | "disallowMultipleVarDecl": true, 36 | "requireSpaceBeforeBlockStatements": true, 37 | "requireSpacesInConditionalExpression": true, 38 | "requireBlocksOnNewline": 1, 39 | "requireCommaBeforeLineBreak": true, 40 | "requireSpaceBeforeBinaryOperators": true, 41 | "requireSpaceAfterBinaryOperators": true, 42 | "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties", 43 | "requireLineFeedAtFileEnd": true, 44 | "requireCapitalizedConstructors": true, 45 | "requireDotNotation": true, 46 | "requireSpacesInForStatement": true, 47 | "requireSpaceBetweenArguments": true, 48 | "requireCurlyBraces": [ 49 | "do" 50 | ], 51 | "requireSpaceBeforeKeywords": [ 52 | "else" 53 | ], 54 | "requireSpaceAfterKeywords": [ 55 | "if", 56 | "else", 57 | "for", 58 | "while", 59 | "do", 60 | "switch", 61 | "case", 62 | "return", 63 | "try", 64 | "catch", 65 | "typeof" 66 | ], 67 | "requirePaddingNewLinesBeforeLineComments": { 68 | "allExcept": "firstAfterCurly" 69 | }, 70 | "safeContextKeyword": [ 71 | "self", 72 | "_this" 73 | ], 74 | "validateLineBreaks": "LF", 75 | "validateIndentation": 2, 76 | "validateQuoteMarks": { 77 | "mark": "'", 78 | "escape": true 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, // Defines globals available when your code is running inside of the Node runtime environment 3 | "esnext": true, // Tells JSHint that your code uses ECMAScript 6 specific syntax. 4 | "bitwise": true, // Prohibits the use of bitwise operators such as ^ (XOR), | (OR) and others. 5 | "curly": false, // Always put curly braces around blocks in loops and conditionals 6 | "noarg": true, // Prohibits the use of arguments.caller and arguments.callee. 7 | "undef": true, // Prohibits the use of explicitly undeclared variables. 8 | "unused": "vars", // Warns when you define and never use your variables. 9 | "strict": true, // Requires all functions to run in ECMAScript 5's strict mode. 10 | "eqnull": true, // Suppresses warnings about == null comparisons 11 | "eqeqeq": true, // Prohibits the use of == and != in favor of === and !==. 12 | "browser": true, // This option defines globals exposed by modern browsers 13 | "mootools": true, // This option defines globals exposed by the MooTools JavaScript framework. 14 | "mocha": true // This option defines globals exposed by the "BDD" and "TDD" UIs of the Mocha unit testing framework. 15 | } 16 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .project 3 | *.sublime-* 4 | .DS_Store 5 | *.seed 6 | *.log 7 | *.csv 8 | *.dat 9 | *.out 10 | *.pid 11 | *.swp 12 | *.swo 13 | node_modules 14 | coverage 15 | *.tgz 16 | *.xml 17 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | unsafe-perm=true 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | - "stable" 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## 1.0.3 (2015-11-20) 3 | 4 | 5 | * Update README.md ([2e9dc8e](https://github.com/kikobeats/json-parse-async/commit/2e9dc8e)) 6 | * updated dependency ([078ee47](https://github.com/kikobeats/json-parse-async/commit/078ee47)) 7 | 8 | 9 | 10 | 11 | ## 1.0.2 (2015-09-07) 12 | 13 | 14 | * 1.0.2 releases ([ec5d96a](https://github.com/kikobeats/json-parse-async/commit/ec5d96a)) 15 | * removed unnecessary dependency ([5565c04](https://github.com/kikobeats/json-parse-async/commit/5565c04)) 16 | * renamed ([2ec62ec](https://github.com/kikobeats/json-parse-async/commit/2ec62ec)) 17 | 18 | 19 | 20 | 21 | ## 1.0.1 (2015-08-03) 22 | 23 | 24 | * 1.0.1 releases ([25928f3](https://github.com/kikobeats/json-parse-async/commit/25928f3)) 25 | * fixed message ([841bcad](https://github.com/kikobeats/json-parse-async/commit/841bcad)) 26 | * updated bumped settings ([ccac781](https://github.com/kikobeats/json-parse-async/commit/ccac781)) 27 | 28 | 29 | 30 | 31 | # 1.0.0 (2015-07-28) 32 | 33 | 34 | * added custom error ([102c6f1](https://github.com/kikobeats/json-parse-async/commit/102c6f1)) 35 | * first commit ([e4cb15d](https://github.com/kikobeats/json-parse-async/commit/e4cb15d)) 36 | * little refactor ([e46bf82](https://github.com/kikobeats/json-parse-async/commit/e46bf82)) 37 | * renamed ([800aa9a](https://github.com/kikobeats/json-parse-async/commit/800aa9a)) 38 | * Update README.md ([6fa2ee9](https://github.com/kikobeats/json-parse-async/commit/6fa2ee9)) 39 | * updated ([2e22430](https://github.com/kikobeats/json-parse-async/commit/2e22430)) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /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-parse-async 2 | 3 | ![Last version](https://img.shields.io/github/tag/Kikobeats/json-parse-async.svg?style=flat-square) 4 | [![Build Status](http://img.shields.io/travis/Kikobeats/json-parse-async/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/json-parse-async) 5 | [![Dependency status](http://img.shields.io/david/Kikobeats/json-parse-async.svg?style=flat-square)](https://david-dm.org/Kikobeats/json-parse-async) 6 | [![Dev Dependencies Status](http://img.shields.io/david/dev/Kikobeats/json-parse-async.svg?style=flat-square)](https://david-dm.org/Kikobeats/json-parse-async#info=devDependencies) 7 | [![NPM Status](http://img.shields.io/npm/dm/json-parse-async.svg?style=flat-square)](https://www.npmjs.org/package/json-parse-async) 8 | [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/kikobeats) 9 | 10 | > The missing JSON.parse async interface. 11 | 12 | ## Install 13 | 14 | ```bash 15 | npm install json-parse-async --save 16 | ``` 17 | 18 | If you want to use in the browser (powered by [Browserify](http://browserify.org/)): 19 | 20 | ```bash 21 | bower install json-parse-async --save 22 | ``` 23 | 24 | and later link in your HTML: 25 | 26 | ```html 27 | 28 | ``` 29 | 30 | ## Usage 31 | 32 | ```js 33 | var parseJSON = require('json-parse-async'); 34 | var stringify = '{"foo":"bar"}'; 35 | 36 | // as callback interface 37 | parseJSON(stringify, function(err, content) { 38 | console.log(content.foo); // => 'bar' 39 | }); 40 | 41 | // as promise interface 42 | parseJSON(stringify) 43 | .then(function(content) { 44 | console.log(content.foo); // => 'bar' 45 | }) 46 | .catch(function(err) { 47 | console.log('promise was rejected:', err); 48 | }); 49 | ``` 50 | 51 | ## License 52 | 53 | MIT © [Kiko Beats](http://www.kikobeats.com) 54 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "json-parse-async", 3 | "description": "The missing JSON.parse async interface.", 4 | "homepage": "https://github.com/Kikobeats/json-parse-async", 5 | "version": "1.0.3", 6 | "main": "./dist/json-parse-async.js", 7 | "authors": [ 8 | { 9 | "name": "Kiko Beats", 10 | "email": "josefrancisco.verdu@gmail.com", 11 | "homepage": "https://github.com/Kikobeats" 12 | } 13 | ], 14 | "repository": "Kikobeats/json-parse-async", 15 | "bugs": { 16 | "url": "https://github.com/Kikobeats/json-parse-async/issues" 17 | }, 18 | "keywords": [ 19 | "JSON", 20 | "parse", 21 | "async", 22 | "promise" 23 | ], 24 | "ignore": [ 25 | "**/.*", 26 | "bower_components", 27 | "node_modules", 28 | "test", 29 | "tests" 30 | ], 31 | "license": "MIT" 32 | } 33 | -------------------------------------------------------------------------------- /dist/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | json-parse-async 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /dist/json-parse-async.js: -------------------------------------------------------------------------------- 1 | /** 2 | * json-parse-async - The missing JSON.parse async interface. 3 | * @version v1.0.3 4 | * @link https://github.com/Kikobeats/json-parse-async 5 | * @license MIT 6 | */require=function t(n,e,r){function o(s,u){if(!e[s]){if(!n[s]){var c="function"==typeof require&&require;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var a=e[s]={exports:{}};n[s][0].call(a.exports,function(t){var e=n[s][1][t];return o(e?e:t)},a,a.exports,t,n,e,r)}return e[s].exports}for(var i="function"==typeof require&&require,s=0;s1)for(var e=1;e - <%= pkg.description %>" 28 | " * @version v<%= pkg.version %>" 29 | " * @link <%= pkg.homepage %>" 30 | " * @license <%= pkg.license %>" 31 | " */"].join("\n") 32 | 33 | # -- Tasks --------------------------------------------------------------------- 34 | 35 | gulp.task 'browserify', -> 36 | browserify 37 | extensions: ['.coffee', '.js'] 38 | .transform coffeeify 39 | .require(src.main, { expose: module.shortcut}) 40 | .ignore('coffee-script') 41 | .bundle() 42 | .pipe source module.filename 43 | .pipe buffer() 44 | .pipe uglify() 45 | .pipe header banner, pkg: pkg 46 | .pipe gulp.dest module.dist 47 | 48 | gulp.task 'default', -> 49 | gulp.start 'browserify' 50 | return 51 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var promise = require('cb2promise'); 4 | var Whoops = require('whoops'); 5 | 6 | var parseAsync = function(data, cb) { 7 | var content; 8 | var error; 9 | 10 | try { 11 | content = JSON.parse(data); 12 | } catch (err) { 13 | content = {}; 14 | error = new Whoops({ 15 | code: 'ENOVALIDJSON', 16 | message: err.message 17 | }); 18 | } finally { 19 | return process.nextTick(function() { 20 | return cb(error, content); 21 | }); 22 | } 23 | }; 24 | 25 | function parseJSON(data, cb) { 26 | if (arguments.length === 1) return promise(parseAsync, data); 27 | return parseAsync(data, cb); 28 | } 29 | 30 | module.exports = parseJSON; 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "json-parse-async", 3 | "description": "The missing JSON.parse async interface.", 4 | "homepage": "https://github.com/Kikobeats/json-parse-async", 5 | "version": "1.0.3", 6 | "main": "./index.js", 7 | "author": { 8 | "name": "Kiko Beats", 9 | "email": "josefrancisco.verdu@gmail.com", 10 | "url": "https://github.com/Kikobeats" 11 | }, 12 | "repository": "Kikobeats/json-parse-async", 13 | "bugs": { 14 | "url": "https://github.com/Kikobeats/json-parse-async/issues" 15 | }, 16 | "keywords": [ 17 | "JSON", 18 | "parse", 19 | "async", 20 | "promise" 21 | ], 22 | "dependencies": { 23 | "cb2promise": "~1.1.0", 24 | "whoops": "~4.0.1" 25 | }, 26 | "devDependencies": { 27 | "browserify": "latest", 28 | "coffee-script": "latest", 29 | "coffeeify": "latest", 30 | "gulp": "latest", 31 | "gulp-header": "latest", 32 | "gulp-uglify": "latest", 33 | "gulp-util": "latest", 34 | "mocha": "latest", 35 | "should": "latest", 36 | "vinyl-buffer": "latest", 37 | "vinyl-source-stream": "latest" 38 | }, 39 | "engines": { 40 | "node": ">= 0.10.0", 41 | "npm": ">= 1.4.0" 42 | }, 43 | "scripts": { 44 | "test": "sh test/test.sh" 45 | }, 46 | "license": "MIT" 47 | } 48 | -------------------------------------------------------------------------------- /test/sample.json: -------------------------------------------------------------------------------- 1 | {"foo":"bar"} 2 | -------------------------------------------------------------------------------- /test/test.coffee: -------------------------------------------------------------------------------- 1 | parseJSON = require '..' 2 | fs = require 'fs' 3 | should = require 'should' 4 | sampleJSON = fs.readFileSync "#{__dirname}/sample.json", encoding: 'utf8' 5 | 6 | describe 'parseJSON ::', -> 7 | 8 | it 'as callback', (done) -> 9 | parseJSON sampleJSON, done 10 | 11 | it 'as promise', -> 12 | parseJSON(sampleJSON).then (content) -> 13 | content.foo.should.be.equal 'bar' 14 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | welcome() { 4 | clear 5 | echo ' _____ _____ _____ _____ _____ _ _ _____ ' 6 | echo '|_ _|| ___|/ ___||_ _||_ _|| \ | || __ \ ' 7 | echo ' | | | |__ \ `--. | | | | | \| || | \/ ' 8 | echo ' | | | __| `--. \ | | | | | . ` || | __ ' 9 | echo ' | | | |___ /\__/ / | | _| |_ | |\ || |_\ \ ' 10 | echo ' \_/ \____/ \____/ \_/ \___/ \_| \_/ \____/ ' 11 | echo 12 | } 13 | 14 | run() { 15 | "$PWD"/node_modules/.bin/mocha \ 16 | -b \ 17 | --compilers coffee:coffee-script/register \ 18 | --require should \ 19 | --reporter spec \ 20 | --timeout 120000 \ 21 | --slow 300 \ 22 | "$@" 23 | } 24 | 25 | ## Main 26 | welcome && run \ 27 | test/test.coffee 28 | 29 | 30 | --------------------------------------------------------------------------------