[Pkg-javascript-commits] [node-syntax-error] 04/47: dox

Bastien Roucariès rouca at moszumanska.debian.org
Fri Aug 25 19:29:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-syntax-error.

commit 023e4c202c70d08aff488f78092f59c346d0520e
Author: James Halliday <mail at substack.net>
Date:   Thu Aug 2 00:14:30 2012 -0700

    dox
---
 readme.markdown | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/readme.markdown b/readme.markdown
new file mode 100644
index 0000000..483ca89
--- /dev/null
+++ b/readme.markdown
@@ -0,0 +1,85 @@
+# syntax-error
+
+Check for and report syntax errors in source code strings.
+
+When you type `node src.js` you get a friendly error report about exactly where
+the syntax error is. This module lets you check for syntax errors and report
+them in a similarly friendly format that wrapping a try/catch around
+`Function()` or `vm.runInNewContext()` doesn't get you.
+
+# example
+
+``` js
+var fs = require('fs');
+var check = require('syntax-error');
+
+var file = __dirname + '/src.js';
+var src = fs.readFileSync(file);
+
+var err = check(src, file);
+if (err) {
+    console.error('ERROR DETECTED' + Array(62).join('!'));
+    console.error(err);
+    console.error(Array(76).join('-'));
+}
+```
+
+***
+
+```
+$ node check.js
+ERROR DETECTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+/home/substack/projects/node-syntax-error/example/src.js:5
+        if (Array.isArray(x) res.push.apply(res, x);
+                             ^
+ParseError: Unexpected identifier
+---------------------------------------------------------------------------
+```
+
+# methods
+
+``` js
+var check = require('syntax-error')
+```
+
+## var err = check(src, file)
+
+Check the source code string `src` for syntax errors.
+Optionally you can specify a filename `file` that will show up in the output.
+
+If `src` has a syntax error, return an error object `err` that can be printed or
+stringified.
+
+If there are no syntax errors in `src`, return `undefined`.
+
+## err.toString()
+
+Return the long string description with a source snippet and a `^` under
+pointing exactly where the error was detected.
+
+# attributes
+
+## err.message
+
+short string description of the error type
+
+## err.line
+
+line number of the error in the original source (indexing starts at 1)
+
+## err.column
+
+column number of the error in the original source (indexing starts at 1)
+
+# install
+
+With [npm](http://npmjs.org) do:
+
+```
+npm install syntax-error
+```
+
+# license
+
+MIT

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-syntax-error.git



More information about the Pkg-javascript-commits mailing list