Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 12, 2012
0 parents commit 052e037
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
support
test
examples
*.sock
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

0.0.1 / 2010-01-03
==================

* Initial release
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

test:
@./node_modules/.bin/mocha \
--require should \
--reporter spec

.PHONY: test
62 changes: 62 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

# trim

Trims string whitespace.

## API

- [trim(str)](#trimstr)
- [.left(str)](#leftstr)
- [.right(str)](#rightstr)
<a name="" />

<a name="trimstr" />
### trim(str)
should trim leading / trailing whitespace.

```js
trim(' foo bar ').should.equal('foo bar');
trim('\n\n\nfoo bar\n\r\n\n').should.equal('foo bar');
```

<a name="leftstr" />
### .left(str)
should trim leading whitespace.

```js
trim.left(' foo bar ').should.equal('foo bar ');
```

<a name="rightstr" />
### .right(str)
should trim trailing whitespace.

```js
trim.right(' foo bar ').should.equal(' foo bar');
```


## License

(The MIT License)

Copyright (c) 2012 TJ Holowaychuk &lt;[email protected]&gt;

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "trim",
"version": "0.0.1",
"description": "Trim string whitespace",
"keywords": ["string", "trim"],
"scripts": ["index.js"]
}
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

exports = module.exports = trim;

function trim(str){
return str.replace(/^\s*|\s*$/g, '');
}

exports.left = function(str){
return str.replace(/^\s*/, '');
};

exports.right = function(str){
return str.replace(/\s*$/, '');
};
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "trim",
"version": "0.0.1",
"description": "Trim string whitespace",
"keywords": ["string", "trim"],
"author": "TJ Holowaychuk <[email protected]>",
"dependencies": {},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"main": "index"
}
21 changes: 21 additions & 0 deletions test/trim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

var trim = require('..');

describe('trim(str)', function(){
it('should trim leading / trailing whitespace', function(){
trim(' foo bar ').should.equal('foo bar');
trim('\n\n\nfoo bar\n\r\n\n').should.equal('foo bar');
})
})

describe('.left(str)', function(){
it('should trim leading whitespace', function(){
trim.left(' foo bar ').should.equal('foo bar ');
})
})

describe('.right(str)', function(){
it('should trim trailing whitespace', function(){
trim.right(' foo bar ').should.equal(' foo bar');
})
})

0 comments on commit 052e037

Please sign in to comment.