Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Commit

Permalink
Fix CommonJS module.exports, edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanqing committed Aug 11, 2014
1 parent 8c84b7c commit 782bd60
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": true
"unused": true,
"globals": {
"define": true
}
}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# Jaunt.js [![Build Status](https://img.shields.io/travis/yuanqing/jaunt.svg?style=flat)](https://travis-ci.org/yuanqing/jaunt) [![Coverage Status](https://img.shields.io/coveralls/yuanqing/jaunt.svg?style=flat)](https://coveralls.io/r/yuanqing/jaunt)

> Access a value in an object or array given a dot-delimited string.
> Access a value in an object or array using a dot-delimited string.
## Usage

```js
var obj = {
foo: {
bar: [
{ baz: 'Hello' },
{ qux: 'World' }
]
bar: ['Hello', 'World']
}
};

Expand Down
25 changes: 11 additions & 14 deletions dist/jaunt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/* globals define */
var f = function () {
(function (root, factory) {
/* istanbul ignore next */
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.jaunt = factory();
}
})(this, function() {

'use strict';

Expand All @@ -22,15 +30,4 @@ var f = function () {
return obj;
};

};

/* istanbul ignore next */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory;
} else {
root.jaunt = factory(root);
}
})(this, f);
});
2 changes: 1 addition & 1 deletion dist/jaunt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ gulp.task('default', [
'lint',
'dist',
'test'
]);
]);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jaunt",
"version": "1.0.0",
"description": "Access a value in an object or array given a dot-delimited string.",
"version": "1.0.1",
"description": "Access a value in an object or array using a dot-delimited string.",
"author": "Lim Yuan Qing",
"license": "MIT",
"repository": {
Expand Down
25 changes: 11 additions & 14 deletions src/jaunt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/* globals define */
var f = function () {
(function (root, factory) {
/* istanbul ignore next */
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.jaunt = factory();
}
})(this, function() {

'use strict';

Expand All @@ -22,15 +30,4 @@ var f = function () {
return obj;
};

};

/* istanbul ignore next */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory;
} else {
root.jaunt = factory(root);
}
})(this, f);
});
2 changes: 1 addition & 1 deletion test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ module.exports = function (config) {
dir: 'coverage/'
}
});
};
};
11 changes: 5 additions & 6 deletions test/spec/jaunt.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals describe, it, expect, jaunt */

describe('jaunt', function() {

var obj = {
Expand All @@ -15,31 +14,31 @@ describe('jaunt', function() {
expect(jaunt(obj, 'foo')).toBe(obj.foo);
expect(jaunt(obj, 'foo.bar')).toBe(obj.foo.bar);
expect(jaunt(obj, 'foo.bar.0')).toBe(obj.foo.bar[0]);
expect(jaunt(obj, 'foo.bar.1')).toBe(obj.foo.bar[1]);
expect(jaunt(obj, ' foo . bar . 0 ')).toBe(obj.foo.bar[0]); // whitespace is trimmed
expect(jaunt(obj, 'foo.bar.1.qux')).toBe(obj.foo.bar[1].qux);
});

it('returns undefined if the `path` string is invalid', function() {
expect(jaunt(obj, '')).toBe(undefined);
expect(jaunt(obj, 'invalid')).toBe(undefined);
expect(jaunt(obj, 'foo.invalid')).toBe(undefined);
expect(jaunt(obj, 'foo.bar.0.invalid')).toBe(undefined);
expect(jaunt(obj, 'foo.bar.0.baz.invalid')).toBe(undefined);
});

it('returns a value in `obj` if `path` is an array', function() {
expect(jaunt(obj, ['foo'])).toBe(obj.foo);
expect(jaunt(obj, ['foo', 'bar'])).toBe(obj.foo.bar);
expect(jaunt(obj, ['foo', 'bar', 0])).toBe(obj.foo.bar[0]);
expect(jaunt(obj, ['foo', 'bar', 1])).toBe(obj.foo.bar[1]);
expect(jaunt(obj, [' foo ', ' bar ', 0])).toBe(obj.foo.bar[0]); // whitespace is trimmed
expect(jaunt(obj, ['foo', 'bar', 1, 'qux'])).toBe(obj.foo.bar[1].qux);
});

it('returns undefined if the `path` array is invalid', function() {
expect(jaunt(obj, [])).toBe(undefined);
expect(jaunt(obj, [''])).toBe(undefined);
expect(jaunt(obj, ['invalid'])).toBe(undefined);
expect(jaunt(obj, ['foo', 'invalid'])).toBe(undefined);
expect(jaunt(obj, ['foo', 'bar', 0, 'invalid'])).toBe(undefined);
expect(jaunt(obj, ['foo', 'bar', 0, 'baz', 'invalid'])).toBe(undefined);
});

});
});

0 comments on commit 782bd60

Please sign in to comment.