string-alter
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -1,6 +0,10 @@ | ||
var SLICE$0 = Array.prototype.slice;function ITER$0(v,f){if(v){if(Array.isArray(v))return f?v.slice():v;var i,r;if(typeof v==='object'&&typeof v['@@iterator']==='function'){i=v['@@iterator'](),r=[];while((f=i['next']()),f['done']!==true)r.push(f['value']);return r;}}throw new Error(v+' is not iterable')};"use strict"; | ||
var SLICE$0 = Array.prototype.slice;function ITER$0(v,f){if(v){if(Array.isArray(v))return f?v.slice():v;var i,r;if(typeof v==='object'&&typeof v['@@iterator']==='function'){i=v['@@iterator'](),r=[];while((f=i['next']()),f['done']!==true)r.push(f['value']);return r;}}throw new Error(v+' is not iterable')};/*global module*/ | ||
/*es6-transpiler has-iterators:false, has-generators:false*/ | ||
"use strict"; | ||
var BUILD_VERSION = '0.7.1'; | ||
var BUILD_VERSION = '0.7.2'; | ||
var RangeIndex = _4019148491396410335742_1_require_rangeindex(); | ||
var RangeIndex = _573457601397589148529_1_require_rangeindex(); | ||
var RangeOffset = _4704933811397589148041_1_require___RangeOffset_js(); | ||
var Record = _4704933811397589148041_2_require___Record_js(); | ||
@@ -10,177 +14,2 @@ var assert = this["assert"] || (function(expect, msg) { if(expect != true)throw new Error(msg || "") }); | ||
var RangeOffset = (function(){ | ||
function RangeOffset() {var offsets = arguments[0];if(offsets === void 0)offsets = []; | ||
this.offsets = offsets; | ||
} | ||
RangeOffset.prototype.addInsert = function(to, offset) { | ||
this.addRange(to, to, offset, true); | ||
} | ||
RangeOffset.prototype.addRemove = function(from, to) { | ||
while( from++ < to ) { | ||
this.addRange(void 0, from, -1); | ||
} | ||
} | ||
RangeOffset.prototype.addRange = function(from, to, offset) {var newIsAdding = arguments[3];if(newIsAdding === void 0)newIsAdding = false; | ||
if( !offset ) { | ||
return; | ||
} | ||
if( offset < 0 ) { | ||
// TODO:: new logic [START] | ||
// if( offset < -1 ) { | ||
// this.addRemove(to + offset, to); | ||
// return; | ||
// } | ||
// | ||
// from = to; | ||
// TODO:: new logic [END] | ||
// this is an old logic: | ||
from = from + (-offset - 1); | ||
} | ||
var offsets = (this).offsets; | ||
var offsetValue = offsets[from] || 0 | ||
, addingValue = 0 | ||
, extendValue = 0 | ||
; | ||
if( typeof offsetValue === "string" ) { | ||
var index = offsetValue.indexOf("|"); | ||
if( index !== -1 ) {//adding | ||
addingValue = offsetValue.substr(index + 1) | 0; | ||
extendValue = offsetValue.substr(0, index) | 0; | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
if( newIsAdding ) { | ||
addingValue += offset; | ||
} | ||
else { | ||
extendValue += offset; | ||
} | ||
if( addingValue ) { | ||
extendValue = (("" + extendValue) + ("|" + addingValue) + ""); | ||
} | ||
else { | ||
extendValue = extendValue; | ||
} | ||
offsets[from] = extendValue; | ||
} | ||
RangeOffset.prototype.clone = function() { | ||
return new RangeOffset(this.offsets.slice()) | ||
} | ||
/** | ||
* | ||
* @param pos | ||
* @param {Array=} offsets | ||
* @returns {*} | ||
*/ | ||
RangeOffset.prototype.getPosition = function(pos) { | ||
return this.getRange(pos, pos, true).from; | ||
} | ||
RangeOffset.prototype.getRecord = function(to, considerExtends) {var from = to.from, to = to.to; | ||
return this.getRange(from, to, considerExtends); | ||
} | ||
RangeOffset.prototype.getRange = function(from, to) {var considerExtends = arguments[2];if(considerExtends === void 0)considerExtends = false;//TODO:: optimize function speed | ||
var offsets = (this).offsets; | ||
if( offsets.length ) { | ||
var positionOffset = 0; | ||
var originalFrom = from + positionOffset, originalTo = to + positionOffset; | ||
for( var offset in offsets ) if( offsets.hasOwnProperty(offset) ) { | ||
// Fast enumeration through sparse array MAY CAUSE PROBLEM WITH WRONG ORDER OF ARRAY ITEM, but it is unlikely | ||
offset = offset | 0; | ||
var offsetValue = offsets[offset]; | ||
var extendValue = 0; | ||
var addingValue = 0; | ||
if( typeof offsetValue === "string" ) { | ||
offsetValue += ""; | ||
var index = offsetValue.indexOf("|"); | ||
if( index !== -1 ) {//adding | ||
addingValue = offsetValue.substr(index + 1) | 0; | ||
extendValue = offsetValue.substr(0, index) | 0; | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
if( offset <= originalTo ) {// must be <= | ||
if( offset <= originalFrom) {// must be <= | ||
if( considerExtends || offset !== originalFrom ) { | ||
from += extendValue; | ||
} | ||
if( addingValue ) { | ||
from += addingValue; | ||
} | ||
} | ||
to += extendValue; | ||
if( offset !== originalTo && addingValue ) { | ||
to += addingValue; | ||
} | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
} | ||
return {from: from, to: to}; | ||
} | ||
;return RangeOffset;})(); | ||
var Record = (function(){ | ||
function Record(from, to) { | ||
this.from = from; | ||
this.to = to; | ||
} | ||
Record.prototype.toString = function() { | ||
return (("" + (Record.uniqueStart)) + ("[" + (this.from)) + ("]" + (Record.uniqueSeparator)) + ("[" + (this.to)) + ("]" + (Record.uniqueEnd)) + ""); | ||
} | ||
Record.prototype.addSubs = function() {var $D$0;var fragments = SLICE$0.call(arguments, 0); | ||
if( fragments.length ) { | ||
if( !this.subs ) { | ||
this.subs = []; | ||
} | ||
($D$0 = this.subs).push.apply($D$0, ITER$0(fragments)); | ||
;$D$0 = void 0} | ||
} | ||
Record.prototype.getSubs = function() { | ||
return this.subs; | ||
} | ||
;return Record;})(); | ||
Record.uniqueStart = "[<" + ((Math.random() * 1e8) | 0);//should matches /\[\<\d{8}/ | ||
Record.uniqueSeparator = "" + ((Math.random() * 1e8) | 0);//should matches /\d{8}/ | ||
Record.uniqueEnd = ((Math.random() * 1e8) | 0) + ">]";//should matches /\d{8}\>\]/ | ||
Record.uniqueRE = new RegExp("\\[\\<\\d{" + (Record.uniqueStart.length - 2) + "}\\[(\\d+)\\]\\d{" + Record.uniqueSeparator.length + "}\\[(\\d+)\\]\\d{" + (Record.uniqueEnd.length - 2) + "}\\>\\]", "g"); | ||
var Fragment = (function(){ | ||
@@ -195,3 +24,3 @@ function Fragment(from, to) {var insertStr = arguments[2];if(insertStr === void 0)insertStr = "";var type = arguments[3];if(type === void 0)type = Fragment.Types.replace; | ||
Fragment.prototype.addSubs = function() {var $D$1;var fragments = SLICE$0.call(arguments, 0); | ||
Fragment.prototype.addSubs = function() {var $D$0;var fragments = SLICE$0.call(arguments, 0); | ||
if( fragments.length ) { | ||
@@ -201,4 +30,4 @@ if( !this.subs ) { | ||
} | ||
($D$1 = this.subs).unshift.apply($D$1, ITER$0(fragments)); | ||
;$D$1 = void 0} | ||
($D$0 = this.subs).unshift.apply($D$0, ITER$0(fragments)); | ||
;$D$0 = void 0} | ||
} | ||
@@ -1002,4 +831,198 @@ | ||
;function _4019148491396410335742_1_require_rangeindex(){var module = {exports: {}};"use strict"; | ||
;function _4704933811397589148041_1_require___RangeOffset_js(){var module = {exports: {}};/*global module*/ | ||
/*es6-transpiler has-iterators:false, has-generators:false*/ | ||
"use strict"; | ||
var RangeOffset = (function(){ | ||
function RangeOffset() {var offsets = arguments[0];if(offsets === void 0)offsets = []; | ||
this.offsets = offsets; | ||
} | ||
RangeOffset.prototype.addInsert = function(to, offset) { | ||
this.addRange(to, to, offset, true); | ||
} | ||
RangeOffset.prototype.addRemove = function(from, to) { | ||
while( from++ < to ) { | ||
this.addRange(void 0, from, -1); | ||
} | ||
} | ||
RangeOffset.prototype.addRange = function(from, to, offset) {var newIsAdding = arguments[3];if(newIsAdding === void 0)newIsAdding = false; | ||
if( !offset ) { | ||
return; | ||
} | ||
if( offset < 0 ) { | ||
// TODO:: new logic [START] | ||
// if( offset < -1 ) { | ||
// this.addRemove(to + offset, to); | ||
// return; | ||
// } | ||
// | ||
// from = to; | ||
// TODO:: new logic [END] | ||
// this is an old logic: | ||
from = from + (-offset - 1); | ||
} | ||
var offsets = (this).offsets; | ||
var offsetValue = offsets[from] || 0 | ||
, addingValue = 0 | ||
, extendValue = 0 | ||
; | ||
if( typeof offsetValue === "string" ) { | ||
var index = offsetValue.indexOf("|"); | ||
if( index !== -1 ) {//adding | ||
addingValue = offsetValue.substr(index + 1) | 0; | ||
extendValue = offsetValue.substr(0, index) | 0; | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
if( newIsAdding ) { | ||
addingValue += offset; | ||
} | ||
else { | ||
extendValue += offset; | ||
} | ||
if( addingValue ) { | ||
extendValue = (("" + extendValue) + ("|" + addingValue) + ""); | ||
} | ||
else { | ||
extendValue = extendValue; | ||
} | ||
offsets[from] = extendValue; | ||
} | ||
RangeOffset.prototype.clone = function() { | ||
return new RangeOffset(this.offsets.slice()) | ||
} | ||
/** | ||
* | ||
* @param pos | ||
* @param {Array=} offsets | ||
* @returns {*} | ||
*/ | ||
RangeOffset.prototype.getPosition = function(pos) { | ||
return this.getRange(pos, pos, true).from; | ||
} | ||
RangeOffset.prototype.getRecord = function(to, considerExtends) {var from = to.from, to = to.to; | ||
return this.getRange(from, to, considerExtends); | ||
} | ||
RangeOffset.prototype.getRange = function(from, to) {var considerExtends = arguments[2];if(considerExtends === void 0)considerExtends = false;//TODO:: optimize function speed | ||
var offsets = (this).offsets; | ||
if( offsets.length ) { | ||
var positionOffset = 0; | ||
var originalFrom = from + positionOffset, originalTo = to + positionOffset; | ||
for( var offset in offsets ) if( offsets.hasOwnProperty(offset) ) { | ||
// Fast enumeration through sparse array MAY CAUSE PROBLEM WITH WRONG ORDER OF ARRAY ITEM, but it is unlikely | ||
offset = offset | 0; | ||
var offsetValue = offsets[offset]; | ||
var extendValue = 0; | ||
var addingValue = 0; | ||
if( typeof offsetValue === "string" ) { | ||
offsetValue += ""; | ||
var index = offsetValue.indexOf("|"); | ||
if( index !== -1 ) {//adding | ||
addingValue = offsetValue.substr(index + 1) | 0; | ||
extendValue = offsetValue.substr(0, index) | 0; | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
} | ||
else { | ||
extendValue = offsetValue | 0; | ||
} | ||
if( offset <= originalTo ) {// must be <= | ||
if( offset <= originalFrom) {// must be <= | ||
if( offset !== originalFrom ) { | ||
from += extendValue; | ||
} | ||
else if ( considerExtends && extendValue > 0 ) { | ||
// positive extend could move from position in this case | ||
from += extendValue; | ||
} | ||
if( addingValue ) { | ||
from += addingValue; | ||
} | ||
} | ||
to += extendValue; | ||
if( offset !== originalTo && addingValue ) { | ||
to += addingValue; | ||
} | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
} | ||
return {from: from, to: to}; | ||
} | ||
;return RangeOffset;})(); | ||
module.exports = RangeOffset; | ||
;return module.exports}; | ||
;function _4704933811397589148041_2_require___Record_js(){var module = {exports: {}};/*global module*/ | ||
/*es6-transpiler has-iterators:false, has-generators:false*/ | ||
"use strict"; | ||
var Record = (function(){ | ||
function Record(from, to) { | ||
this.from = from; | ||
this.to = to; | ||
} | ||
Record.prototype.toString = function() { | ||
return (("" + (Record.uniqueStart)) + ("[" + (this.from)) + ("]" + (Record.uniqueSeparator)) + ("[" + (this.to)) + ("]" + (Record.uniqueEnd)) + ""); | ||
} | ||
Record.prototype.addSubs = function() {var $D$1;var fragments = SLICE$0.call(arguments, 0); | ||
if( fragments.length ) { | ||
if( !this.subs ) { | ||
this.subs = []; | ||
} | ||
($D$1 = this.subs).push.apply($D$1, ITER$0(fragments)); | ||
;$D$1 = void 0} | ||
} | ||
Record.prototype.getSubs = function() { | ||
return this.subs; | ||
} | ||
;return Record;})(); | ||
Record.uniqueStart = "[<" + ((Math.random() * 1e8) | 0);//should matches /\[\<\d{8}/ | ||
Record.uniqueSeparator = "" + ((Math.random() * 1e8) | 0);//should matches /\d{8}/ | ||
Record.uniqueEnd = ((Math.random() * 1e8) | 0) + ">]";//should matches /\d{8}\>\]/ | ||
Record.uniqueRE = new RegExp("\\[\\<\\d{" + (Record.uniqueStart.length - 2) + "}\\[(\\d+)\\]\\d{" + Record.uniqueSeparator.length + "}\\[(\\d+)\\]\\d{" + (Record.uniqueEnd.length - 2) + "}\\>\\]", "g"); | ||
module.exports = Record; | ||
;return module.exports}; | ||
;function _573457601397589148529_1_require_rangeindex(){var module = {exports: {}};"use strict"; | ||
var BUILD_VERSION = '0.0.4'; | ||
@@ -1006,0 +1029,0 @@ |
{ | ||
"name": "string-alter", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "String alter", | ||
@@ -5,0 +5,0 @@ "main": "./build/es5/StringAlter.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45411
1107
0