utils.js 613 B

1234567891011121314151617181920
  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 = ['id', 'index', 'src', 'type']
  5. // transform the attrs on a SFC block descriptor into a resourceQuery string
  6. exports.attrsToQuery = (attrs, langFallback) => {
  7. let query = ``
  8. for (const name in attrs) {
  9. const value = attrs[name]
  10. if (!ignoreList.includes(name)) {
  11. query += `&${qs.escape(name)}=${value ? qs.escape(value) : ``}`
  12. }
  13. }
  14. if (langFallback && !(`lang` in attrs)) {
  15. query += `&lang=${langFallback}`
  16. }
  17. return query
  18. }