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

sailfish

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sailfish - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

32

index.js

@@ -10,3 +10,3 @@ var

render = require("./lib/render"),
router = require("./lib/router");
Router = require("./lib/router");

@@ -20,2 +20,3 @@ /**

this.render = null;
this.componentRelativePath = undefined;

@@ -56,3 +57,2 @@ this.libRelativePath = undefined;

'components' : './components',
'controllers': './controllers',
'views' : './views'

@@ -117,3 +117,2 @@ };

this.render = new render(this.config, this.requirejs);
this.router = new router(this.config);

@@ -155,5 +154,2 @@ //prepare domain

this.app.engine('html', this.render.render.bind(this.render));
//routing
this.app.all(/\/(?:([^\/]*)\/?)?(?:([^\/]*)\/?)?(.*)?/, this.router.route.bind(this.router));
};

@@ -234,2 +230,26 @@

moduleExports.Component = require("./lib/Component.js");
moduleExports.baseRouting = function(controllersPath){
var
router,
regExp = /\/(?:([^\/]*)\/?)?(?:([^\/]*)\/?)?(.*)?/;
//resolve path
controllersPath = nodePath.resolve(process.cwd(), controllersPath || './controllers');
//check resolved path on disk
if(!fs.existsSync(controllersPath)){
throw new Error("baseRouting : '" + controllersPath + "' not found");
}
router = new Router(controllersPath);
return function(req, res, next){
req.params = [];
var a = regExp.exec(req.originalUrl) || [];
for (var i = 1, l = a.length; i < l; i++){
a[i] && req.params.push(a[i]);
}
router.route.apply(router, arguments);
}
};
module.exports = moduleExports;

7

lib/router.js

@@ -9,9 +9,8 @@ /**

var Router = function(config){
var Router = function(controllersPath){
var self = this;
this.config = config;
this.controllers = {};
fs.readdirSync(this.config["controllers"]).forEach(function(controller){
self.controllers[controller.replace(/\..*$/, "")] = require(nodePath.join(self.config["controllers"], controller));
fs.readdirSync(controllersPath).forEach(function(controller){
self.controllers[controller.replace(/\..*$/, "")] = require(nodePath.join(controllersPath, controller));
});

@@ -18,0 +17,0 @@ };

{
"name": "sailfish",
"version": "0.0.10",
"version": "0.0.11",
"main": "./index.js",

@@ -5,0 +5,0 @@ "bin": {

define("js!Abstract", ["js!utils", "js!Class", "js!EventBus"], function (utils, Class, EventBus) {
return Class.extend({
_id : null,
_options: {
id : ''
},
_eventChannel : null,
init : function(){
this._id = utils.generateId();
this._options.id = this._options.id || utils.generateId();
this._eventChannel = EventBus.channel(this._id);

@@ -24,3 +26,3 @@ },

getId : function(){
return this._id;
return this._options.id;
},

@@ -27,0 +29,0 @@ destroy : function(){

define('js!BaseComponent', ['js!utils', 'js!Abstract', 'js!dom'], function(utils, Abstract, dom){
var global = (function(){return this || (0,eval)('this')})();
var
dataComponent = /data-component=('|")([^'"]*)\1/,
hasClass = /^<[a-z][a-z0-9]*[^>]*?class=('|")/,
tagStart = /^<[a-z][a-z0-9]*/,
global = (function(){return this || (0,eval)('this')})();
global.require = require;

@@ -18,3 +22,3 @@

case 'element':
utils.extend(true, this._options, utils.parseOptions(cfg));
utils.extend(true, this._options, utils.parseConfigAttr(cfg));
this._container = cfg;

@@ -49,2 +53,3 @@ break;

this._container = buffer;
this._container.removeAttribute('config');
}

@@ -64,7 +69,8 @@ },

