esnext.array.is-template-object.js 962 B

1234567891011121314151617181920212223242526272829
  1. var $ = require('../internals/export');
  2. var isArray = require('../internals/is-array');
  3. // eslint-disable-next-line es/no-object-isfrozen -- safe
  4. var isFrozen = Object.isFrozen;
  5. var isFrozenStringArray = function (array, allowUndefined) {
  6. if (!isFrozen || !isArray(array) || !isFrozen(array)) return false;
  7. var index = 0;
  8. var length = array.length;
  9. var element;
  10. while (index < length) {
  11. element = array[index++];
  12. if (!(typeof element === 'string' || (allowUndefined && typeof element === 'undefined'))) {
  13. return false;
  14. }
  15. } return length !== 0;
  16. };
  17. // `Array.isTemplateObject` method
  18. // https://github.com/tc39/proposal-array-is-template-object
  19. $({ target: 'Array', stat: true }, {
  20. isTemplateObject: function isTemplateObject(value) {
  21. if (!isFrozenStringArray(value, true)) return false;
  22. var raw = value.raw;
  23. if (raw.length !== value.length || !isFrozenStringArray(raw, false)) return false;
  24. return true;
  25. }
  26. });