0.8.0 • Published 2 years ago

hays v0.8.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

hays

find the dot path and value of a key of a specific name or pattern deep inside an object and transform or replace it.

Install

npm install hays

Usage

const hays = require('hays')

const book = {
  isbn: '123-456-222',
  title: 'The Ultimate Database Study Guide',
  category: ['Non-Fiction', 'Technology'],
  author: {
    lastname: 'Windler',
    firstname: 'Dianne',
  },
  editor: {
    lastname: 'Smith',
    firstname: 'Felicity',
  },
}

hays.find(book, 'firstname').then(console.log)
// [
//  { path: 'author.firstname', data: { value: 'Dianne' } },
//  { path: 'editor.firstname', data: { value: 'Felicity' } }
// ]

hays.find(book, /.*name/).then(console.log)
// [
//   { path: 'author.lastname', data: { value: 'Windler' } },
//   { path: 'author.firstname', data: { value: 'Dianne' } },
//   { path: 'editor.lastname', data: { value: 'Smith' } },
//   { path: 'editor.firstname', data: { value: 'Felicity' } }
// ]

hays.find(book, 'title', { transform: s => s.toLowerCase() }).then(console.log)
// [
//   {
//     path: 'title',
//     data: {
//       value: 'The Ultimate Database Study Guide',
//       transformed: 'the ultimate database study guide',
//     },
//   }
// ]

hays.replace(book, 'category', c => c.concat('Educational')).then(console.log)
// [
//   {
//     path: 'category',
//     data: {
//       old: [ 'Non-Fiction', 'Technology' ],
//       new: [ 'Non-Fiction', 'Technology', 'Educational' ]
//     }
//   }
// ]

console.log(book)
// {
//   isbn: '123-456-222',
//   title: 'The Ultimate Database Study Guide',
//   category: ['Non-Fiction', 'Technology', 'Educational'],
//   author: { lastname: 'Windler', firstname: 'Dianne' },
//   editor: { lastname: 'Smith', firstname: 'Felicity' },
// }
0.8.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago