Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from nicholascloud/no-underscore
Browse files Browse the repository at this point in the history
no underscore, updated README, and fixed npm prepublish
  • Loading branch information
nicholascloud committed May 12, 2016
2 parents adc2abd + 26d2ee9 commit 0873221
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 44 deletions.
16 changes: 10 additions & 6 deletions README.md
Expand Up @@ -21,12 +21,16 @@ You might think I'm kidding about this but I've seen this code. It haunts my dre

I hate this so much that I created this library, `l33teral` (pronounced: `leet-er-all`) to stop this madness.

## Dependencies

None. (__Note__: l33teral < v3.0.0 depends on Underscore.js.)

## Usage

_l33teral will work in node.js, or in the browser with require.js, or in the browser as a direct include with script tags. All examples in the README are node.js examples, but the API is the same regardless of environment._

```javascript
var leet = require('l33teral');
var l33t = require('l33teral');

var myLiteral = {
data: {
Expand All @@ -48,7 +52,7 @@ var myLiteral = {
}
};

var myLeet = leet(myLiteral);
var myLeet = l33t(myLiteral);
// now use methods on myLeet
```

Expand Down Expand Up @@ -143,7 +147,7 @@ var user = {
startDate: '2013-01-01'
};

var leetUser = leet(user);
var leetUser = l33t(user);
leetUser.hasAllProperties('name', 'title', 'startDate');
// true
```
Expand All @@ -165,7 +169,7 @@ var user = {
startDate: '2013-01-01'
};

var leetUser = leet(user);
var leetUser = l33t(user);
leetUser.hasAnyProperties('dob', 'title', 'ssn');
// true
```
Expand Down Expand Up @@ -241,7 +245,7 @@ Deletes the key at the end of an object path.

```javascript
var mock = {foo: {bar: {baz: 'bin'}}};
var mockLeet = leet(mock);
var mockLeet = l33t(mock);
mockLeet.snip('foo.bar.baz');
assert.property(mock.foo, 'bar');
assert.notProperty(mock.foo.bar, 'baz');
Expand All @@ -257,7 +261,7 @@ Deletes the key at the end of an object path (like `snip`), and all keys along t

```javascript
var mock = {foo: {stop:1, bar: {baz: {bin: {} } } } };
var mockLeet = leet(mock);
var mockLeet = l33t(mock);
mockLeet.purge('foo.bar.baz.bin');
assert.property(mock, 'foo');
assert.property(mock.foo, 'stop');
Expand Down
3 changes: 1 addition & 2 deletions bower.json
@@ -1,6 +1,6 @@
{
"name": "l33teral",
"version": "2.1.0",
"version": "3.0.0",
"location": "git://github.com/nicholascloud/l33teral",
"author": "Nicholas Cloud",
"description": "functions to help deal with object literals",
Expand All @@ -10,7 +10,6 @@
"url": "git://github.com/nicholascloud/l33teral"
},
"dependencies": {
"underscore": "1.5.2"
},
"devDependencies": {},
"main": "./build/l33teral-latest.js",
Expand Down
45 changes: 28 additions & 17 deletions build/l33teral-latest.js
@@ -1,5 +1,5 @@
/**
* l33teral 2.1.0
* l33teral 3.0.0
*
* The MIT License (MIT)
*
Expand Down Expand Up @@ -30,22 +30,21 @@
// CommonJS (node) module
if (typeof module === 'object' && module.exports) {
return module.exports = factory(
require('underscore'),
global
);
}

// AMD module
if (typeof define === 'function' && define.amd) {
return define(['underscore'], function (_) {
return factory(_, global);
return define([], function () {
return factory(global);
});
}

// browser
global.l33teral = factory(global._, global);
global.l33teral = factory(global);

}(this, function (_, global, undefined) {
}(this, function (global, undefined) {

// use native otherwise polyfill
var create = Object.create || (function () {
Expand Down Expand Up @@ -84,13 +83,25 @@
return Object.prototype.toString.call(target) === '[object Null]';
};

var isUndefined = function (target) {
return Object.prototype.toString.call(target) === '[object Undefined]';
};

var isArray = Array.isArray ? Array.isArray : function (target) {
return Object.prototype.toString.call(target) === '[object Array]';
};

var isObject = function (target) {
return Object.prototype.toString.call(target) === '[object Object]';
};

/**
* L33teral constructor
* @param {Object} obj
* @constructor
*/
function L33teral(obj) {
this.__version__ = '2.1.0';
this.__version__ = '3.0.0';
this.obj = obj || {};
}

Expand Down Expand Up @@ -126,7 +137,7 @@
throw e;
}

