urbit-ob

JavaScript utilities for phonemic base wrangling.
Log | Files | Refs | README

commit 1cbf9cbacbb1e8decc217268fb893d34d653fada
parent d2dc897ac35bdeb0fe5e0a3442a1d406ad38d4fe
Author: Jared Tobin <jared@jtobin.io>
Date:   Tue, 24 Mar 2020 16:41:58 +0400

co: strengthen isValidPatp, isValidPatq

Resolves #17.

Uses a simple heuristic to more rigorously validate patp and patq
strings.

Exports 'isValidPat' for faster/weaker checks.

Diffstat:
Msrc/internal/co.js | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/internal/co.js b/src/internal/co.js @@ -350,6 +350,24 @@ const isValidPat = name => { } /** + * Validate a @p string. + * + * @param {String} str a string + * @return {String} + */ +const isValidPatp = str => + isValidPat(str) && str === patp(patp2dec(str)) + +/** + * Validate a @q string. + * + * @param {String} str a string + * @return {String} + */ +const isValidPatq = str => + isValidPat(str) && eqPatq(str, patq(patq2dec(str))) + +/** * Remove all leading zero bytes from a sliceable value. * @param {String, Buffer, Array} * @return {String} @@ -444,6 +462,7 @@ module.exports = { patq2dec, eqPatq, - isValidPatp: isValidPat, // reserving for diff impls in future - isValidPatq: isValidPat + isValidPat, + isValidPatp, + isValidPatq }