Comparing version 1.0.7 to 2.0.0
@@ -1,42 +0,14 @@ | ||
function Message() { | ||
Object.defineProperties( | ||
this, { | ||
data: { | ||
enumerable: true, | ||
get: getData, | ||
set: setData | ||
}, | ||
type: { | ||
enumerable: true, | ||
get: getType, | ||
set: setType | ||
}, | ||
load:{ | ||
enumerable:true, | ||
writable:false, | ||
value:parse | ||
}, | ||
JSON: { | ||
enumerable: true, | ||
get: getJSON | ||
} | ||
} | ||
); | ||
var type = ''; | ||
var data = {}; | ||
function getType() { | ||
return type; | ||
export class Message { | ||
constructor() { | ||
} | ||
function getData() { | ||
return data; | ||
} | ||
type='' | ||
data={} | ||
function getJSON() { | ||
get JSON() { | ||
return JSON.stringify( | ||
{ | ||
type: type, | ||
data: data | ||
type: this.type, | ||
data: this.data | ||
} | ||
@@ -46,23 +18,15 @@ ); | ||
function setType(value) { | ||
type = value; | ||
} | ||
function setData(value) { | ||
data = value; | ||
} | ||
function parse(message){ | ||
try{ | ||
var message=JSON.parse(message); | ||
type=message.type; | ||
data=message.data; | ||
}catch(err){ | ||
var badMessage=message; | ||
type='error', | ||
data={ | ||
message:'Invalid JSON response format', | ||
err:err, | ||
response:badMessage | ||
} | ||
load(message) { | ||
try { | ||
const parsedMessage = JSON.parse(message); | ||
this.type = parsedMessage.type; | ||
this.data = parsedMessage.data; | ||
} catch (err) { | ||
const badMessage = message; | ||
this.type = 'error'; | ||
this.data = { | ||
message: 'Invalid JSON response format', | ||
err: err, | ||
response: badMessage | ||
}; | ||
} | ||
@@ -72,2 +36,2 @@ } | ||
module.exports=Message; | ||
export default Message; |
{ | ||
"name": "js-message", | ||
"version": "1.0.7", | ||
"description": "normalized JS Object and JSON message and event protocol for node.js, vanialla js, react.js, components, actions, stores and dispatchers", | ||
"main": "Message.js", | ||
"version": "2.0.0", | ||
"description": "normalized JS Object and JSON message and event protocol for ES6+ node.js, browsers, electron, vanialla js, react.js, components, actions, stores and dispatchers", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node devServer.js" | ||
"start": "node-http-server port=8000 verbose=true" | ||
}, | ||
@@ -15,3 +16,3 @@ "repository": { | ||
"engines": { | ||
"node": ">=0.6.0" | ||
"node": ">=13.2.0" | ||
}, | ||
@@ -54,3 +55,6 @@ "keywords": [ | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
"devDependencies": { | ||
"node-http-server": "^8.1.3", | ||
"vanilla-test": "^1.4.2" | ||
} | ||
} |
@@ -30,8 +30,17 @@ # js-message | ||
For the browser you can do either an import with the path to make the first http request for your module, and have it cached for other scripts thereafter ***OR*** you can import it with the `<script>` tag upfront which automatically loads as `defer` so it doesn't interrupt the parser. | ||
```html | ||
<script type="module" src='/path/to/module/js-message-vanilla.js' /> | ||
``` | ||
Both node and the browser now support `import` statements. If you use relative pathing you can use the same exact code from node in the browser without even transpiling much the less bundling. | ||
```javascript | ||
//commonjs | ||
var Message=require('js-message'); | ||
//plain old javascript | ||
<script src='js-message-vanilla.js' /> | ||
//works for browser natively AND node natively | ||
import { default as Message } from './node_modules/js-message/Message.js'; | ||
//works for browser transpiled AND node natively | ||
import { default as Message } from 'js-message'; | ||
@@ -97,2 +106,2 @@ var myMessage=new Message; | ||
This work is licenced via the [DBAD Public Licence](http://www.dbad-license.org/). | ||
This work is licenced via the MIT Licence |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105
Yes
9423
2
5
96