Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

utils.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright 2011 Rackspace
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /**
  18. * @param {Object} hash.
  19. * @param {Array} ignored.
  20. */
  21. function items(hash, ignored) {
  22. ignored = ignored || null;
  23. var k, rv = [];
  24. function is_ignored(key) {
  25. if (!ignored || ignored.length === 0) {
  26. return false;
  27. }
  28. return ignored.indexOf(key);
  29. }
  30. for (k in hash) {
  31. if (hash.hasOwnProperty(k) && !(is_ignored(ignored))) {
  32. rv.push([k, hash[k]]);
  33. }
  34. }
  35. return rv;
  36. }
  37. function findall(re, str) {
  38. var match, matches = [];
  39. while ((match = re.exec(str))) {
  40. matches.push(match);
  41. }
  42. return matches;
  43. }
  44. function merge(a, b) {
  45. var c = {}, attrname;
  46. for (attrname in a) {
  47. if (a.hasOwnProperty(attrname)) {
  48. c[attrname] = a[attrname];
  49. }
  50. }
  51. for (attrname in b) {
  52. if (b.hasOwnProperty(attrname)) {
  53. c[attrname] = b[attrname];
  54. }
  55. }
  56. return c;
  57. }
  58. exports.items = items;
  59. exports.findall = findall;
  60. exports.merge = merge;