General Utilities¶
Object fields and schema inspection¶
import {
get_field_schema, iterfield, getfield, setfield, concatlistfield
} from '@phfaist/zoodb/util/getfield';
import {
iter_object_fields_recursive, iter_schema_fields_recursive,
} from '@phfaist/zoodb/util/objectinspector';
// all the above symbols can also be imported as
// "import ... from '@phfaist/zoodb/util' "
Todo, doc………
Splitting a ‘prefix:label’ string¶
import { split_prefix_label } from '@phfaist/zoodb/util/prefixlabel';
// the above symbol can also be imported as
// "import ... from '@phfaist/zoodb/util' "
- split_prefix_label(label)¶
Split a string of the form ‘prefix:label’, commonly used in LaTeX reference labels. We also use such strings for citations (e.g. ‘arXiv:1234.56789’).
This function returns a two-element list
[prefix, label]
where prefix is the string before the ‘:’ separator, and the label is the string after the ‘:’ separator.The argument label should be a string and should not be null or undefined.
If the label contains a ‘:’ character, the initial string up to the first ‘:’ is split off as a “prefix”, the rest of the string without the separating ‘:’ is the “label”. Any additional ‘:’ characters are considered as part of the label.
If the label does not contain any ‘:’ character, then the prefix is null and the entire string is considered to be the label.
HTML Javascript template literals¶
import { sqzhtml } from '@phfaist/zoodb/util/sqzhtml';
// the above symbol can also be imported as
// "import ... from '@phfaist/zoodb/util' "
- sqzhtml(strings, values)¶
A utility for typing template literal strings in JavaScript for generating HTML, while removing some spurious whitespace. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals.
Use as follows:
url = 'https://errorcorrectionzoo.org'; html_block = sqzhtml` <div> Link to the <a href="${url}">Error Correction Zoo</a>. </div> `; // --> html_block = // '<div>Link to the <a href="https://errorcorrectionzoo.org">Error\n' // + ' Correction Zoo</a>.</div>'
“Squeeze” HTML template strings (only the template strings themselves, the interpolated values are not touched) – remove newlines and accompanying whitespace immediately before/after tag beginning/end. Keep all other newlines and whitespace.