first commit

This commit is contained in:
DanielRamirezGe
2020-01-14 20:43:08 -06:00
parent 3557894f7f
commit 5eecfbf6cd
26326 changed files with 2434803 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
function Message() {
Object.defineProperties(
this, {
data: {
enumerable: true,
get: getData,
set: setData
},
type: {
enumerable: true,
get: getType,
set: setType
},
load:{
enumarable:true,
writable:false,
value:parse
},
JSON: {
enumerable: true,
get: getJSON
}
}
);
var type = '';
var data = {};
function getType() {
return type;
}
function getData() {
return data;
}
function getJSON() {
return JSON.stringify(
{
type: type,
data: data
}
);
}
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
}
}
}
}
module.exports=Message;
+96
View File
@@ -0,0 +1,96 @@
# js-message
Normalized JS & JSON Message and event Protocol for node.js, vanilla.js (plain old javascript), react.js, websockets, rest api's, node-ipc, and any other protocol that might use a js object and or a JSON string.
js-message allows for seamless conversion of JSON messages and events to JS objects for a normalized implementation on the server and in the client without needing to concern yourself with JSON intermediaries and custom parsers.
Things are just easier when you normalize them.
npm js-message info : [See npm trends and stats for js-message](http://npm-stat.com/charts.html?package=js-message&author=&from=&to=)
![js-message npm version](https://img.shields.io/npm/v/js-message.svg) ![supported node version for js-message](https://img.shields.io/node/v/js-message.svg) ![total npm downloads for js-message](https://img.shields.io/npm/dt/js-message.svg) ![monthly npm downloads for js-message](https://img.shields.io/npm/dm/js-message.svg) ![npm licence for js-message](https://img.shields.io/npm/l/js-message.svg)
` npm install --save js-message `
[![RIAEvangelist](https://avatars3.githubusercontent.com/u/369041?v=3&s=100)](https://github.com/RIAEvangelist)
GitHub info :
[![js-message GitHub Release](https://img.shields.io/github/release/RIAEvangelist/js-message.svg) ![GitHub license js-message license](https://img.shields.io/github/license/RIAEvangelist/js-message.svg) ![open issues for js-message on GitHub](https://img.shields.io/github/issues/RIAEvangelist/js-message.svg)](http://riaevangelist.github.io/js-message/)
[js-message site](http://riaevangelist.github.io/js-message/)
|method or key |type |mutable|description|
|---------------|-------|-------|-----------|
|type |String |true |the type of message|
|data |Object |true |the message data or payload|
|load |func |false |load a message from JSON, this will return a message with the type of error if not valid JSON|
|JSON |String |not by user|JSON representation of the message|
### Creating a Message Object
```javascript
//commonjs
var Message=require('js-message');
//plain old javascript
<script src='js-message-vanilla.js' />
var myMessage=new Message;
myMessage.type='message or event type';
myMessage.data.something='something';
myMessage.data.stuff=[1,2,3,4,5]
console.log(myMessage.JSON);
```
### Creating a Message From JSON
```javascript
//commonjs
var Message=require('js-message');
//plain old javascript
<script src='js-message-vanilla.js' />
//lets say we have the above example running on
//a websocket server sending js-messages as JSON
//
//and lets say this is the client in the browser
ws.on(
'message',
handleMessage
);
handleMessage(e){
var message=new Message;
message.load(e.data);
console.log(message.type, message.data);
}
```
### Sending a Message Object via WebSocket
```javascript
//commonjs
var Message=require('js-message');
//plain old javascript
<script src='js-message-vanilla.js' />
//client example, but works the same on server too!
var ws=new WebSocket('ws://myawesomeWS:8000');
var myMessage=new Message;
myMessage.type='setUsername';
myMessage.data.username='sideshow bob';
ws.send(myMessage.JSON);
```
---
This work is licenced via the [DBAD Public Licence](http://www.dbad-license.org/).
+75
View File
@@ -0,0 +1,75 @@
(
function(){
function Message() {
Object.defineProperties(
this, {
data: {
enumerable: true,
get: getData,
set: setData
},
type: {
enumerable: true,
get: getType,
set: setType
},
load:{
enumarable:true,
writable:false,
value:parse
},
JSON: {
enumerable: true,
get: getJSON
}
}
);
var type = '';
var data = {};
function getType() {
return type;
}
function getData() {
return data;
}
function getJSON() {
return JSON.stringify(
{
type: type,
data: data
}
);
}
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
}
}
}
}
window.message=Message;
}
)();
+27
View File
@@ -0,0 +1,27 @@
# DON'T BE A DICK PUBLIC LICENSE
> Version 1, December 2009
> Copyright (C) 2009 Philip Sturgeon <email@philsturgeon.co.uk>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
> DON'T BE A DICK PUBLIC LICENSE
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
1. Do whatever you like with the original work, just don't be a dick.
Being a dick includes - but is not limited to - the following instances:
1a. Outright copyright infringement - Don't just copy this and change the name.
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
2. If you become rich through modifications, related works/services, or supporting the original work,
share the love. Only a dick would make loads off this work and not buy the original work's
creator(s) a pint.
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
+81
View File
@@ -0,0 +1,81 @@
{
"_from": "js-message@1.0.5",
"_id": "js-message@1.0.5",
"_inBundle": false,
"_integrity": "sha1-IwDSSxrwjondCVvBpMnJz8uJLRU=",
"_location": "/js-message",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "js-message@1.0.5",
"name": "js-message",
"escapedName": "js-message",
"rawSpec": "1.0.5",
"saveSpec": null,
"fetchSpec": "1.0.5"
},
"_requiredBy": [
"/node-ipc"
],
"_resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
"_shasum": "2300d24b1af08e89dd095bc1a4c9c9cfcb892d15",
"_spec": "js-message@1.0.5",
"_where": "/home/george/citwa/red_de_investigacion_front/first/node_modules/node-ipc",
"author": {
"name": "Brandon Nozaki Miller"
},
"bugs": {
"url": "https://github.com/RIAEvangelist/js-message/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "normalized JS Object and JSON message and event protocol for node.js, vanialla js, react.js, components, actions, stores and dispatchers",
"devDependencies": {},
"engines": {
"node": ">=0.6.0"
},
"homepage": "https://github.com/RIAEvangelist/js-message#readme",
"keywords": [
"message",
"normalize",
"events",
"js",
"json",
"protocol",
"ipc",
"node",
"nodejs",
"node.js",
"react",
"react.js",
"reactjs",
"websocket",
"websockets",
"web",
"socket",
"sockets",
"ws",
"flux",
"reflux",
"component",
"components",
"store",
"stores",
"action",
"actions"
],
"license": "DBAD",
"main": "Message.js",
"name": "js-message",
"repository": {
"type": "git",
"url": "git+https://github.com/RIAEvangelist/js-message.git"
},
"scripts": {
"start": "node devServer.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.5"
}