STD
@webhare/std offers APIs that may have generic use but are especially useful when building WebHare applications
String manipulation
GenerateUFS128BitId()->generateRandomId()EncodeUFS(x)->encodeString(x, 'base64url')DecodeUFS(x)->decodeString(x, 'base64url')EncodeValue(x)->encodeString(x, 'attribute')DecodeValue(x)->decodeString(x, 'attribute')EncodeHTML(x)->encodeString(x, 'html')DecodeHTML(x)->decodeString(x, 'html')LIKEoperator ->wildcardsToRegExpEncodeJSON->JSON.stringifyorstableStringifyif you require ordered keys
Be careful when porting the UC (Unicode) functions in HareScript especially when dealing with characters outside the
16 bit range. JavaScript length and substr(ing) operators are based on the UTF16 string representation which does
not correspond to the actual codepoints. Ie: UCLength('😀') = 1, Length('😀') = 4 and '😀'.length == 2. Consider the
String iterator
Promises
CreateDeferredPromise()->createDeferred
HSCompat
@webhare/hscompat offers APIs useful for migrating to JS but things that we don't consider best practice
Datetime
- makeDateFromParts
- localToUTC and UTCToLocal. We strongly recommend using a Temporal polyfill instead.
WHFS
OpenWHFSObject...->openFile/openFolder(if you really need it:openFileOrFolderbut this is less useful esp. with TypeScript)OpenSite/OpenSiteByName->openSite
We also strongly advise against direct selection of any system tables from JavaScript. Generated fields (eg parentsite, whfspath, webroot)
are not easily available and considered internal implementations. You should instead use object-based APis such as listSites or list on a WHFSFolder.
Files
GetBasenameFromPath->path.parse().nameGetExtensionFromPath->path.extnameorpath.parse().ext- however initial dot handling differs slightly..
getExtensionFromPath(".doc")would not return.docbutpath.extnamewill
- however initial dot handling differs slightly..
GetSafeName->slugifyMergePath->path.joinStoreDiskFile->storeDiskFile(from @webhare/system-tools)