Comparing version 0.8.0 to 0.9.0
var arrSlice = Array.prototype.slice; | ||
/** | ||
@@ -9,3 +7,20 @@ * Create slice of source array or array-like object | ||
function slice(arr, start, end){ | ||
return arrSlice.call(arr, start, end); | ||
if (start == null) { | ||
start = 0; | ||
} else if (start < 0) { | ||
start = Math.max(arr.length + start, 0); | ||
} | ||
if (end == null) { | ||
end = arr.length; | ||
} else if (end < 0) { | ||
end = Math.max(arr.length + end, 0); | ||
} | ||
var result = []; | ||
while (start < end) { | ||
result.push(arr[start++]); | ||
} | ||
return result; | ||
} | ||
@@ -12,0 +27,0 @@ |
mout changelog | ||
============== | ||
v0.9.0 (2014/02/04) | ||
------------------- | ||
- add `date/quarter`; | ||
- add `function/constant`; | ||
- add `random/randBool`; | ||
- add un-padded 12-hour (`%l`) to `date/strftime`; | ||
- fix `array/slice` on IE < 9 by using a custom implementation. | ||
- fix `object/forIn` iteration for IE8 constructor property; | ||
- fix `string/removeNonWord` to cover more chars; | ||
- improve `lang/inheritPrototype` by returning the `prototype`; | ||
- improve `string/repeat` performance; | ||
- improve `string/unescapeHtml` by acceptin leading zeros for `'`; | ||
v0.8.0 (2013/11/22) | ||
@@ -5,0 +20,0 @@ ------------------- |
@@ -12,2 +12,3 @@ | ||
'parseIso' : require('./date/parseIso'), | ||
'quarter' : require('./date/quarter'), | ||
'startOf' : require('./date/startOf'), | ||
@@ -14,0 +15,0 @@ 'strftime' : require('./date/strftime'), |
var pad = require('../number/pad'); | ||
var lpad = require('../string/lpad'); | ||
var i18n = require('./i18n_'); | ||
@@ -72,2 +73,4 @@ var dayOfTheYear = require('./dayOfTheYear'); | ||
return pad(dayOfTheYear(date), 3); | ||
case 'l': | ||
return lpad(date.getHours() % 12, 2); | ||
case 'L': | ||
@@ -74,0 +77,0 @@ return pad(date.getMilliseconds(), 3); |
@@ -673,3 +673,4 @@ # array # | ||
If `start` is omitted, it will start at `0`. If `end` is omitted, it will used | ||
the last index of the array. | ||
the last index of the array. If `start` or `end` is negative, it is used as an | ||
offset from the end of the array. | ||
@@ -685,2 +686,4 @@ It will also convert array-like objects to arrays. | ||
slice({ length: 2, 0: 'a', 1: 'b' }); // ['a', 'b'] | ||
slice([1, 2, 3], 0, -1); // [1, 2] | ||
slice([1, 2, 3], -2); // [2, 3] | ||
``` | ||
@@ -687,0 +690,0 @@ |
@@ -102,3 +102,14 @@ # date # | ||
## quarter(date):Number | ||
Get a number between 1 to 4 that represents the quarter of the year. | ||
```js | ||
quarter(new Date(2013, 1, 19)); // 1 | ||
quarter(new Date(2013, 4, 12)); // 2 | ||
quarter(new Date(2013, 7, 25)); // 3 | ||
quarter(new Date(2013, 10, 8)); // 4 | ||
``` | ||
## startOf(date, period):Date | ||
@@ -144,2 +155,3 @@ | ||
<dt>%j</dt><dd> day of the year as a decimal number [001..366].</dd> | ||
<dt>%l</dt><dd> hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank</dd> | ||
<dt>%L</dt><dd> zero-padded milliseconds [000..999]</dd> | ||
@@ -146,0 +158,0 @@ <dt>%m</dt><dd> month as a decimal number [01..12].</dd> |
@@ -23,10 +23,17 @@ # function # | ||
var callback = after(onLoaded, 1000); | ||
loadImages(callback); | ||
function onLoaded() { | ||
... | ||
function onLoaded(){ | ||
console.log('loaded'); | ||
} | ||
``` | ||
You can also cancel de delayed call by simply using the native `clearTimeout` | ||
method (like a regular `setTimeout` call). | ||
```js | ||
var timeoutId = callback(); | ||
// onLoaded won't be called since it was canceled before the 1000ms delay | ||
clearTimeout(timeoutId); | ||
``` | ||
### Arguments: | ||
@@ -74,2 +81,19 @@ | ||
## constant(value):Function | ||
Returns a new function that will always return `value` when called. | ||
```js | ||
var f = constant('foo'); | ||
f(); // 'foo' | ||
// Provided arguments are ignored; value is always returned | ||
f(1); // 'foo' | ||
f = constant({ foo: 'bar' }); | ||
f(); // { foo: 'bar' } | ||
``` | ||
## debounce(fn, delay[, isAsap]):Function | ||
@@ -76,0 +100,0 @@ |
@@ -135,3 +135,3 @@ # lang # | ||
## inheritPrototype(childCtor, parentCtor):void | ||
## inheritPrototype(childCtor, parentCtor):Object | ||
@@ -142,2 +142,4 @@ Inherit the prototype methods from one constructor into another. | ||
It returns the the `childCtor.prototype` for convenience. | ||
```js | ||
@@ -157,4 +159,7 @@ function Foo(name){ | ||
//should be called before calling constructor | ||
inheritPrototype(Bar, Foo); | ||
var proto = inheritPrototype(Bar, Foo); | ||
// for convenience we return the new prototype object | ||
console.log(proto === Bar.prototype); // true | ||
var myObj = new Bar('lorem ipsum'); | ||
@@ -161,0 +166,0 @@ myObj.getName(); // "lorem ipsum" |
@@ -93,3 +93,17 @@ # random # | ||
## randBool():Boolean | ||
Returns a random Boolean (`true` or `false`). | ||
Since this is very common it makes sense to abstract it into a discrete method. | ||
### Example: | ||
```js | ||
randBool(); // true | ||
randBool(); // false | ||
``` | ||
## randHex([size]):String | ||
@@ -96,0 +110,0 @@ |
@@ -68,4 +68,12 @@ # string # | ||
Escapes HTML special chars (`>`, `<`, `&`, `"`, `'`). | ||
Escapes the following special characters for use in HTML: | ||
* `&` becomes `&` | ||
* `<` becomes `<` | ||
* `>` becomes `>` | ||
* `'` becomes `'` | ||
* `"` becomes `"` | ||
No other characters are escaped. To HTML-escape other characters as well, use a third-party library like [_he_](http://mths.be/he). | ||
See: [`unescapeHtml()`](#unescapeHtml) | ||
@@ -546,4 +554,13 @@ | ||
Unescapes HTML special chars (`>`, `<`, `&`, `"`, `'`). | ||
Unescapes the following HTML character references back into the raw symbol they map to: | ||
* `&` becomes `&` | ||
* `<` becomes `<` | ||
* `>` becomes `>` | ||
* `'` becomes `'` | ||
* `"` becomes `"` | ||
No other HTML character references are unescaped. To HTML-unescape other entities as well, use a third-party library like [_he_](http://mths.be/he). | ||
See: [`escapeHtml()`](#escapeHtml) | ||
@@ -550,0 +567,0 @@ |
@@ -9,2 +9,3 @@ | ||
'compose' : require('./function/compose'), | ||
'constant' : require('./function/constant'), | ||
'debounce' : require('./function/debounce'), | ||
@@ -11,0 +12,0 @@ 'func' : require('./function/func'), |
/**@license | ||
* mout v0.8.0 | http://moutjs.com | MIT license | ||
* mout v0.9.0 | http://moutjs.com | MIT license | ||
*/ | ||
@@ -9,3 +9,3 @@ | ||
module.exports = { | ||
'VERSION' : '0.8.0', | ||
'VERSION' : '0.9.0', | ||
'array' : require('./array'), | ||
@@ -12,0 +12,0 @@ 'collection' : require('./collection'), |
@@ -14,2 +14,3 @@ var createObject = require('./createObject'); | ||
child.super_ = parent; | ||
return p; | ||
} | ||
@@ -16,0 +17,0 @@ |
@@ -0,3 +1,3 @@ | ||
var hasOwn = require('./hasOwn'); | ||
var _hasDontEnumBug, | ||
@@ -43,7 +43,21 @@ _dontEnums; | ||
if (_hasDontEnumBug) { | ||
var ctor = obj.constructor, | ||
isProto = !!ctor && obj === ctor.prototype; | ||
while (key = _dontEnums[i++]) { | ||
// since we aren't using hasOwn check we need to make sure the | ||
// property was overwritten | ||
if (obj[key] !== Object.prototype[key]) { | ||
// For constructor, if it is a prototype object the constructor | ||
// is always non-enumerable unless defined otherwise (and | ||
// enumerated above). For non-prototype objects, it will have | ||
// to be defined on this object, since it cannot be defined on | ||
// any prototype objects. | ||
// | ||
// For other [[DontEnum]] properties, check if the value is | ||
// different than Object prototype value. | ||
if ( | ||
(key !== 'constructor' || | ||
(!isProto && hasOwn(obj, key))) && | ||
obj[key] !== Object.prototype[key] | ||
) { | ||
if (exec(fn, obj, key, thisObj) === false) { | ||
@@ -50,0 +64,0 @@ break; |
{ | ||
"name": "mout", | ||
"description": "Modular Utilities", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"homepage": "http://moutjs.com/", | ||
@@ -54,3 +54,4 @@ "contributors": [ | ||
"jshint": "2.x", | ||
"rimraf": "~2.2.2" | ||
"rimraf": "~2.2.2", | ||
"regenerate": "~0.5.4" | ||
}, | ||
@@ -57,0 +58,0 @@ "testling": { |
@@ -10,2 +10,3 @@ | ||
'randBit' : require('./random/randBit'), | ||
'randBool' : require('./random/randBool'), | ||
'randHex' : require('./random/randHex'), | ||
@@ -12,0 +13,0 @@ 'randInt' : require('./random/randInt'), |
@@ -1,2 +0,2 @@ | ||
var random = require('./random'); | ||
var randBool = require('./randBool'); | ||
@@ -7,3 +7,3 @@ /** | ||
function randomBit() { | ||
return random() > 0.5? 1 : 0; | ||
return randBool()? 1 : 0; | ||
} | ||
@@ -10,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
var random = require('./random'); | ||
var randBool = require('./randBool'); | ||
@@ -7,3 +7,3 @@ /** | ||
function randomSign() { | ||
return random() > 0.5? 1 : -1; | ||
return randBool()? 1 : -1; | ||
} | ||
@@ -10,0 +10,0 @@ |
define(function () { | ||
var arrSlice = Array.prototype.slice; | ||
/** | ||
@@ -9,3 +7,20 @@ * Create slice of source array or array-like object | ||
function slice(arr, start, end){ | ||
return arrSlice.call(arr, start, end); | ||
if (start == null) { | ||
start = 0; | ||
} else if (start < 0) { | ||
start = Math.max(arr.length + start, 0); | ||
} | ||
if (end == null) { | ||
end = arr.length; | ||
} else if (end < 0) { | ||
end = Math.max(arr.length + end, 0); | ||
} | ||
var result = []; | ||
while (start < end) { | ||
result.push(arr[start++]); | ||
} | ||
return result; | ||
} | ||
@@ -12,0 +27,0 @@ |
@@ -12,2 +12,3 @@ define(function(require){ | ||
'parseIso' : require('./date/parseIso'), | ||
'quarter' : require('./date/quarter'), | ||
'startOf' : require('./date/startOf'), | ||
@@ -14,0 +15,0 @@ 'strftime' : require('./date/strftime'), |
@@ -1,2 +0,2 @@ | ||
define(['../number/pad', './i18n_', './dayOfTheYear', './timezoneOffset', './timezoneAbbr', './weekOfTheYear'], function (pad, i18n, dayOfTheYear, timezoneOffset, timezoneAbbr, weekOfTheYear) { | ||
define(['../number/pad', '../string/lpad', './i18n_', './dayOfTheYear', './timezoneOffset', './timezoneAbbr', './weekOfTheYear'], function (pad, lpad, i18n, dayOfTheYear, timezoneOffset, timezoneAbbr, weekOfTheYear) { | ||
@@ -67,2 +67,4 @@ var _combinations = { | ||
return pad(dayOfTheYear(date), 3); | ||
case 'l': | ||
return lpad(date.getHours() % 12, 2); | ||
case 'L': | ||
@@ -69,0 +71,0 @@ return pad(date.getMilliseconds(), 3); |
@@ -9,2 +9,3 @@ define(function(require){ | ||
'compose' : require('./function/compose'), | ||
'constant' : require('./function/constant'), | ||
'debounce' : require('./function/debounce'), | ||
@@ -11,0 +12,0 @@ 'func' : require('./function/func'), |
/**@license | ||
* mout v0.8.0 | http://moutjs.com | MIT license | ||
* mout v0.9.0 | http://moutjs.com | MIT license | ||
*/ | ||
@@ -9,3 +9,3 @@ define(function(require){ | ||
return { | ||
'VERSION' : '0.8.0', | ||
'VERSION' : '0.9.0', | ||
'array' : require('./array'), | ||
@@ -12,0 +12,0 @@ 'collection' : require('./collection'), |
@@ -14,2 +14,3 @@ define(['./createObject'], function(createObject){ | ||
child.super_ = parent; | ||
return p; | ||
} | ||
@@ -16,0 +17,0 @@ |
@@ -1,2 +0,2 @@ | ||
define(function () { | ||
define(['./hasOwn'], function (hasOwn) { | ||
@@ -43,7 +43,21 @@ var _hasDontEnumBug, | ||
if (_hasDontEnumBug) { | ||
var ctor = obj.constructor, | ||
isProto = !!ctor && obj === ctor.prototype; | ||
while (key = _dontEnums[i++]) { | ||
// since we aren't using hasOwn check we need to make sure the | ||
// property was overwritten | ||
if (obj[key] !== Object.prototype[key]) { | ||
// For constructor, if it is a prototype object the constructor | ||
// is always non-enumerable unless defined otherwise (and | ||
// enumerated above). For non-prototype objects, it will have | ||
// to be defined on this object, since it cannot be defined on | ||
// any prototype objects. | ||
// | ||
// For other [[DontEnum]] properties, check if the value is | ||
// different than Object prototype value. | ||
if ( | ||
(key !== 'constructor' || | ||
(!isProto && hasOwn(obj, key))) && | ||
obj[key] !== Object.prototype[key] | ||
) { | ||
if (exec(fn, obj, key, thisObj) === false) { | ||
@@ -50,0 +64,0 @@ break; |
@@ -10,2 +10,3 @@ define(function(require){ | ||
'randBit' : require('./random/randBit'), | ||
'randBool' : require('./random/randBool'), | ||
'randHex' : require('./random/randHex'), | ||
@@ -12,0 +13,0 @@ 'randInt' : require('./random/randInt'), |
@@ -1,2 +0,2 @@ | ||
define(['./random'], function (random) { | ||
define(['./randBool'], function (randBool) { | ||
@@ -7,3 +7,3 @@ /** | ||
function randomBit() { | ||
return random() > 0.5? 1 : 0; | ||
return randBool()? 1 : 0; | ||
} | ||
@@ -10,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
define(['./random'], function (random) { | ||
define(['./randBool'], function (randBool) { | ||
@@ -7,3 +7,3 @@ /** | ||
function randomSign() { | ||
return random() > 0.5? 1 : -1; | ||
return randBool()? 1 : -1; | ||
} | ||
@@ -10,0 +10,0 @@ |
define(['../lang/toString'], function(toString){ | ||
// This pattern is generated by the _build/pattern-removeNonWord.js script | ||
var PATTERN = /[^\x20\x2D0-9A-Z\x5Fa-z\xC0-\xD6\xD8-\xF6\xF8-\xFF]/g; | ||
/** | ||
@@ -7,3 +10,3 @@ * Remove non-word chars. | ||
str = toString(str); | ||
return str.replace(/[^0-9a-zA-Z\xC0-\xFF \-_]/g, ''); | ||
return str.replace(PATTERN, ''); | ||
} | ||
@@ -10,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
define(['../lang/toString'], function(toString){ | ||
define(['../lang/toString', '../number/toInt'], function(toString, toInt){ | ||
@@ -7,4 +7,16 @@ /** | ||
function repeat(str, n){ | ||
var result = ''; | ||
str = toString(str); | ||
return (new Array(n + 1)).join(str); | ||
n = toInt(n); | ||
if (n < 1) { | ||
return ''; | ||
} | ||
while (n > 0) { | ||
if (n % 2) { | ||
result += str; | ||
} | ||
n = Math.floor(n / 2); | ||
str += str; | ||
} | ||
return result; | ||
} | ||
@@ -11,0 +23,0 @@ |
@@ -11,3 +11,3 @@ define(['../lang/toString'], function (toString) { | ||
.replace(/>/g , '>') | ||
.replace(/'/g , "'") | ||
.replace(/�*39;/g , "'") | ||
.replace(/"/g, '"'); | ||
@@ -14,0 +14,0 @@ return str; |
var toString = require('../lang/toString'); | ||
// This pattern is generated by the _build/pattern-removeNonWord.js script | ||
var PATTERN = /[^\x20\x2D0-9A-Z\x5Fa-z\xC0-\xD6\xD8-\xF6\xF8-\xFF]/g; | ||
/** | ||
@@ -7,3 +10,3 @@ * Remove non-word chars. | ||
str = toString(str); | ||
return str.replace(/[^0-9a-zA-Z\xC0-\xFF \-_]/g, ''); | ||
return str.replace(PATTERN, ''); | ||
} | ||
@@ -10,0 +13,0 @@ |
var toString = require('../lang/toString'); | ||
var toInt = require('../number/toInt'); | ||
@@ -7,4 +8,16 @@ /** | ||
function repeat(str, n){ | ||
var result = ''; | ||
str = toString(str); | ||
return (new Array(n + 1)).join(str); | ||
n = toInt(n); | ||
if (n < 1) { | ||
return ''; | ||
} | ||
while (n > 0) { | ||
if (n % 2) { | ||
result += str; | ||
} | ||
n = Math.floor(n / 2); | ||
str += str; | ||
} | ||
return result; | ||
} | ||
@@ -11,0 +24,0 @@ |
@@ -11,3 +11,3 @@ var toString = require('../lang/toString'); | ||
.replace(/>/g , '>') | ||
.replace(/'/g , "'") | ||
.replace(/�*39;/g , "'") | ||
.replace(/"/g, '"'); | ||
@@ -14,0 +14,0 @@ return str; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
392187
517
8716
11