logoots-utils
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "logoots-utils", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Helper providing several function manipulating strings or arrays", | ||
@@ -5,0 +5,0 @@ "main": "utils.js", |
158
utils.js
@@ -1,88 +0,76 @@ | ||
/** | ||
* Fonction permettant d'insérer à une position 'index' une chaîne de caractères 'string' | ||
*/ | ||
var insert = function (s, index, string) { | ||
if (index > 0) { | ||
return s.substring(0, index) + string + s.substring(index, s.length); | ||
} | ||
return string + s; | ||
}; | ||
/** | ||
* Fonction permettant de supprimer le caractère à une position 'index' | ||
*/ | ||
var del = function (s, begin, end) { | ||
var str = ''; | ||
if(begin !== 0) { | ||
str = s.substring(0, begin); | ||
} | ||
return str + s.substring(end + 1, s.length); | ||
}; | ||
/** | ||
* Fonction permettant de retirer un élément d'un tableau | ||
*/ | ||
var unset = function (arr, elt) { | ||
var index = arr.indexOf(elt); | ||
if(index > -1) { | ||
arr.splice(index, 1); | ||
} | ||
}; | ||
/** | ||
* Fonction permettant d'insérer une liste d'éléments dans un tableau | ||
*/ | ||
var pushAll = function(arr, elts) { | ||
var i; | ||
for(i=0; i<elts.length; i++) { | ||
arr.push(elts[i]); | ||
} | ||
}; | ||
var iterator = function(arr) { | ||
var it = { | ||
index: 0, | ||
items: arr, | ||
first: function() { | ||
this.reset(); | ||
return this.next(); | ||
}, | ||
next: function() { | ||
return this.items[this.index++]; | ||
}, | ||
hasNext: function() { | ||
return this.index < this.items.length; | ||
}, | ||
reset: function() { | ||
this.index = 0; | ||
}, | ||
}; | ||
return it; | ||
}; | ||
var getLast = function (arr) { | ||
return arr[arr.length-1]; | ||
}; | ||
var copy = function (arr) { | ||
var copy = []; | ||
var i; | ||
for(i=0; i<arr.length; i++) { | ||
if(typeof arr[i] === "number" || typeof arr[i] === "string") { | ||
copy.push(arr[i]); | ||
module.exports = { | ||
Result: { | ||
B1AfterB2: 'B1AfterB2', | ||
B1BeforeB2: 'B1BeforeB2', | ||
B1InsideB2: 'B1InsideB2', | ||
B2InsideB1: 'B2InsideB1', | ||
B1ConcatB2: 'B1ConcatB2', | ||
B2ConcatB1: 'B2ConcatB1' | ||
}, | ||
Children: { | ||
LEFT: 0, | ||
RIGHT: 1 | ||
}, | ||
insert: function (s, index, string) { | ||
if (index > 0) { | ||
return s.substring(0, index) + string + s.substring(index, s.length); | ||
} | ||
else if(typeof arr[i] === "object") { | ||
copy.push(arr[i].copy()); | ||
return string + s; | ||
}, | ||
del: function (s, begin, end) { | ||
var str = ''; | ||
if(begin !== 0) { | ||
str = s.substring(0, begin); | ||
} | ||
return str + s.substring(end + 1, s.length); | ||
}, | ||
unset: function (arr, elt) { | ||
var index = arr.indexOf(elt); | ||
if(index > -1) { | ||
arr.splice(index, 1); | ||
} | ||
}, | ||
pushAll: function(arr, elts) { | ||
var i; | ||
for(i=0; i<elts.length; i++) { | ||
arr.push(elts[i]); | ||
} | ||
}, | ||
iterator: function(arr) { | ||
var it = { | ||
index: 0, | ||
items: arr, | ||
first: function() { | ||
this.reset(); | ||
return this.next(); | ||
}, | ||
next: function() { | ||
return this.items[this.index++]; | ||
}, | ||
hasNext: function() { | ||
return this.index < this.items.length; | ||
}, | ||
reset: function() { | ||
this.index = 0; | ||
}, | ||
}; | ||
return it; | ||
}, | ||
getLast: function (arr) { | ||
return arr[arr.length-1]; | ||
}, | ||
copy: function (arr) { | ||
var copy = []; | ||
var i; | ||
for(i=0; i<arr.length; i++) { | ||
if(typeof arr[i] === "number" || typeof arr[i] === "string") { | ||
copy.push(arr[i]); | ||
} | ||
else if(typeof arr[i] === "object") { | ||
copy.push(arr[i].copy()); | ||
} | ||
} | ||
return copy; | ||
} | ||
return copy; | ||
}; | ||
exports.insert = insert; | ||
exports.del = del; | ||
exports.unset = unset; | ||
exports.pushAll = pushAll; | ||
exports.iterator = iterator; | ||
exports.getLast = getLast; | ||
exports.copy = copy; | ||
}; |
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
1932
74