Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Add or() to Sandbox utils API
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-brechemier committed Sep 10, 2013
1 parent a6676c2 commit c30ce36
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.txt
Expand Up @@ -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

7 changes: 4 additions & 3 deletions src/lb/lb.core.Sandbox.js
Expand Up @@ -53,7 +53,8 @@
* - <lb.core.plugins.url.sandbox.url.onHashChange(callback)>
*
* General utilities (sandbox.utils):
* TODO: add no() to sandbox.utils
* - <lb.core.plugins.utils.sandbox.utils.no(value): boolean>
* - <lb.core.plugins.utils.sandbox.utils.or(a,b): any>
* - <lb.core.plugins.utils.sandbox.utils.has(object,property[,...]): boolean>
* - <lb.core.plugins.utils.sandbox.utils.is([...,]value[,type]): boolean>
* - <lb.core.plugins.utils.sandbox.utils.getTimestamp(): number>
Expand All @@ -72,15 +73,15 @@
* o Marc Delhommeau <marc.delhommeau@legalbox.com>
*
* 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:
* BSD License
* http://creativecommons.org/licenses/BSD/
*
* Version:
* 2011-08-14
* 2013-09-10
*/
/*global define, document, window */
define(
Expand Down
33 changes: 30 additions & 3 deletions src/lb/lb.core.plugins.utils.js
Expand Up @@ -15,7 +15,7 @@
* http://creativecommons.org/licenses/BSD/
*
* Version:
* 2013-09-09
* 2013-09-10
*/
/*global define, window */
define(
Expand Down Expand Up @@ -47,6 +47,7 @@ define(

// Declare aliases
var no = lbBase.no,
or = lbBase.or,
has = object.has,
is = type.is,
trim = string.trim,
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -290,6 +316,7 @@ define(

sandbox.utils = {
no: no,
or: or,
has: has,
is: is,
getTimestamp: getTimestamp,
Expand Down

0 comments on commit c30ce36

Please sign in to comment.