-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alessandro Giordo
committed
Feb 15, 2016
1 parent
c6cda3d
commit 2062c96
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function convert(time) { | ||
var hours = time.getHours() < 10 ? '0' + time.getHours() : time.getHours(), | ||
minutes = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes(), | ||
seconds = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds(), | ||
milliseconds = time.getMilliseconds() < 100 ? (time.getMilliseconds() < 10 ? '00' + time.getMilliseconds() : '0' + time.getMilliseconds()) : time.getMilliseconds(); | ||
|
||
return [hours, minutes, seconds].join(':') + ',' + milliseconds; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function dadFilter(str){ | ||
return str.replace(/^[, ]+|[, ]+$/g, "").replace(/,+/g, ","); | ||
} | ||
|
||
|
||
// or | ||
|
||
function dadFilter(str){ | ||
return str.replace(/,{2,}/g,",").replace(/,+( +)?$/,""); | ||
} | ||
|
||
function dadFilter(str) { | ||
return str.replace(/,,+/g, ",").replace(/,\s*$/, "") | ||
} | ||
|
||
function dadFilter(str){ | ||
return str.replace(/,+/g, ",").replace(/(,|\s)+$/, ""); | ||
} | ||
|
||
function dadFilter(str){ | ||
str = str.replace(/,+/g, ",") | ||
.trim() | ||
.replace(/,$/, ""); | ||
|
||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function toCamelCase(str){ | ||
return str.replace(/(_|-)([a-z])/gi, toUpperCase ); | ||
|
||
} | ||
function toUpperCase(str){ | ||
console.log(str[1]); | ||
return str[1].toUpperCase(); | ||
} | ||
|
||
// or | ||
|
||
function toCamelCase(str){ | ||
var regExp=/[-_]\w/ig; | ||
return str.replace(regExp,function(match){ | ||
return match.charAt(1).toUpperCase(); | ||
}); | ||
} | ||
|
||
// or | ||
|
||
function toCamelCase(str) { | ||
return str.replace(/[_-][A-Za-z]/g, function(match) {return match[1].toUpperCase();}); | ||
} | ||
|
||
// complex | ||
|
||
function toCamelCase(str){ | ||
var demarcs ='-_'; | ||
return str.split('').map(function(value,index,array){ | ||
if(demarcs.indexOf(value) > -1){ | ||
return ''; | ||
} else if (demarcs.indexOf(array[index - 1]) > -1){ | ||
return value.toUpperCase(); | ||
} else { | ||
return value; | ||
} | ||
}).join(''); | ||
} | ||
|
||
// or | ||
|
||
unction toCamelCase(str){ | ||
var strArray; | ||
if (str.indexOf('-') !== -1){ //if delineated by - | ||
strArray = str.split('-'); | ||
} else { | ||
strArray = str.split('_'); //if delineated by _ | ||
} | ||
var camelCase = strArray[0]; //keeps first word value as is | ||
for (var i=1, len=strArray.length; i < len; i++){ | ||
var capitalized = strArray[i].substr(0, 1).toUpperCase() + strArray[i].slice(1); | ||
camelCase += capitalized; | ||
} | ||
return camelCase; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import re | ||
def to_camel_case(str): | ||
return re.sub(r'(_|-)([a-zA-Z])', upper_repl , str) | ||
|
||
def upper_repl(match): | ||
return "" + match.group(2).upper() | ||
|
||
# no regex | ||
|
||
def to_camel_case(text): | ||
words = text.replace('_', '-').split('-') | ||
return words[0] + ''.join([x.title() for x in words[1:]]) | ||
|
||
# other regex | ||
|
||
from re import compile as reCompile | ||
|
||
PATTERN = reCompile(r'(?i)[-_]([a-z])') | ||
|
||
def to_camel_case(text): | ||
return PATTERN.sub(lambda m: m.group(1).upper(), text) |