renderAuthorize.js 704 B

123456789101112131415161718192021222324252627282930
  1. /* eslint-disable eslint-comments/disable-enable-pair */
  2. /* eslint-disable import/no-mutable-exports */
  3. let CURRENT = 'NULL'
  4. /**
  5. * use authority or getAuthority
  6. * @param {string|()=>String} currentAuthority
  7. */
  8. const renderAuthorize = Authorized => currentAuthority => {
  9. if (currentAuthority) {
  10. if (typeof currentAuthority === 'function') {
  11. CURRENT = currentAuthority()
  12. }
  13. if (
  14. Object.prototype.toString.call(currentAuthority) === '[object String]' ||
  15. Array.isArray(currentAuthority)
  16. ) {
  17. CURRENT = currentAuthority
  18. }
  19. } else {
  20. CURRENT = 'NULL'
  21. }
  22. return Authorized
  23. }
  24. export { CURRENT }
  25. export default Authorized => renderAuthorize(Authorized)