mirror of
https://github.com/flynx/object.js.git
synced 2025-10-31 19:40:09 +00:00
minor refactroing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1b42aa4b19
commit
a7f42d1e8c
44
object.js
44
object.js
@ -10,8 +10,32 @@ function(require){ var module={} // makes module AMD/node compatible...
|
|||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
// Helpers...
|
||||||
|
|
||||||
|
// XXX is this the right place for this???
|
||||||
|
// ...when moving take care that ImageGrid's core.doc uses this...
|
||||||
|
var normalizeIndent =
|
||||||
|
module.normalizeIndent =
|
||||||
|
function(text){
|
||||||
|
var lines = text.split(/\n/)
|
||||||
|
var l = lines
|
||||||
|
.reduce(function(l, e, i){
|
||||||
|
var indent = e.length - e.trimLeft().length
|
||||||
|
return e.trim().length == 0
|
||||||
|
// ignore 0 indent of first line...
|
||||||
|
|| (i == 0 && indent == 0) ? l
|
||||||
|
: l < 0 ?
|
||||||
|
indent
|
||||||
|
: Math.min(l, indent)
|
||||||
|
}, -1)
|
||||||
|
return lines
|
||||||
|
.map(function(line, i){
|
||||||
|
return i == 0 ? line : line.slice(l) })
|
||||||
|
.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
// Make a JavaScrip object constructor...
|
// Make a JavaScrip object constructor...
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -203,25 +227,7 @@ function makeConstructor(name, a, b){
|
|||||||
.replace(/[^{]*{/, '{')
|
.replace(/[^{]*{/, '{')
|
||||||
: '{ .. }'
|
: '{ .. }'
|
||||||
|
|
||||||
// normalize code indent...
|
return `${this.name}(${args})${normalizeIndent(code)}`
|
||||||
// NOTE: this repeats ImageGrid's core.doc(..)...
|
|
||||||
var lines = code.split(/\n/)
|
|
||||||
var l = lines
|
|
||||||
.reduce(function(l, e, i){
|
|
||||||
var indent = e.length - e.trimLeft().length
|
|
||||||
return e.trim().length == 0
|
|
||||||
// ignore 0 indent of first line...
|
|
||||||
|| (i == 0 && indent == 0) ? l
|
|
||||||
: l < 0 ?
|
|
||||||
indent
|
|
||||||
: Math.min(l, indent)
|
|
||||||
}, -1)
|
|
||||||
code = lines
|
|
||||||
.map(function(line, i){
|
|
||||||
return i == 0 ? line : line.slice(l) })
|
|
||||||
.join('\n')
|
|
||||||
|
|
||||||
return `${this.name}(${args})${code}`
|
|
||||||
},
|
},
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user