minor refactroing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-08-21 02:27:54 +03:00
parent 1b42aa4b19
commit a7f42d1e8c
2 changed files with 26 additions and 20 deletions

View File

@ -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,
}) })

View File

@ -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": {