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
// MM/DD/YYYY, M/D/YYYY | |
const dateRegex = new RegExp(/^(\d{2}|\d{1})\/(\d{2}|\d{1})\/\d{4}$/); | |
// HH:MM am/pm, HH:MM AM/PM | |
const timeRegex = new RegExp(/\b((1[0-2]|0?[1-9]):([0-5][0-9]) ([AaPp][Mm]))/); | |
// Convert date and time strings to a Date object | |
function stringsToDate(dateStr, timeStr) { | |
if (!dateRegex.test(dateStr) || !timeRegex.test(timeStr)) { | |
return null; | |
} |
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
function capitalize(str) { | |
// Capitalize first letter of string | |
return str.charAt(0).toUpperCase() + str.slice(1); | |
} |
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
// MM/DD/YYYY, M/D/YYYY | |
const DATE_REGEX = new RegExp(/^(\d{2}|\d{1})\/(\d{2}|\d{1})\/\d{4}$/); | |
export { DATE_REGEX }; |
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
function slugify(text) { | |
const a = 'ãàáäâèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'; | |
const b = 'aaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'; | |
const p = new RegExp(a.split('').join('|'), 'g'); | |
return text.toString().toLowerCase() | |
.replace(/\s+/g, '-') // Replace spaces with - | |
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special chars | |
.replace(/&/g, '-and-') // Replace & with 'and' | |
.replace(/[^\w\-]+/g, '') // Remove all non-word chars |
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
/** | |
* Generate a random date between now and one year from now | |
* With a time between 7am and 8pm | |
* Minutes on the full hour :00 | |
* @returns {Date} | |
*/ | |
function randomDate() { | |
var start = new Date(); | |
var end = new Date(new Date().setFullYear(start.getFullYear() + 1)); | |
var date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime())); |
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
/** | |
* Get ordinal value | |
* | |
* @param n {number} if a string is provided, % will attempt to convert to number | |
* @returns {string} th, st, nd, rd | |
*/ | |
function getOrdinal(n) { | |
var ordArr = ['th', 'st', 'nd', 'rd']; | |
var modulus = n % 100; |
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
/*-- Media query variables --*/ | |
$mq-small: 'media and (max-width: 767px)'; | |
$mq-large: 'media and (min-width: 768px)'; | |
/*-- Media query mixin --*/ | |
@mixin mq($mqString) { | |
@media #{$mqString} { | |
@content; |
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
// Firefox uses HTML, Webkit uses body, iOS uses pageYOffset, therefore check for any: | |
var scrollPosition = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset; |
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
myApp.filter('noWidows',function(){ | |
return function(input){ | |
var wordArray = input.split(' '); | |
if (wordArray.length > 1) { | |
wordArray[wordArray.length - 2] += ' ' + wordArray[wordArray.length - 1]; | |
wordArray.pop(); | |
return wordArray.join(' '); | |
} else { |
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
$scope.orderByValue = function(value) { | |
return value; | |
} | |
// usage: ng-repeat="item in items | orderBy:orderByValue" |