Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit f9e95a8362d881b42d8d623ed1e273b14ec22c08 0 parents
@tj tj authored
4 .gitignore
@@ -0,0 +1,4 @@
+components
+build
+node_module
+node_modules
16 Makefile
@@ -0,0 +1,16 @@
+
+build: components index.js
+ @component build --dev
+
+components:
+ @component install --dev
+
+clean:
+ rm -fr build components template.js
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --reporter spec
+
+.PHONY: clean test
20 Readme.md
@@ -0,0 +1,20 @@
+
+# humanize
+
+ Humanize a string
+
+## Installation
+
+ $ component install component/humanize
+
+## Example
+
+```js
+var humanize = require('humanize');
+humanize('maru-_the_cat.png');
+// => "Maru the cat"
+```
+
+# License
+
+ MIT
12 component.json
@@ -0,0 +1,12 @@
+{
+ "name": "humanize",
+ "repo": "component/humanize",
+ "description": "Humanize a string",
+ "version": "0.0.1",
+ "keywords": ["humanize", "string", "utility"],
+ "dependencies": {},
+ "development": {},
+ "scripts": [
+ "index.js"
+ ]
+}
12 index.js
@@ -0,0 +1,12 @@
+
+module.exports = function(str){
+ str = removeExtension(str);
+ str = str[0].toUpperCase() + str.slice(1);
+ return str.replace(/[\W_]+/g, ' ');
+};
+
+function removeExtension(str) {
+ var i = str.lastIndexOf('.');
+ if (-1 == i) return str;
+ return str.slice(0, i);
+}
11 package.json
@@ -0,0 +1,11 @@
+{
+ "name": "humanize-component",
+ "description": "Humanize a string",
+ "version": "0.0.1",
+ "keywords": ["humanize", "string", "utility"],
+ "dependencies": {},
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ }
+}
14 test/index.js
@@ -0,0 +1,14 @@
+
+var humanize = require('..');
+
+describe('humanize(str)', function(){
+ it('should translate punctuation to spaces', function(){
+ humanize('foo__bar_baz').should.equal('Foo bar baz');
+ humanize('Maru-the-cat').should.equal('Maru the cat');
+ })
+
+ it('should remove extensions', function(){
+ humanize('maru_the_cat.png').should.equal('Maru the cat');
+ humanize('maru_the.cat.png').should.equal('Maru the cat');
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.