Skip to content

Commit

Permalink
change val names in Readme and test
Browse files Browse the repository at this point in the history
  • Loading branch information
retrofox committed Sep 26, 2012
1 parent 4f043a9 commit e40a031
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

0.0.1 / 2012-09-26
==================

* first aprox
* initial init
63 changes: 39 additions & 24 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@

# to-object
# toObject

to-object utility
toObject array utility. Creats an object with the given array.

## Installation

$ component install retrofox/to-object

## API

### to-object(array)
### toObject(array)

Returns an `object`

```js
var toObject = require('to-object');

var heroes = [
{
first: 'Manuel',
last: 'Belgrano'
},
{
first: 'Juan Jose',
last: 'San Martin'
},
{
first: 'Hipolito',
last: 'Bouchard'
},
{
first: 'Martin Miguel',
last: 'de Güemes'
}
];
{
first: 'Manuel',
last: 'Belgrano'
},
{
first: 'Juan Jose',
last: 'San Martin'
},
{
first: 'Hipolito',
last: 'Bouchard'
},
{
first: 'Martin Miguel',
last: 'de Güemes'
}
];

// returns an object with number key
var heroesObject = to-object(heroes);
var heroesObject = toObject(heroes);

// return an object with first value as key
var heroesObject = to-object(heroes, 'first');
var heroesObject = toObject(heroes, 'first');

// return an object with first value as key and remove the key
var heroesObject = to-object(heroes, 'first', true);
var heroesObject = toObject(heroes, 'first', true);

// return an object with first value modified as key
var heroesObject = to-object(heroes, 'first', function(key){
var heroesObject = toObject(heroes, 'first', function(key){
return key.toLowerCase().replace(/\s/i, '_');
});
```

## Running tests

Make sure dependencies are installed:

```
$ npm install
```

Then run:

```
$ make test
```

# License

(The MIT License)
Expand Down
10 changes: 5 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var toObj = require('../');
var toObject = require('../');

function getArray(){
return [
Expand All @@ -23,7 +23,7 @@ function getArray(){

describe('toObject(arr)', function(){
describe('should return an object with number key', function(){
var obj = toObj(getArray());
var obj = toObject(getArray());
obj.should.eql({
0: { first: 'Manuel', last: 'Belgrano' },
1: { first: 'Juan Jose', last: 'San Martin' },
Expand All @@ -35,7 +35,7 @@ describe('toObject(arr)', function(){

describe('toObject(arr, key)', function(){
describe('should return an object with first value as key', function(){
var obj = toObj(getArray(), 'first');
var obj = toObject(getArray(), 'first');
obj.should.eql({
'Manuel': { first: 'Manuel', last: 'Belgrano' },
'Juan Jose': { first: 'Juan Jose', last: 'San Martin' },
Expand All @@ -47,7 +47,7 @@ describe('toObject(arr, key)', function(){

describe('toObject(arr, key, removeKeyItem)', function(){
describe('should return an object removing the key', function(){
var obj = toObj(getArray(), 'first', true);
var obj = toObject(getArray(), 'first', true);
obj.should.eql({
'Manuel': { last: 'Belgrano' },
'Juan Jose': { last: 'San Martin' },
Expand All @@ -59,7 +59,7 @@ describe('toObject(arr, key, removeKeyItem)', function(){

describe('toObject(arr, key, fn)', function(){
describe('should return an object changing the key using the callback', function(){
var obj = toObj(getArray(), 'first', function(key){
var obj = toObject(getArray(), 'first', function(key){
return key.toLowerCase().replace(/\s/i, '_');
});
obj.should.eql({
Expand Down

0 comments on commit e40a031

Please sign in to comment.