if (_.isUndefined(value) && useDefault) {
if (isUndefined(value) && useDefault) {
return defaultValue;
}

Expand Down Expand Up @@ -176,11 +187,11 @@
var virginPaths = paths;
var hasDefaults = false;

if (_.isObject(paths) && !_.isArray(paths)) {
if (isObject(paths) && !isArray(paths)) {
paths = Object.keys(paths);
hasDefaults = true;
}
if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand Down Expand Up @@ -216,10 +227,10 @@
L33teral.prototype.extract = function (paths) {
var values = this.collect.apply(this, arguments);

if (_.isObject(paths) && !_.isArray(paths)) {
if (isObject(paths) && !isArray(paths)) {
paths = Object.keys(paths);
}
if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand Down Expand Up @@ -249,7 +260,7 @@
L33teral.prototype.hasAllProperties = function (properties) {
var self = this;

if (!_.isArray(properties)) {
if (!isArray(properties)) {
properties = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -266,7 +277,7 @@
L33teral.prototype.hasAnyProperties = function (properties) {
var self = this;

if (!_.isArray(properties)) {
if (!isArray(properties)) {
properties = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -283,7 +294,7 @@
L33teral.prototype.probeAll = function (paths) {
var self = this;

if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -300,7 +311,7 @@
L33teral.prototype.probeAny = function (paths) {
var self = this;

if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -318,7 +329,7 @@
L33teral.prototype.truthy = function (paths) {
var self = this;

if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand Down
41 changes: 26 additions & 15 deletions l33teral.js
Expand Up @@ -5,22 +5,21 @@
// CommonJS (node) module
if (typeof module === 'object' && module.exports) {
return module.exports = factory(
require('underscore'),
global
);
}

// AMD module
if (typeof define === 'function' && define.amd) {
return define(['underscore'], function (_) {
return factory(_, global);
return define([], function () {
return factory(global);
});
}

// browser
global.l33teral = factory(global._, global);
global.l33teral = factory(global);

}(this, function (_, global, undefined) {
}(this, function (global, undefined) {

// use native otherwise polyfill
var create = Object.create || (function () {
Expand Down Expand Up @@ -59,6 +58,18 @@
return Object.prototype.toString.call(target) === '[object Null]';
};

var isUndefined = function (target) {
return Object.prototype.toString.call(target) === '[object Undefined]';
};

var isArray = Array.isArray ? Array.isArray : function (target) {
return Object.prototype.toString.call(target) === '[object Array]';
};

var isObject = function (target) {
return Object.prototype.toString.call(target) === '[object Object]';
};

/**
* L33teral constructor
* @param {Object} obj
Expand Down Expand Up @@ -101,7 +112,7 @@
throw e;
}

if (_.isUndefined(value) && useDefault) {
if (isUndefined(value) && useDefault) {
return defaultValue;
}

Expand Down Expand Up @@ -151,11 +162,11 @@
var virginPaths = paths;
var hasDefaults = false;

if (_.isObject(paths) && !_.isArray(paths)) {
if (isObject(paths) && !isArray(paths)) {
paths = Object.keys(paths);
hasDefaults = true;
}
if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand Down Expand Up @@ -191,10 +202,10 @@
L33teral.prototype.extract = function (paths) {
var values = this.collect.apply(this, arguments);

if (_.isObject(paths) && !_.isArray(paths)) {
if (isObject(paths) && !isArray(paths)) {
paths = Object.keys(paths);
}
if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand Down Expand Up @@ -224,7 +235,7 @@
L33teral.prototype.hasAllProperties = function (properties) {
var self = this;

if (!_.isArray(properties)) {
if (!isArray(properties)) {
properties = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -241,7 +252,7 @@
L33teral.prototype.hasAnyProperties = function (properties) {
var self = this;

if (!_.isArray(properties)) {
if (!isArray(properties)) {
properties = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -258,7 +269,7 @@
L33teral.prototype.probeAll = function (paths) {
var self = this;

if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -275,7 +286,7 @@
L33teral.prototype.probeAny = function (paths) {
var self = this;

if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand All @@ -293,7 +304,7 @@
L33teral.prototype.truthy = function (paths) {
var self = this;

if (!_.isArray(paths)) {
if (!isArray(paths)) {
paths = Array.prototype.slice.call(arguments, 0);
}

Expand Down
6 changes: 2 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "l33teral",
"version": "2.1.0",
"version": "3.0.0",
"author": "Nicholas Cloud",
"description": "functions to help deal with object literals",
"keywords": ["literals", "objects", "utilities"],
Expand All @@ -9,7 +9,6 @@
"url": "git://github.com/nicholascloud/l33teral"
},
"dependencies": {
"underscore": "1.5.2"
},
"devDependencies": {
"async": "0.2.5",
Expand All @@ -21,7 +20,6 @@
},
"main": "./build/l33teral-latest",
"scripts": {
"test": "./node_modules/.bin/jake test --trace",
"prepublish": "./node_modules/.bin/jake build"
"test": "./node_modules/.bin/jake test --trace"
}
}

0 comments on commit 0873221

Please sign in to comment.