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')
LIKE
operator -> wildcardsToRegExp
EncodeJSON
-> JSON.stringify
or stableStringify
if you require ordered keys
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')
LIKE
operator -> wildcardsToRegExp
EncodeJSON
-> JSON.stringify
or stableStringify
if 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
CreateDeferredPromise()
-> createDeferred
@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: openFileOrFolder
but this is less useful esp. with TypeScript)
OpenSite
/OpenSiteByName
-> openSite
makeDateFromParts
localToUTC and UTCToLocal. We strongly recommend using a Temporal polyfill instead.
OpenWHFSObject...
->openFile
/openFolder
(if you really need it:openFileOrFolder
but 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().name
GetExtensionFromPath
-> path.extname
or path.parse().ext
however initial dot handling differs slightly.. getExtensionFromPath(".doc")
would not return .doc
but path.extname
will
GetSafeName
-> slugify
MergePath
-> path.join
StoreDiskFile
-> storeDiskFile
(from @webhare/system-tools)
GetBasenameFromPath
-> path.parse().name
GetExtensionFromPath
-> path.extname
or path.parse().ext
however initial dot handling differs slightly..
getExtensionFromPath(".doc")
would not return.doc
butpath.extname
will
GetSafeName
-> slugify
MergePath
-> path.join
StoreDiskFile
-> storeDiskFile
(from @webhare/system-tools)