PHP 7.4.33
Preview: index.js Size: 866 B
/var/www/cookieconsent.bitkit.dk/httpdocs/node_modules/safe-identifier/index.js
const reserved = require('./reserved.js')

// from https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
function hashCode(str) {
  let hash = 0
  for (let i = 0; i < str.length; ++i) {
    const char = str.charCodeAt(i)
    hash = (hash << 5) - hash + char
    hash |= 0 // Convert to 32bit integer
  }
  return hash
}

function identifier(key, unique) {
  if (unique) key += ' ' + hashCode(key).toString(36)
  const id = key.trim().replace(/\W+/g, '_')
  return reserved.ES3[id] || reserved.ESnext[id] || /^\d/.test(id)
    ? '_' + id
    : id
}

function property(obj, key) {
  if (/^[A-Z_$][0-9A-Z_$]*$/i.test(key) && !reserved.ES3[key]) {
    return obj ? obj + '.' + key : key
  } else {
    const jkey = JSON.stringify(key)
    return obj ? obj + '[' + jkey + ']' : jkey
  }
}

module.exports = { identifier, property }

Directory Contents

Dirs: 0 × Files: 7
Name Size Perms Modified Actions
792 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
866 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
832 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
750 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
862 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
1.38 KB lrw-r--r-- 2025-06-16 05:45:39
Edit Download
808 B lrw-r--r-- 2025-06-16 05:45:39
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).