Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

javascript-editor

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

javascript-editor - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

3

demo.js

@@ -1,1 +0,2 @@

require('./')({ container: document.querySelector('#editor') })
var jsEdit = require('./')({ container: document.querySelector('#editor') })
jsEdit.setValue(document.querySelector('#program').text)

@@ -16,6 +16,8 @@ var events = require('events')

if (!opts) opts = {}
if (!opts.container) opts.container = document.body
var left = opts.container.querySelector('.left')
var right = opts.container.querySelector('.right')
if (left) opts.container = left
var defaults = {
value: "// hello world\n",
container: document.body,
mode: "javascript",

@@ -43,2 +45,10 @@ lineNumbers: true,

this.errorLines = []
if (right) {
this.results = CodeMirror(right, {
mode: 'javascript',
tabSize: 2,
readOnly: 'nocursor'
})
this.results.setOption("theme", 'mistakes')
}
this.update()

@@ -58,22 +68,32 @@ if (this.opts.dragAndDrop) this.addDropHandler()

while ( self.errorLines.length > 0 ) {
self.editor.removeLineClass( self.errorLines.shift(), 'background', 'errorLine' )
self.editor.removeLineClass( self.errorLines.shift().num, 'background', 'errorLine' )
}
try {
var result = esprima.parse( value, { tolerant: true, loc: true } ).errors;
var result = esprima.parse( value, { tolerant: true, loc: true } ).errors
for ( var i = 0; i < result.length; i ++ ) {
var error = result[ i ];
var lineNumber = error.lineNumber - 1;
self.errorLines.push( lineNumber );
self.editor.addLineClass( lineNumber, 'background', 'errorLine' );
var error = result[ i ]
var lineNumber = error.lineNumber - 1
self.errorLines.push( {num: lineNumber, message: error.message} )
self.editor.addLineClass( lineNumber, 'background', 'errorLine' )
}
} catch ( error ) {
var lineNumber = error.lineNumber - 1;
self.errorLines.push( lineNumber );
self.editor.addLineClass( lineNumber, 'background', 'errorLine' );
var lineNumber = error.lineNumber - 1
self.errorLines.push( {num: lineNumber, message: error.message} )
self.editor.addLineClass( lineNumber, 'background', 'errorLine' )
}
return self.errorLines.length === 0;
if (this.results) {
if (self.errorLines.length === 0) return this.results.setValue('')
var numLines = self.errorLines[self.errorLines.length - 1].num
var lines = []
for (var i = 0; i < numLines; i++) lines[i] = ''
self.errorLines.map(function(errLine) {
lines[errLine.num] = errLine.message
})
this.results.setValue(lines.join('\n'))
}
return self.errorLines.length === 0
}

@@ -101,1 +121,9 @@

}
Editor.prototype.getValue = function() {
return this.editor.getValue()
}
Editor.prototype.setValue = function(value) {
return this.editor.setValue(value)
}
{
"name": "javascript-editor",
"version": "0.0.2",
"version": "0.1.0",
"description": "codemirror + esprima powered html5 javascript editor component",

@@ -20,3 +20,3 @@ "repository": {

"scripts": {
"start": "./node_modules/browservefy/bin/browservefy demo.js 8080 --browserify=./node_modules/browserify/bin/cmd.js -- -d"
"start": "./node_modules/browservefy/bin/browservefy demo.js:bundle.js 8080 --browserify=./node_modules/browserify/bin/cmd.js -- -d"
},

@@ -23,0 +23,0 @@ "engines": {

@@ -23,5 +23,5 @@ # javascript-editor

```javascript
var editor = require('javascript-editor')
var createEditor = require('javascript-editor')
editor({ container: document.querySelector('#editor') })
var editor = createEditor({ container: document.querySelector('#editor') })

@@ -28,0 +28,0 @@ editor.on('change', function() {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc