array.js 774 B

1234567891011121314151617181920
  1. import { inspectProperty, inspectList } from './helpers'
  2. export default function inspectArray(array, options) {
  3. // Object.keys will always output the Array indices first, so we can slice by
  4. // `array.length` to get non-index properties
  5. const nonIndexProperties = Object.keys(array).slice(array.length)
  6. if (!array.length && !nonIndexProperties.length) return '[]'
  7. options.truncate -= 4
  8. const listContents = inspectList(array, options)
  9. options.truncate -= listContents.length
  10. let propertyContents = ''
  11. if (nonIndexProperties.length) {
  12. propertyContents = inspectList(
  13. nonIndexProperties.map(key => [key, array[key]]),
  14. options,
  15. inspectProperty
  16. )
  17. }
  18. return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ''} ]`
  19. }