frink
Very liberal implementation of W3C XPath and XQuery functions 3.1
Last updated 2 years ago by wshager .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install frink 
SYNC missed versions from official npm registry.

Frink: everything but the kitchen sink

Parse XML into a DOM level 4 compatible, persistent (AKA immutable) virtual tree.

Traverse trees with speed-optimized functions reminiscent of XPath.

Parse JSON into similar, traversable trees, or mix with XML.

Generate L3, a lightweight, flat representation of XML or JSON trees (or mixed) for fast storage and retrieval.

Construct trees with a coherent set of functions, to create persistent HTML, XML or JSON documents.

Render persistent trees or L3 as HTML in the browser. Uses a super-simple, lightning-fast tree diffing algorithm.

Validate both XML and JSON using a custom extension of JSON Schema v0.4.

To be used together with Raddle's standards-based document processing language.


Why Frink?

It is not the spoon that bends

The browser's DOM API is ... inconvenient. The stuff you see in a web application is not always represented in the source code. Instead, they are in some part of the browser you need to access or update. So, like others have done before, we'll just connect to those parts and modify our document as though they're already part of it. I didn't come up with this idea: it's called virtual DOM, and there are many libraries out there that work like this.

However, what is called virtual DOM is actually not HTML anymore, as it must obey stricter rules than is just required for the representation you download from the server. It's actually a mix of XML and javascript data (AKA JSON). This library tries to formalize that notion, in a data model called L3N. It also provides tried and tested tools for accessing and updating this data model, as they have been developed in the W3C XML working group. These functional tools have been used for years on semi-structured data with great success. As XML has lost its appeal as data modelling language, I try to salvage the good parts with a modern javascript API, for use in the browser and in nodejs.

Frink integrates with legacy XML projects that don't rely on DTD validation.

API (WIP)

Sequences

Sequences come in two flavors. The default (ArraySeq) is based on a javascript array, the other is an Observable sequence. The two are interopable, to the extend that the array-based Sequence implements a limited number of methods from RxJS and converts to an Observable when needed. To guarantee interoperability, you should use the functions provided by Frink instead of RxJS.

seq(...) => ArraySeq|Observable

Creates a sequence. Any sequences or iterables (except strings) in arguments are flattened. In case any argument is an Observable or a Promise, the sequence is converted to an Observable.

zeroOrOne(seqOrValue) => ArraySeq|Observable

Tests a sequence for cardinality. If it contains zero or one item, the sequence is returned. Else an error is thrown instead.

Param Type Description
seqOrValue ArraySeq Observable

exactlyOne(seqOrValue) => ArraySeq|Observable

Tests a sequence for cardinality. If it contains exactly one item, the sequence is returned. Else an error is thrown instead.

Param Type Description
seqOrValue ArraySeq Observable

oneOrMore(seqOrValue) => ArraySeq|Observable

Tests a sequence for cardinality. If it contains one or more items, the sequence is returned. Else an error is thrown instead.

Param Type Description
seqOrValue ArraySeq Observable

empty(seqOrValue) => Boolean|Observable<Boolean>

Tests is a sequence is entry. Returns a boolean (for ArraySeq or null) or an Observable holding a boolean value if the param is an Observable.

Param Type Description
seqOrValue ArraySeq Observable

exists(seqOrValue) => Boolean|Observable<Boolean>

The opposite of empty. Returns a boolean for ArraySeq or any other value that isn't a sequence. Returns an Observable holding a boolean value if the param is an Observable.

Param Type Description
seqOrValue ArraySeq Observable

forEach(seqOrValue, fn)

Apply function to value or each value in sequence.

Param Type Description
seqOrValue ArraySeq Observable
fn function Transformation

filter(seqOrValue, fn)

Filter value or values in sequence based on provided function.

Param Type Description
seqOrValue ArraySeq Observable
fn function Filter function

foldLeft(seqOrValue[, seed], fn)

Reduce sequence or value to a new sequence.

Param Type Description
seqOrValue ArraySeq Observable
fn function Transformation

Current Tags

  • 0.5.2                                ...           latest (2 years ago)

13 Versions

  • 0.5.2                                ...           2 years ago
  • 0.5.1                                ...           2 years ago
  • 0.4.3                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.9                                ...           2 years ago
  • 0.2.8                                ...           2 years ago
  • 0.2.6                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.4                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 3
Dependencies (6)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |