Skip to content

Commit

Permalink
Removed all external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeche committed Oct 29, 2014
1 parent 156237a commit a0e6b5c
Show file tree
Hide file tree
Showing 35 changed files with 72 additions and 1,416 deletions.
2 changes: 1 addition & 1 deletion lib/assets/resources.js
Expand Up @@ -94,7 +94,7 @@ define(function(require, exports, module) {

function expandSnippetsDefinition(snippets) {
var out = {};
each(snippets)(function(val, key) {
each(snippets, function(val, key) {
var items = key.split('|');
// do not use iterators for better performance
for (var i = items.length - 1; i >= 0; i--) {
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/tabStops.js
Expand Up @@ -139,7 +139,7 @@ define(function(require, exports, module) {
text: buf,
tabstops: tabStops.sort(function(a, b) {
return a.start - b.start;
});
})
};
},

Expand Down
2 changes: 1 addition & 1 deletion lib/resolver/css.js
Expand Up @@ -720,7 +720,7 @@ define(function(require, exports, module) {
stream.match(/^t|[0-9a-f]+(\.\d+)?/i, true);
values.push(stream.current());
} else if (ch == '-') {
if (isValidKeyword(values[values.length - 1] ||
if (isValidKeyword(utils.last(values)) ||
( stream.start && isNumeric(str.charAt(stream.start - 1)) )
) {
stream.start = stream.pos;
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/abbreviation.js
Expand Up @@ -10,7 +10,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var elements = require('../assets/elements');
var tabStops = require('../assets/tabStops');
var utils = require('../utils/common');
Expand Down Expand Up @@ -77,7 +76,7 @@ define(function(require, exports, module) {
*/
hasBlockChildren: function(node) {
return (this.hasTagsInContent(node) && this.isBlock(node))
|| _.any(node.children, function(child) {
|| node.children.some(function(child) {
return this.isBlock(child);
}, this);
},
Expand All @@ -91,7 +90,7 @@ define(function(require, exports, module) {
* @returns {String
*/
insertChildContent: function(text, childContent, options) {
options = _.extend({
options = utils.extend({
keepVariable: true,
appendIfNoChild: true
}, options || {});
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/action.js
Expand Up @@ -9,7 +9,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var utils = require('./common');
var cssSections = require('./cssSections');
var abbreviationParser = require('../parser/abbreviation');
Expand Down Expand Up @@ -165,7 +164,7 @@ define(function(require, exports, module) {
var syntax = editor.getSyntax();
if (syntax in allowedSyntaxes) {
var content = editor.getContent();
if (_.isUndefined(pos)) {
if (typeof pos === 'undefined') {
pos = editor.getCaretPos();
}

Expand All @@ -181,7 +180,7 @@ define(function(require, exports, module) {
// parse attributes
var tagTree = xmlEditTree.parse(startTag.range.substring(content));
if (tagTree) {
contextNode.attributes = _.map(tagTree.getAll(), function(item) {
contextNode.attributes = tagTree.getAll().map(function(item) {
return {
name: item.name(),
value: item.value()
Expand Down
1 change: 0 additions & 1 deletion lib/utils/comments.js
Expand Up @@ -9,7 +9,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var utils = require('./common');
var range = require('../assets/range');
var stringStream = require('../assets/stringStream');
Expand Down
37 changes: 20 additions & 17 deletions lib/utils/common.js
Expand Up @@ -8,7 +8,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var range = require('../assets/range');

/**
Expand Down Expand Up @@ -87,7 +86,7 @@ define(function(require, exports, module) {
.split(nl);

if (removeEmpty) {
lines = _.filter(lines, function(line) {
lines = lines.filter(function(line) {
return line.length && !!this.trim(line);
}, this);
}
Expand Down Expand Up @@ -116,12 +115,14 @@ define(function(require, exports, module) {
* @returns {Array}
*/
getStringsPads: function(strings) {
var lengths = _.map(strings, function(s) {
return _.isString(s) ? s.length : +s;
var lengths = strings.map(function(s) {
return typeof s === 'string' ? s.length : +s;
});

var max = _.max(lengths);
return _.map(lengths, function(l) {
var max = lengths.reduce(function(prev, cur) {
return typeof prev === 'undefined' ? cur : Math.max(prev, cur);
});
return lengths.map(function(l) {
var pad = max - l;
return pad ? this.repeatString(' ', pad) : '';
}, this);
Expand Down Expand Up @@ -201,7 +202,7 @@ define(function(require, exports, module) {
var curSl = sl;
matchCount++;
var newValue = replace;
if (_.isFunction(replace)) {
if (typeof replace === 'function') {
var replaceData = replace(str, symbol, i, matchCount);
if (replaceData) {
curSl = replaceData[0].length;
Expand Down Expand Up @@ -269,7 +270,7 @@ define(function(require, exports, module) {
base = parseInt(m[2] || 1, 10) - 1;
}

if (decrement && total && _.isNumber(value)) {
if (decrement && total && typeof value === 'number') {
value = total - value + 1;
}

Expand Down Expand Up @@ -314,7 +315,7 @@ define(function(require, exports, module) {
* @returns {String}
*/
getCaretPlaceholder: function() {
return _.isFunction(caretPlaceholder)
return typeof caretPlaceholder === 'function'
? caretPlaceholder.apply(this, arguments)
: caretPlaceholder;
},
Expand Down Expand Up @@ -382,16 +383,18 @@ define(function(require, exports, module) {
* <code>start</code> argument is used
*/
replaceSubstring: function(str, value, start, end) {
if (_.isObject(start) && 'end' in start) {
if (typeof start === 'object' && 'end' in start) {
end = start.end;
start = start.start;
}

if (_.isString(end))
if (typeof end === 'string') {
end = start + end.length;
}

if (_.isUndefined(end))
if (typeof end === 'undefined') {
end = start;
}

if (start < 0 || start > str.length)
return str;
Expand All @@ -409,7 +412,7 @@ define(function(require, exports, module) {
replaceWith: function(content, ranges, ch, noRepeat) {
if (ranges.length) {
var offset = 0, fragments = [];
_.each(ranges, function(r) {
ranges.forEach(function(r) {
var repl = noRepeat ? ch : this.repeatString(ch, r[1] - r[0]);
fragments.push(content.substring(offset, r[0]), repl);
offset = r[1];
Expand Down Expand Up @@ -495,7 +498,7 @@ define(function(require, exports, module) {


// Handle case when target is a string or something (possible in deep copy)
if (!_.isObject(target) && !_.isFunction(target)) {
if (typeof target !== 'object' && typeof target !== 'function') {
target = {};
}

Expand All @@ -513,13 +516,13 @@ define(function(require, exports, module) {
}

// Recurse if we're merging plain objects or arrays
if ( copy && ( _.isObject(copy) || (copyIsArray = _.isArray(copy)) ) ) {
if ( copy && ( typeof copy === 'object' || (copyIsArray = Array.isArray(copy)) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && _.isArray(src) ? src : [];
clone = src && Array.isArray(src) ? src : [];

} else {
clone = src && _.isObject(src) ? src : {};
clone = src && typeof src === 'object' ? src : {};
}

// Never move original objects, clone them
Expand Down
30 changes: 15 additions & 15 deletions lib/utils/cssSections.js
Expand Up @@ -5,7 +5,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var utils = require('./common');
var commentsUtils = require('./comments');
var range = require('../assets/range');
Expand Down Expand Up @@ -68,7 +67,7 @@ define(function(require, exports, module) {
section = new CSSSection(section);
}

var lastChild = _.last(this.children);
var lastChild = utils.last(this.children);
if (lastChild) {
lastChild.nextSibling = section;
section.previousSibling = lastChild;
Expand Down Expand Up @@ -159,7 +158,7 @@ define(function(require, exports, module) {
out.push(this.range);
}

_.each(this.children, function(child) {
this.children.forEach(function(child) {
out = out.concat(child.allRanges());
});

Expand All @@ -177,7 +176,7 @@ define(function(require, exports, module) {
stringify: function(indent) {
indent = indent || '';
var out = '';
_.each(this.children, function(item) {
this.children.forEach(function(item) {
out += indent + item.name().replace(/\n/g, '\\n') + '\n';
out += item.stringify(indent + '--');
});
Expand All @@ -204,7 +203,7 @@ define(function(require, exports, module) {
var start = r.start;
var out = '';

_.each(this.children, function(child) {
this.children.forEach(function(child) {
out += source.substring(start, child.range.start);
start = child.range.end;
});
Expand All @@ -224,14 +223,15 @@ define(function(require, exports, module) {
content = this.sanitize(content);
var stream = stringStream(content);
var ranges = [], matchedRanges;
var self = this;

var saveRule = _.bind(function(r) {
var selRange = this.extractSelector(content, r.start);
var saveRule = function(r) {
var selRange = self.extractSelector(content, r.start);
var rule = range.create2(selRange.start, r.end);
rule._selectorEnd = selRange.end;
rule._contentStart = r.start;
ranges.push(rule);
}, this);
};

var ch;
while (ch = stream.next()) {
Expand All @@ -245,10 +245,10 @@ define(function(require, exports, module) {

if (ch == '{') {
matchedRanges = this.matchBracesRanges(content, stream.pos - 1);
_.each(matchedRanges, saveRule);
matchedRanges.forEach(saveRule);

if (matchedRanges.length) {
stream.pos = _.last(matchedRanges).end;
stream.pos = utils.last(matchedRanges).end;
continue;
}
}
Expand Down Expand Up @@ -375,15 +375,15 @@ define(function(require, exports, module) {
* @return {Range}
*/
matchEnclosingRule: function(content, pos) {
if (_.isString(content)) {
if (typeof content === 'string') {
content = this.findAllRules(content);
}

var rules = _.filter(content, function(r) {
var rules = content.filter(function(r) {
return r.inside(pos);
});

return _.last(rules);
return utils.last(rules);
},

/**
Expand Down Expand Up @@ -485,7 +485,7 @@ define(function(require, exports, module) {
};

var ctx = root;
_.each(rules, function(r) {
rules.forEach(function(r) {
ctx = insert(r, ctx);
});

Expand All @@ -501,7 +501,7 @@ define(function(require, exports, module) {
nestedSectionsInRule: function(rule) {
var offset = rule.valueRange(true).start;
var nestedSections = this.findAllRules(rule.valueRange().substring(rule.source));
_.each(nestedSections, function(section) {
nestedSections.forEach(function(section) {
section.start += offset;
section.end += offset;
section._selectorEnd += offset;
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/editor.js
Expand Up @@ -9,7 +9,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var utils = require('./common');
var resources = require('../assets/resources');

Expand Down Expand Up @@ -90,7 +89,7 @@ define(function(require, exports, module) {
* @return {String}
*/
normalize: function(text, options) {
options = _.extend({
options = utils.extend({
newline: resources.getNewline(),
indentation: resources.getVariable('indentation')
}, options);
Expand All @@ -104,7 +103,7 @@ define(function(require, exports, module) {

// normailze indentation if it’s not tabs
if (options.indentation !== '\t') {
lines = _.map(lines, function(line) {
lines = lines.map(function(line) {
return line.replace(reIndent, indent);
});
}
Expand Down
9 changes: 5 additions & 4 deletions lib/utils/template.js
Expand Up @@ -10,7 +10,6 @@ if (typeof module === 'object' && typeof define !== 'function') {
}

define(function(require, exports, module) {
var _ = require('lodash');
var stringStream = require('../assets/stringStream');
var utils = require('./common');

Expand All @@ -28,7 +27,9 @@ define(function(require, exports, module) {
}

args.push(utils.trim(stream.current()));
return _.compact(args);
return args.filter(function(a) {
return !!a;
});
}

function parseFunctionCall(str) {
Expand Down Expand Up @@ -59,7 +60,7 @@ define(function(require, exports, module) {
return arg.replace(/^(['"])(.+?)\1$/, '$2');
}

if (!_.isNaN(+arg)) {
if (!isNaN(+arg)) {
// a number
return +arg;
}
Expand All @@ -81,7 +82,7 @@ define(function(require, exports, module) {
match = utils.trim(match);
var fn = parseFunctionCall(match);
if (fn) {
var fnArgs = _.map(fn.args, function(arg) {
var fnArgs = fn.args.map(function(arg) {
return evalArg(arg, context);
});
return context[fn.name].apply(context, fnArgs);
Expand Down

0 comments on commit a0e6b5c

Please sign in to comment.