Git Product home page Git Product logo

Comments (2)

feichao93 avatar feichao93 commented on May 31, 2024 1

I think using lodash functions as filter would be great. However, there is one major problem -- temme can only parse simple JavaScript literals while "lodash filters" requires complex arguments. For example, sortBy(collection, iteratees) requires iteratees a function, which is not a simple literal value and cannot be parsed by temme.

If you want process the output of temme, you can pipe the output from temme to jq. For example...

cat a.html | temme some-selector-or-selector-file | jq xxxx

Or save the temme-selector in a file and use that file in the CLI, so that you can define some customized filters to process data. For example...

echo 'div { $foo; }' > a.temme
temme a.temme "<div class=foo>hello</div>"
# output:  {"foo":"hello"}

from temme.

chocolateboy avatar chocolateboy commented on May 31, 2024 1

temme can only parse simple JavaScript literals while "lodash filters" requires complex arguments.

Ah, fair enough. That makes sense.

Or save the temme-selector in a file and use that file in the CLI, so that you can define some customized filters to process data.

Thanks. I'll do that.


One thing that might be worth considering is some kind of import or require statement that can pull in a JavaScript module which can interact with the library to add custom filters e.g.:

// movies.temme
import "filters.mjs";
// movies.temme
require("filters.js");

- and/or a command-line option to do this (like -r/--require in node/ruby etc.). The module could export a function which is passed the temme exports e.g.:

// filters.js

module.exports = function (temme) {
    temme.defineFilter(...)
}

Or possibly:

// filters.mjs

export default function ({ defineFilter }) { ... }

This could then be invoked with e.g.:

$ temme -r filters.js -s <selector-expression> -i <html-expression>
$ temme -r filters.mjs -S <selector-file> -I <html-file>

As you can see, the options would probably need to be made more explicit to accommodate this, but I'd actually prefer that anyway.

Closing this, thanks (but I'm happy to raise a new issue for the require/--require proposal — or discuss it here — if there's any interest).

By the way, thanks for temme! It's the best DSL for extracting data from unstructured documents I think I've ever used, and I've tried (and even written :-) quite a few over the years 👍

from temme.

Related Issues (19)

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.