Comments (2)
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.
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)
- Add a playground to allow using temme in the browser. HOT 1
- Enhance selector syntax. HOT 2
- Refine scripts for development and deployment.
- Version 0.5
- Command line tool support
- Add examples/stackoverflow in English
- 建议新增scss语法和对象合并支持 HOT 10
- Version 0.7
- Version 10 of node.js has been released
- 逻辑判断 HOT 2
- 建议提供从多个选择器捕获的功能 HOT 6
- version 0.8
- :first-child HOT 1
- An in-range update of prettier is breaking the build 🚨 HOT 1
- 需要发布新版本
- Allow spaces around the pipe operator HOT 1
- 新版网站更新进度
- 可能的话还是再优化优化体积吧 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from temme.