constructor = null,
parsedOptions = {};
parsedOptions = {},
xmlObject;
try{
//try to parse component type
componentType = /data-component=('|")([^'"]*)\1/.exec(markup)[2];
componentType = dataComponent.exec(markup)[2];
//get constructor

@@ -77,6 +83,14 @@ constructor = global.require('js!' + componentType);

function pushAttr(attrs, name, value){
attrs.push({name: name, value: value});
}
if (constructor){
if (typeof constructor.prototype._dotTplFn == 'function'){
xmlObject = dom.parse(markup).documentElement;
var attributes = xmlObject.attributes;
//parse configuration
parsedOptions = utils.parseMarkup(markup);
parsedOptions = utils.parseMarkup(xmlObject);
utils.extend(true, options, constructor.prototype._options, parsedOptions);

@@ -86,12 +100,29 @@

//append important attributes
markup = markup.replace(/^<\/?[a-z][a-z0-9]*/, function(start){
var attributes = " config='"+ utils.encodeConfig(parsedOptions) +"' hasmarkup='true' ";
if (options.id){
attributes += ("id='"+ options.id +"' ")
//prepare attributes
var attrStr = '';
if (options.id){
pushAttr(attributes, 'id', options.id);
}
if (parentId){
pushAttr(attributes, 'data-pid', parentId);
}
pushAttr(attributes, 'config', utils.encodeConfig(parsedOptions));
pushAttr(attributes, 'hasmarkup', 'true');
for (var i = 0, l = attributes.length; i < l; i++){
var a = attributes[i];
if (a.name == 'class'){
if (hasClass.test(markup)){
markup = markup.replace(hasClass, function(start){
return start + a.value + ' ';
});
continue;
}
}
if (parentId){
attributes += ("data-pid='"+ parentId +"' ");
}
return start + attributes;
attrStr += (' ' + a.name + "='"+ a.value +"'");
}
//append attributes
markup = markup.replace(tagStart, function(start){
return start + attrStr;
})

@@ -98,0 +129,0 @@ }

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

define("js!Class", ["js!utils"], function (core) {
define("js!Class", ["js!utils"], function (utils) {
/* Simple JavaScript Inheritance

@@ -44,5 +44,7 @@ * By John Resig http://ejohn.org/

})(name, prop[name]) :
name == "_options" ? core.extend(true, this.prototype[name], prop[name]) : prop[name];
name == "_options" ? utils.extend(true, {}, this.prototype[name], prop[name]) : prop[name];
}
prototype.__getDefaultOptions = utils.deepCopyFn(prototype._options);
// The dummy class constructor

@@ -52,4 +54,5 @@ function Class() {

if (!initializing && this.init){
if ("_options" in this && core.type(arguments[0]) === "object"){
this._options = core.extend(true, this._options, arguments[0]);
if ("_options" in this && utils.type(arguments[0]) === "object"){
var b = this.__getDefaultOptions();
this._options = utils.extend(true, b, arguments[0]);
}

@@ -56,0 +59,0 @@ this.init.apply(this, arguments);

define('js!dom', ['js!Node'], function(Node){
var
tagRegExp = /(<\/?[a-z][a-z0-9]*\s*(?:\s+[a-z0-9-_]+=(?:(?:'.*?')|(?:".*?")))*\s*\/?>)|([^<]|<(?![a-z\/]))*/gi,
tagRegExp = /(<\/?[a-z][a-z0-9]*(?::[a-z][a-z0-9]*)?\s*(?:\s+[a-z0-9-_]+=(?:(?:'.*?')|(?:".*?")))*\s*\/?>)|([^<]|<(?![a-z\/]))*/gi,
attrRegExp = /\s[a-z0-9-_]+\b(=('|").*?\2)?/gi,

@@ -10,3 +10,3 @@ startComponent = /^<component/,

closeTag = /^<\//,
nodeName = /<([a-z][a-z0-9]*)/i,
nodeName = /<([a-z][a-z0-9]*)(?::([a-z][a-z0-9]*))?/i,
attributeQuotes = /(^'|")|('|")$/g;

@@ -51,2 +51,3 @@

result = new Node({
document : true,
childNodes: [],

@@ -58,2 +59,3 @@ parentNode: null

tag,
fullNodeName,
attrBuffer = [],

@@ -65,2 +67,3 @@ attrStr = [],

tag = tags[i];
fullNodeName = tag.match(nodeName);

@@ -79,3 +82,4 @@ if (startTag.test(tag)){

nodeType: 1, //element node
nodeName : tag.match(nodeName)[1],
nodeName : fullNodeName[1],
namespace : fullNodeName[2],
attributes: attributes,

@@ -86,2 +90,6 @@ childNodes: [],

}));
if (currentObject.isDocument() && !currentObject.documentElement){
currentObject.documentElement = buffer;
}
if (!selfClose.test(tag)){

@@ -88,0 +96,0 @@ currentObject = buffer;

@@ -9,2 +9,3 @@ define('js!Node', function(){

this.nodeName = cfg.nodeName;
this.namespace = cfg.namespace || null;
this.attributes = cfg.attributes || [];

@@ -14,2 +15,5 @@ this.childNodes = cfg.childNodes;

this.text = cfg.text;
this._document = !!cfg.document;
this.documentElement = undefined;
};

@@ -54,3 +58,7 @@

Node.prototype.isDocument = function(){
return this._document;
};
return Node;
});

@@ -35,3 +35,2 @@ /**

function parseElem(elem){

@@ -45,5 +44,5 @@ var result;

else {
if (/Object|object|Array|array/.test(elem.getAttribute('type'))){
if (/Object|object|Array|array/.test(elem.namespace)){
var
isArray = /Array|array/.test(elem.getAttribute('type')),
isArray = /Array|array/.test(elem.namespace),
res = isArray ? [] : {},

@@ -80,3 +79,3 @@ childRes,

}
else if (/HTML|html/.test(elem.getAttribute('type'))){
else if (/HTML|html/.test(elem.namespace)){
result = {name : elem.nodeName, value : elem.innerHTML()};

@@ -336,20 +335,12 @@ }

* Parse configuration from html element declaration
* @param {HTMLElement} markup HTMLElement contained config declared by html
* @param {Object} xmlObject faked xmlElement
* @returns {Object}
*/
utils.parseMarkup = function(markup){
utils.parseMarkup = function(xmlObject){
var
xmlObject = dom.parse(markup),
obj,
childNodes;
for (var cI = 0, cL = xmlObject.childNodes.length; cI < cL; cI++){
if (xmlObject.childNodes[cI].nodeType == 1){
xmlObject = xmlObject.childNodes[cI];
break;
}
}
obj = utils.parseConfigAttr(xmlObject);
obj = utils.parseOptions(xmlObject);
obj.name = xmlObject.getAttribute('name') || obj.name || '';

@@ -379,3 +370,3 @@ obj.id = xmlObject.getAttribute('id') || obj.id || utils.generateId();

utils.parseOptions = function(container){
utils.parseConfigAttr = function(container){
var result = {};

@@ -407,3 +398,68 @@ try{

function getStr(v, storage){
var result = '';
if (v instanceof Array){
if (!v.length){
result = '[]';
}
else{
result = '[';
for (var i = 0, l = v.length; i < l; i++){
result += getStr(v[i], storage);
}
result += ']';
}
}
else if (Object.prototype.toString.call(v) == '[object Object]'){
result = '{';
var firstProperty = true;
for (var n in v){
if (v.hasOwnProperty(n)){
if (!firstProperty){
result += ',';
}
else{
firstProperty = false;
}
result += '"' + n + '":' + getStr(v[n], storage);
}
}
result += '}';
}
else if (v instanceof Date){
result = 'new Date('+ (+v) +')';
}
else if (v instanceof RegExp){
var flags =
(v.multiline ? 'm' : '') +
(v.global ? 'g' : '') +
(v.ignoreCase ? 'i' : '');
result = 'new RegExp("'+ v.source +'","'+ flags +'")'
}
else if (typeof(v) == 'function'){
result = 'this.storage[' + storage.length + ']';
storage.push(v);
}
else if (typeof(v) == 'string'){
result = '"' + v + '"';
}
else {
result = '' + v;
}
return result;
}
utils.deepCopyFn = function(toCopy){
var
context = {
storage : []
},
fn = new Function('return ' + getStr(toCopy, context.storage) + ';');
return function(){
return fn.apply(context, arguments);
}
};
return utils;
});

@@ -8,3 +8,22 @@ define('html!test.Component', ['doT'], function(doT){

return BaseComponent.extend({
_dotTplFn: doTfn
_array: [],
_options : {
value : 1,
array: []
},
_dotTplFn: doTfn,
init: function(cfg){
this._super(cfg);
this._array.push(1);
this._options.array.push(1);
},
getValue: function(){
return this._options.value;
},
getPropertyArrayLength: function(){
return this._array.length;
},
getOptionArrayLength: function(){
return this._options.array.length;
}
});

@@ -18,5 +37,14 @@ });

define('js!test.ParentComponent', ['js!BaseComponent', 'html!test.ParentComponent', 'js!test.Component'], function(BaseComponent, doTfn){
return BaseComponent.extend({
_dotTplFn: doTfn
define('js!test.ParentComponent', ['js!CompoundComponent', 'html!test.ParentComponent', 'js!test.Component'], function(CompoundComponent, doTfn){
return CompoundComponent.extend({
_dotTplFn: doTfn,
getChildControlsCount: function(){
var count = 0;
for (var i in this._components){
if (this._components.hasOwnProperty(i)){
count++;
}
}
return count;
}
});

@@ -90,3 +118,3 @@ });

var markup = '\
<component id="4224" data-component="test.ParentComponent">\
<component id="4224" data-component="test.ParentComponent" class="some-class" some-attr="attrValue">\
<content type="html">\

@@ -100,4 +128,3 @@ <component data-component="test.Component">\

var
result = parentConstr.prototype._prepareMarkup.apply(parentConstr.prototype, [markup]),
var result = parentConstr.prototype._prepareMarkup.apply(parentConstr.prototype, [markup]),
elem = document.createElement('div');

@@ -128,3 +155,36 @@

});
it('additionalAttr', function(){
expect(elem.getElementsByClassName('test-ParentComponent')[0].getAttribute('some-attr')).toEqual('attrValue');
});
it('class', function(){
expect(elem.getElementsByClassName('test-ParentComponent')[0].getAttribute('class')).toEqual('some-class test-ParentComponent')
});
it('_components', function(){
var c = new parentConstr(elem.getElementsByClassName('test-ParentComponent')[0]);
expect(c.getChildControlsCount()).toEqual(1);
});
});
describe('overwritingOptions', function(){
var
a = new constr({value: 1}),
b = new constr({value: 2});
//todo: improve inheritance for protection non-function properties
/*it('hardTypeProperty', function(){
expect(a.getPropertyArrayLength()).toEqual(1);
expect(b.getPropertyArrayLength()).toEqual(1);
});*/
it('simpleTypeOption', function(){
expect(a.getValue()).toEqual(1);
expect(b.getValue()).toEqual(2);
});
it('hardTypeOption', function(){
expect(a.getOptionArrayLength()).toEqual(1);
expect(b.getOptionArrayLength()).toEqual(1);
});
});
});

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

define(['js!utils'], function(utils){
define(['js!utils', 'js!dom'], function(utils, dom){

@@ -14,5 +14,6 @@ describe('parseMarkup', function() {

</component>',
xmlObject = dom.parse(innerHTML).documentElement,
res;
res = utils.parseMarkup(innerHTML);
res = utils.parseMarkup(xmlObject);

@@ -32,3 +33,3 @@ expect(res).toEqual({

var xml = '<component name="test">\
<arr type="array">\
<arr:array>\
<foo>bar</foo>\

@@ -41,5 +42,6 @@ <num>42</num>\

</component>',
xmlObject = dom.parse(xml).documentElement,
res;
res = utils.parseMarkup(xml);
res = utils.parseMarkup(xmlObject);

@@ -57,3 +59,3 @@ expect(res.arr).toEqual([

var xml = '<component name="test">\
<obj type="object">\
<obj:object>\
<foo>bar</foo>\

@@ -66,5 +68,6 @@ <num>42</num>\

</component>',
xmlObject = dom.parse(xml).documentElement,
res;
res = utils.parseMarkup(xml);
res = utils.parseMarkup(xmlObject);

@@ -82,10 +85,10 @@ expect(res.obj).toEqual({

var xml = '<component name="test">\
<obj type="object" foo="bar" num="42" bool="false" null="null" undefined="undefined"></obj>\
<obj:object foo="bar" num="42" bool="false" null="null" undefined="undefined"></obj>\
</component>',
xmlObject = dom.parse(xml).documentElement,
res;
res = utils.parseMarkup(xml);
res = utils.parseMarkup(xmlObject);
expect(res.obj).toEqual({
'type': 'object',
'foo': 'bar',

@@ -101,16 +104,17 @@ 'num': 42,

var xml = '<component name="test">\
<obj type="object">\
<arr type="array">\
<o type="object">\
<obj:object>\
<arr:array>\
<o:object>\
</o>\
<o type="object"></o>\
<o type="object" foo="bar"></o>\
<o type="object" bool="false"></o>\
<o:object></o>\
<o:object foo="bar"></o>\
<o:object bool="false"></o>\
</o>\
<obj type="object" foo="bar" num="42" bool="false" null="null" undefined="undefined"></o>\
<obj:object foo="bar" num="42" bool="false" null="null" undefined="undefined"></o>\
</obj>\
</component>',
xmlObject = dom.parse(xml).documentElement,
res;
res = utils.parseMarkup(xml);
res = utils.parseMarkup(xmlObject);

@@ -120,11 +124,7 @@ expect(res.obj).toEqual({

{},
{},
{
type: 'object'
},
{
type: 'object',
foo: 'bar'
},
{
type: 'object',
bool: false

@@ -134,3 +134,2 @@ }

'obj': {
'type': 'object',
'foo': 'bar',

@@ -145,2 +144,40 @@ 'num': 42,

it('parseMarkup.complicatedMarkup', function() {
var xml = '<component id="123" data-component="docs.Sidebar" name="menu">\
<activeLink>/qs/example</activeLink>\
<items:array>\
<o:object>\
<caption>Quick start</caption>\
<submenu:array>\
<o:object caption="Install" href="/qs/install"></o>\
<o:object caption="Usage" href="/qs/example"></o>\
</submenu>\
</o>\
</items>\
</component>',
xmlObject = dom.parse(xml).documentElement,
res;
res = utils.parseMarkup(xmlObject);
expect(res).toEqual({
"name": "menu",
"id": "123",
"activeLink": "/qs/example",
"items": [
{
"caption": "Quick start",
"submenu": [
{
"caption": "Install",
"href": "/qs/install"
},
{
"caption": "Usage",
"href": "/qs/example"
}
]
}
]});
});
it('parseMarkup.parseAttr', function() {

@@ -156,6 +193,8 @@ var

},
xmlObject,
res;
markup = "<component id='2' config='"+ utils.encodeConfig(cfg) +"' />";
res = utils.parseMarkup(markup);
xmlObject = dom.parse(markup).documentElement;
res = utils.parseMarkup(xmlObject);

@@ -162,0 +201,0 @@ expect(res).toEqual({

@@ -18,2 +18,3 @@ define(['js!utils'], function(utils){

'regexp' : /./,
'date' : new Date(),
'element': document.createElement('div'),

@@ -35,2 +36,127 @@ 'nan' : NaN,

describe('deepCloneFn', function(){
it('NaN', function(){
var
toClone = {nan : NaN},
cloneFn = utils.deepCopyFn(toClone),
clone = cloneFn();
expect(clone.nan).toBeNaN();
});
it('EmptyString', function(){
utils.deepCopyFn({id : ''});
var
toClone = {id : ''},
cloneFn = utils.deepCopyFn(toClone),
clone = cloneFn();
expect(clone).toEqual(toClone);
});
it ('simpleType', function(){
var
toClone = {
'null' : null,
'undefined' : {}.a,
'string' : 'str',
'number' : 1,
'boolean' : true,
'regexp' : /./gim,
'date' : new Date(),
'infinity' : 1/0
},
deepCopyFn = utils.deepCopyFn(toClone),
clone = deepCopyFn();
expect(clone).toEqual(toClone);
});
it ('deepClone', function(){
var
toClone = {
'null' : null,
'undefined' : {}.a,
'string' : 'str',
'number' : 1,
'boolean' : true,
'regexp' : /./gim,
'date' : new Date(),
'infinity' : 1/0,
'object' : {
a : {
'null' : null,
'undefined' : {}.a,
'string' : 'str',
'number' : 1,
'boolean' : true,
'regexp' : /./gim,
'date' : new Date(),
'infinity' : 1/0
},
b : [
{
'null' : null,
'undefined' : {}.a,
'string' : 'str',
'number' : 1,
'boolean' : true,
'regexp' : /./gim,
'date' : new Date(),
'infinity' : 1/0,
'object' : {
a : {
'null' : null,
'undefined' : {}.a,
'string' : 'str',
'number' : 1,
'boolean' : true,
'regexp' : /./gim,
'date' : new Date(),
'infinity' : 1/0
},
b : [
{
'null' : null,
'undefined' : {}.a,
'string' : 'str',
'number' : 1,
'boolean' : true,
'regexp' : /./gim,
'date' : new Date(),
'infinity' : 1/0
}
]
}
}
]
}
},
cloneFn = utils.deepCopyFn(toClone),
clone = cloneFn();
expect(clone).toEqual(toClone);
});
it ('functions', function(){
var
globalVar = 42,
toClone = {
fn : function(){
return globalVar + 1;
},
fn1: function(){
return this.fn() + 1;
}
},
cloneFn = utils.deepCopyFn(toClone),
clone = cloneFn();
expect(clone.fn()).toEqual(43);
expect(clone.fn1()).toEqual(44);
})
});
});
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