Closed redapple closed 7 years ago
Hey @rolando, I'm introducing a js2xml.utils
submodule.
Would your helpers in #22 fit?
Merging #26 into master will decrease coverage by
0.11%
. The diff coverage is93.22%
.
@@ Coverage Diff @@
## master #26 +/- ##
==========================================
- Coverage 90.54% 90.43% -0.12%
==========================================
Files 9 10 +1
Lines 656 669 +13
==========================================
+ Hits 594 605 +11
- Misses 62 64 +2
Impacted Files | Coverage Δ | |
---|---|---|
js2xml/jsonlike.py | 100% <100%> (+4.34%) |
:arrow_up: |
js2xml/utils/objects.py | 92.3% <92.3%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 8c49cd3...11d3b21. Read the comment docs.
@redapple Yes, sounds good to me.
js2xlm.jsonlike
is a misleading name for what the submodule provides:make_dict
can return more than just a Python dict, e.g. a string or booleanThis very change moves the functionality of
js2xml.jsonlike
to its own submodulejs2xml.utils.objects
.In there, you can still get out Python dicts and lists, but also "simple" JavaScript built-in objects:
{a: 1}
) intodict
,list
,bool
,str
,int
orfloat
None
.You have 3 main methods:
js2xml.utils.objects.make(node)
: takes a node in the js-parsed tree and converts to the Python object following the mapping described above,js2xml.utils.objects.findall(tree, types)
: to find the top-most nodes in the js-parsed tree that can be converted to one of these Python types above; you can pass the Python types you want in thetypes
(as a list or tuple). By default it will look forlist
-like anddict
-like objects, but you can passtypes=['str']
to search for strings.js2xml.utils.objects.getall(tree, types)
: same asfindall
except that is converts what was found to the corresponding Python object, usingmake()