You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
623 B

4 years ago
  1. const qs = require('querystring')
  2. // these are built-in query parameters so should be ignored
  3. // if the user happen to add them as attrs
  4. const ignoreList = [
  5. 'id',
  6. 'index',
  7. 'src',
  8. 'type'
  9. ]
  10. // transform the attrs on a SFC block descriptor into a resourceQuery string
  11. exports.attrsToQuery = (attrs, langFallback) => {
  12. let query = ``
  13. for (const name in attrs) {
  14. const value = attrs[name]
  15. if (!ignoreList.includes(name)) {
  16. query += `&${qs.escape(name)}=${value ? qs.escape(value) : ``}`
  17. }
  18. }
  19. if (langFallback && !(`lang` in attrs)) {
  20. query += `&lang=${langFallback}`
  21. }
  22. return query
  23. }