版博士V2.0程序
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.
 
 
 
 

21 lines
774 B

  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. }