Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3ee771a

Browse files
committed
refactor(*): DRY camelcase method
remove the camelCase function from jqLite and use the one from the public API
1 parent edb1c95 commit 3ee771a

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

src/jqLite.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,6 @@ function jqNextId() { return ++jqId; }
125125
var MOUSE_EVENT_MAP= { mouseleave: "mouseout", mouseenter: "mouseover"};
126126
var jqLiteMinErr = minErr('jqLite');
127127

128-
/**
129-
* Converts snake_case to camelCase.
130-
* Also there is special case for Moz prefix starting with upper case letter.
131-
* @param name Name to normalize
132-
*/
133-
function camelCase(name) {
134-
return name.
135-
replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
136-
return offset ? letter.toUpperCase() : letter;
137-
}).
138-
replace(MOZ_HACK_REGEXP, 'Moz$1');
139-
}
140-
141128
var SINGLE_TAG_REGEXP = /^<(\w+)\s*\/?>(?:<\/\1>|)$/;
142129
var HTML_REGEXP = /<|&#?\w+;/;
143130
var TAG_NAME_REGEXP = /<([\w:]+)/;
@@ -575,7 +562,7 @@ forEach({
575562
hasClass: jqLiteHasClass,
576563

577564
css: function(element, name, value) {
578-
name = camelCase(name);
565+
name = camelcase(name);
579566

580567
if (isDefined(value)) {
581568
element.style[name] = value;

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ var PREFIX_REGEXP = /^((?:x|data)[\:\-_])/i;
24952495
* @param name Name to normalize
24962496
*/
24972497
function directiveNormalize(name) {
2498-
return camelCase(name.replace(PREFIX_REGEXP, ''));
2498+
return camelcase(name.replace(PREFIX_REGEXP, ''));
24992499
}
25002500

25012501
/**

src/ng/sce.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1033,13 +1033,13 @@ function $SceProvider() {
10331033

10341034
forEach(SCE_CONTEXTS, function(enumValue, name) {
10351035
var lName = lowercase(name);
1036-
sce[camelCase("parse_as_" + lName)] = function(expr) {
1036+
sce[camelcase("parse_as_" + lName)] = function(expr) {
10371037
return parse(enumValue, expr);
10381038
};
1039-
sce[camelCase("get_trusted_" + lName)] = function(value) {
1039+
sce[camelcase("get_trusted_" + lName)] = function(value) {
10401040
return getTrusted(enumValue, value);
10411041
};
1042-
sce[camelCase("trust_as_" + lName)] = function(value) {
1042+
sce[camelcase("trust_as_" + lName)] = function(value) {
10431043
return trustAs(enumValue, value);
10441044
};
10451045
});

test/jqLiteSpec.js

-24
Original file line numberDiff line numberDiff line change
@@ -1965,30 +1965,6 @@ describe('jqLite', function() {
19651965
});
19661966
});
19671967

1968-
1969-
describe('camelCase', function() {
1970-
it('should leave non-dashed strings alone', function() {
1971-
expect(camelCase('foo')).toBe('foo');
1972-
expect(camelCase('')).toBe('');
1973-
expect(camelCase('fooBar')).toBe('fooBar');
1974-
});
1975-
1976-
1977-
it('should covert dash-separated strings to camelCase', function() {
1978-
expect(camelCase('foo-bar')).toBe('fooBar');
1979-
expect(camelCase('foo-bar-baz')).toBe('fooBarBaz');
1980-
expect(camelCase('foo:bar_baz')).toBe('fooBarBaz');
1981-
});
1982-
1983-
1984-
it('should covert browser specific css properties', function() {
1985-
expect(camelCase('-moz-foo-bar')).toBe('MozFooBar');
1986-
expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar');
1987-
expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar');
1988-
});
1989-
});
1990-
1991-
19921968
describe('jqLiteDocumentLoaded', function() {
19931969

19941970
function createMockWindow(readyState) {

0 commit comments

Comments
 (0)