Giter Club home page Giter Club logo

cheerio-json-mapper's People

Contributors

denkan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cheerio-json-mapper's Issues

Error getting attributes of current element

Love this library, its exactly what cheerio is missing. Hopefully they'll merge it in!

I'm using the JSON mapper to pull marketing data about our competition from Clutch.

The following errors though when Im trying to get the attribute of the current element. I assume I'm doing it wrong.

Error: Empty sub-selector

{"companies": [
  {
    "$": "ul.directory-list li.provider-row",
    "clutchId": "$ | attr:data-clutch-pid",
    "title": ".company_info a",
    "tagline": ".tagline",
    "rating": ".rating",
    "reviewCount": ".reviews-link",
    "minProjectSize": "div [data-content='<i>Min. project size</i>'] span",
    "avgHourlyRate": "div [data-content='<i>Avg. hourly rate</i>'] span",
    "employees": "div [data-content='<i>Employees</i>'] span",
    "location": "div [data-content='<i>Location</i>'] span"
}
]}

The error occurs when I include the line

"clutchId": "$.attr",

This is the HTML Im parsing at this point

<ul class="directory-list"> <li data-position="1" id="provider-12345" data-type="Sponsor" class="provider provider-row sponsor" data-is-list="true" data-clutch-pid="12345" data-title="XXXX"

Dynamic keys

Is it possible to to do something like

const html= `
  <table>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
    <tr>
      <td>John</td>
      <td>30</td>
    </tr>
    <tr>
      <td>Jane</td>
      <td>28</td>
    </tr>
  </table>
`;

const schema = [
  {
    "th: "td"
  }
]

which would map to:

[
  {
    "Name": "John",
    "Age": "30"
  },
  {
    "Name": "James",
    "Age": "28"
  },
]

Typed return value

Thanks for writing this app, since cheerio can't seem to release a new version since 6 months!

I wonder why you choose to return a Promise<unknown> instead of a promise with the structure of the template (types)?
I guess its not easy to derive the type from the piped values, but how about adding a template argument to the function where we can specifiy the resulting objects shape?

Or have you looked at [zod](https://www.npmjs.com/package/zod) which is completely typesafe and also supports the concept of pipes (althought differently named).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.