diff --git a/README.txt b/README.txt index 33d64ed8..a888d72f 100644 --- a/README.txt +++ b/README.txt @@ -228,7 +228,7 @@ HISTORY 2011-07-12, v1.8.1, Upgraded jslint4java and JSLint, updated Ant macro 2011-08-14, v1.8.2, Project deleted by Legal-Box, moved to eric-brechemier 2013-09-09, v1.8.3, Add no() to Sandbox utils API - 2013-XX-XX, v1.8.4, ROADMAP: Add a = or(a,b) to Sandbox utils API + 2013-09-10, v1.8.4, Add or() to Sandbox utils API 2013-XX-XX, v1.9.0, ROADMAP: add foreach(), map(), reduce() in array API 2013-XX-XX, v1.10.0, ROADMAP: add animate() method to CSS API of Sandbox diff --git a/src/lb/lb.core.Sandbox.js b/src/lb/lb.core.Sandbox.js index 8ad3b164..202fa775 100644 --- a/src/lb/lb.core.Sandbox.js +++ b/src/lb/lb.core.Sandbox.js @@ -53,7 +53,8 @@ * - * * General utilities (sandbox.utils): - * TODO: add no() to sandbox.utils + * - + * - * - * - * - @@ -72,7 +73,7 @@ * o Marc Delhommeau * * Copyright: - * Eric Bréchemier (c) 2011, Some Rights Reserved + * Eric Bréchemier (c) 2011-2013, Some Rights Reserved * Legal-Box SAS (c) 2010-2011, All Rights Reserved * * License: @@ -80,7 +81,7 @@ * http://creativecommons.org/licenses/BSD/ * * Version: - * 2011-08-14 + * 2013-09-10 */ /*global define, document, window */ define( diff --git a/src/lb/lb.core.plugins.utils.js b/src/lb/lb.core.plugins.utils.js index a0dce24b..5ae2d0c2 100644 --- a/src/lb/lb.core.plugins.utils.js +++ b/src/lb/lb.core.plugins.utils.js @@ -15,7 +15,7 @@ * http://creativecommons.org/licenses/BSD/ * * Version: - * 2013-09-09 + * 2013-09-10 */ /*global define, window */ define( @@ -47,6 +47,7 @@ define( // Declare aliases var no = lbBase.no, + or = lbBase.or, has = object.has, is = type.is, trim = string.trim, @@ -83,6 +84,33 @@ define( // Note: no() is an alias for lb.base.no + // Function: sandbox.utils.or(a,b): any + // Get a default value when given value is null or undefined + // + // The intent of this method is to replace unsafe initialization of + // optional parameters to a default value relying on type coercion: + // | function on(event,options){ + // | options = options || {}; // type coercion + // | var isUser = options.isUser || false; // type coercion + // | // ... + // | } + // with a safer initialization without type coercion: + // | function on(event,options){ + // | options = or(options, {}); // no type coercion + // | var isUser = or(options.isUser, false); // no type coercion + // | // ... + // | } + // + // Parameters: + // a - any, the value to check + // b - any, the default value + // + // Returns: + // any, the default value when the value is null or undefined, + // the value itself otherwise. + + // Note: or() is an alias for lb.base.or + // Function: sandbox.utils.has(object,property[,...]): boolean // Check whether an object property is present and not null nor undefined. // @@ -205,8 +233,6 @@ define( // Note: is() is an alias for lb.base.type.is - // TODO: add no() to utils plugin and sandbox - function getTimestamp(){ // Function: sandbox.utils.getTimestamp(): number // Get current timestamp, in milliseconds. @@ -290,6 +316,7 @@ define( sandbox.utils = { no: no, + or: or, has: has, is: is, getTimestamp: getTimestamp,