Skip to content

Commit 2a17997

Browse files
First commit
Got the basic Grunt workflow working with linting and Karma test runner testing the single util that is there so far.
0 parents  commit 2a17997

9 files changed

+23145
-0
lines changed

.gitattributes

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.gitignore

+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
46+
[Dd]ebug/
47+
[Rr]elease/
48+
x64/
49+
build/
50+
[Bb]in/
51+
[Oo]bj/
52+
53+
# MSTest test Results
54+
[Tt]est[Rr]esult*/
55+
[Bb]uild[Ll]og.*
56+
57+
*_i.c
58+
*_p.c
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.log
79+
*.scc
80+
81+
# Visual C++ cache files
82+
ipch/
83+
*.aps
84+
*.ncb
85+
*.opensdf
86+
*.sdf
87+
*.cachefile
88+
89+
# Visual Studio profiler
90+
*.psess
91+
*.vsp
92+
*.vspx
93+
94+
# Guidance Automation Toolkit
95+
*.gpState
96+
97+
# ReSharper is a .NET coding add-in
98+
_ReSharper*/
99+
*.[Rr]e[Ss]harper
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
*.ncrunch*
109+
.*crunch*.local.xml
110+
111+
# Installshield output folder
112+
[Ee]xpress/
113+
114+
# DocProject is a documentation generator add-in
115+
DocProject/buildhelp/
116+
DocProject/Help/*.HxT
117+
DocProject/Help/*.HxC
118+
DocProject/Help/*.hhc
119+
DocProject/Help/*.hhk
120+
DocProject/Help/*.hhp
121+
DocProject/Help/Html2
122+
DocProject/Help/html
123+
124+
# Click-Once directory
125+
publish/
126+
127+
# Publish Web Output
128+
*.Publish.xml
129+
*.pubxml
130+
131+
# NuGet Packages Directory
132+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133+
#packages/
134+
135+
# Windows Azure Build Output
136+
csx
137+
*.build.csdef
138+
139+
# Windows Store app package directory
140+
AppPackages/
141+
142+
# Others
143+
sql/
144+
*.Cache
145+
ClientBin/
146+
[Ss]tyle[Cc]op.*
147+
~$*
148+
*~
149+
*.dbmdl
150+
*.[Pp]ublish.xml
151+
*.pfx
152+
*.publishsettings
153+
154+
# RIA/Silverlight projects
155+
Generated_Code/
156+
157+
# Backup & report files from converting an old project file to a newer
158+
# Visual Studio version. Backup files are not needed, because we have git ;-)
159+
_UpgradeReport_Files/
160+
Backup*/
161+
UpgradeLog*.XML
162+
UpgradeLog*.htm
163+
164+
# SQL Server files
165+
App_Data/*.mdf
166+
App_Data/*.ldf
167+
168+
#############
169+
## Windows detritus
170+
#############
171+
172+
# Windows image file caches
173+
Thumbs.db
174+
ehthumbs.db
175+
176+
# Folder config file
177+
Desktop.ini
178+
179+
# Recycle Bin used on file shares
180+
$RECYCLE.BIN/
181+
182+
# Mac crap
183+
.DS_Store
184+
185+
186+
#############
187+
## Python
188+
#############
189+
190+
*.py[co]
191+
192+
# Packages
193+
*.egg
194+
*.egg-info
195+
dist/
196+
build/
197+
eggs/
198+
parts/
199+
var/
200+
sdist/
201+
develop-eggs/
202+
.installed.cfg
203+
204+
# Installer logs
205+
pip-log.txt
206+
207+
# Unit test / coverage reports
208+
.coverage
209+
.tox
210+
211+
#Translations
212+
*.mo
213+
214+
#Mr Developer
215+
.mr.developer.cfg
216+
217+
# custom
218+
.idea/
219+
node_modules/

Gruntfile.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = function(grunt) {
2+
3+
grunt.initConfig({
4+
pkg: grunt.file.readJSON('package.json'),
5+
6+
jshint: {
7+
src: [
8+
'src/**/*.js'
9+
],
10+
options: {
11+
curly: true,
12+
immed: true,
13+
newcap: true,
14+
noarg: true,
15+
sub: true,
16+
boss: true,
17+
eqnull: true
18+
}
19+
},
20+
21+
karma: {
22+
unit: {
23+
options: {
24+
files: [
25+
'vendor/angular/angular.js',
26+
'vendor/angular/angular-mocks.js',
27+
'src/angularUtils.js',
28+
'src/filters/ordinalDate/ordinalDate.js',
29+
'src/filters/ordinalDate/ordinalDate.spec.js'
30+
//'src/**/*.js'
31+
],
32+
frameworks: [ 'jasmine' ],
33+
plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-chrome-launcher', 'karma-phantomjs-launcher' ]
34+
35+
},
36+
singleRun: true,
37+
port: 9877
38+
}
39+
}
40+
41+
});
42+
43+
grunt.loadNpmTasks('grunt-karma');
44+
grunt.loadNpmTasks('grunt-contrib-jshint');
45+
46+
grunt.registerTask('default', ['jshint', 'karma']);
47+
48+
};

