Source: extras/data.js

  1. /**
  2. * Data manipulation related functions.
  3. * @namespace
  4. */
  5. Bravey.Data = {};
  6. /**
  7. * Extract entities or context values with the same name from a {@link Bravey.ContextManager.testBySessionId} call result.
  8. * @param {ContextManagerResultBySessionId} matchdata - The data returned by {@link Bravey.ContextManager.testBySessionId}.
  9. * @param {string} entityname - The data returned by {@link Bravey.ContextManager.testBySessionId}.
  10. * @param {string} [defaultvalue=undefined] - The matched entity value cosidered as "default". (i.e. if found, session data value is returned anyway)
  11. * @returns {string} The matching value.
  12. * @returns {undefined} If the entity name is not set in match or session.
  13. */
  14. Bravey.Data.getEntityValue = function(matchdata, entityname, defaultvalue) {
  15. var found;
  16. if (matchdata) {
  17. if ((matchdata.result !== undefined) && (matchdata.result.entitiesIndex !== undefined) && (matchdata.result.entitiesIndex[entityname] !== undefined))
  18. found = matchdata.result.entitiesIndex[entityname].value;
  19. if (found == defaultvalue) found = undefined;
  20. if ((found == undefined) && (matchdata.sessionData !== undefined))
  21. found = matchdata.sessionData[entityname];
  22. }
  23. return found;
  24. }
  25. /**
  26. * Returns true if a {@link Bravey.ContextManager.testBySessionId} result contains the specified entity.
  27. * @param {ContextManagerResultBySessionId} matchdata - The data returned by {@link Bravey.ContextManager.testBySessionId}.
  28. * @param {string} entityname - The entity to be checked.
  29. * @returns {true} When the entity is specified.
  30. */
  31. Bravey.Data.isExplicit = function(matchdata, entityname) {
  32. return (matchdata && (matchdata.result !== undefined) && (matchdata.result.entitiesIndex !== undefined) && (matchdata.result.entitiesIndex[entityname] !== undefined));
  33. }