Comparing version 1.0.0 to 1.1.0
module.exports = function (prototype, func) { | ||
// Don't override existing definitions | ||
if ( prototype[func.name] ) return; | ||
Object.defineProperty(prototype, func.name, { | ||
@@ -4,0 +8,0 @@ value: func, |
13
index.js
exports.install = function () { | ||
var package = require('./package.json') | ||
exports.load = function (modules) { | ||
if ( ! package.exjs ) { | ||
console.warning("[exjs] WARNING: No `exjs` key in package.json") | ||
if ( ! Array.isArray(modules) ) { | ||
console.error("[exjs] Error: The argument to `.load()` must be an array of strings.") | ||
return | ||
} | ||
if ( ! Array.isArray(package.exjs) ) { | ||
console.error("[exjs] Error: The value of `exjs` in package.json must be an array of strings.") | ||
return | ||
} | ||
package.exjs.forEach(function (ex) { | ||
modules.forEach(function (ex) { | ||
require('./' + ex) | ||
}) | ||
} |
{ | ||
"name": "exjs", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "README.md", | ||
@@ -9,11 +9,5 @@ "main": "index.js", | ||
}, | ||
"exjs": [ | ||
"function/papp", | ||
"function/pappRight", | ||
"function/throttle", | ||
"global/inspect" | ||
], | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
"license": "MIT" | ||
} |
@@ -27,16 +27,19 @@ # ExJS | ||
require('exjs').install() | ||
```js | ||
require('exjs').load([ | ||
"array/find", | ||
"date/format", | ||
"function/papp", | ||
"function/throttle", | ||
"global/inspect", | ||
// etc. | ||
]) | ||
``` | ||
Lastly, add the `exjs` key to your `package.json` with an array as its value. Example: | ||
Alternatively, you can load each file individually: | ||
```json | ||
{ | ||
"name": "my-awesome-project", | ||
..., | ||
"exjs": [ | ||
"function/papp", | ||
"function/throttle", | ||
"global/inspect", | ||
] | ||
} | ||
```js | ||
require('exjs/array/find') | ||
require('exjs/date/format') | ||
// etc. | ||
``` | ||
@@ -46,2 +49,15 @@ | ||
### `array/find` | ||
A polyfill based on the [MDN implementation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find#Polyfill). Useful when including for client apps targeting older browsers. | ||
### `date/format` | ||
A handly function for formatting JavaScript dates. [Click here](date/format.md) for full docs on usage. | ||
```javascript | ||
var myDate = new Date('3/20/2018'); | ||
myDate.format('M jS, Y') //=> "Mar 20th, 2018" | ||
``` | ||
### `function/papp` and `function/pappRight` | ||
@@ -48,0 +64,0 @@ |
27257
13
513
123