package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "angularUtils",
3+
"version": "0.0.0",
4+
"description": "A collection of re-usable AngularJS components",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Michael Bromley",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"grunt": "~0.4.2",
13+
"karma-script-launcher": "~0.1.0",
14+
"karma-chrome-launcher": "~0.1.2",
15+
"karma-firefox-launcher": "~0.1.3",
16+
"karma-html2js-preprocessor": "~0.1.0",
17+
"karma-jasmine": "~0.1.5",
18+
"karma-coffee-preprocessor": "~0.1.2",
19+
"requirejs": "~2.1.10",
20+
"karma-requirejs": "~0.2.1",
21+
"karma-phantomjs-launcher": "~0.1.1",
22+
"karma": "~0.10.9",
23+
"grunt-karma": "~0.6.2",
24+
"grunt-contrib-jshint": "~0.8.0"
25+
}
26+
}

src/angularUtils.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
angular.module( 'app', []);
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
angular.module( 'app' )
2+
3+
.filter('ordinalDate', function($filter) {
4+
5+
var getOrdinalSuffix = function(number) {
6+
var suffixes = ["'th'", "'st'", "'nd'", "'rd'"];
7+
var relevantDigits = (number < 30) ? number % 20 : number % 30;
8+
return (relevantDigits <= 3) ? suffixes[relevantDigits] : suffixes[0];
9+
};
10+
11+
/**
12+
* Look through the format string for any possible match for 'd'.
13+
* It needs to ignore 'dd' and also occurrences of the letter d inside
14+
* string such as "d 'day of' MM'.
15+
* @param format
16+
*/
17+
var getIndecesOfDayCharacter = function(format) {
18+
var dayRegex = /(?:'(?:[^']|'')*')|(?:d+)/g;
19+
var matchingIndices = [];
20+
var finishedLooking = false;
21+
22+
while(!finishedLooking) {
23+
var matches = dayRegex.exec(format);
24+
if (matches) {
25+
dayRegex.lastIndex = matches.index + matches[0].length;
26+
if (matches[0] === 'd') {
27+
matchingIndices.push(matches.index + 1);
28+
}
29+
} else {
30+
finishedLooking = true;
31+
}
32+
}
33+
34+
return matchingIndices;
35+
};
36+
37+
/**
38+
* Insert a string at a given index of another string
39+
* @param inputString
40+
* @param index
41+
* @param stringToInsert
42+
* @returns {string}
43+
*/
44+
var insertAtIndex = function(inputString, index, stringToInsert) {
45+
var partBeforeIndex = inputString.substring(0, index);
46+
var partAfterIndex = inputString.substring(index, inputString.length);
47+
return partBeforeIndex + stringToInsert + partAfterIndex;
48+
};
49+
50+
return function(timestamp, format) {
51+
var date = new Date(timestamp);
52+
var dayOfMonth = date.getDate();
53+
var suffix = getOrdinalSuffix(dayOfMonth);
54+
55+
var matchingIndices = getIndecesOfDayCharacter(format);
56+
57+
// now we to insert the suffix at the index(-ces) that we found
58+
for (var i = matchingIndices.length; i > 0; i --) {
59+
format = insertAtIndex(format, matchingIndices[i-1], suffix);
60+
}
61+
return $filter('date')(new Date(timestamp), format);
62+
};
63+
});

0 commit comments

Comments
 (0)