{"modulePath":"github.com/Defacto2/server","version":"v1.16.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package simple\n\nPackage simple provides functions for handling string or integer input data.\n\n## Constants\n\n```go\nconst (\n\tYYYYMMDD   = \"2006-Jan-02\"\n\tANSImation = \"ANSImation\"\n\tANSIBlink  = \" with blinking\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrLinkType = errors.New(\"simple: the id value is an invalid type\")\n\tErrName     = errors.New(\"simple: name is an empty string\")\n\tErrNegative = errors.New(\"simple: value cannot be a negative number\")\n)\n```\n\n## Functions\n\n```go\nfunc AnimPreview(unid string, preview dir.Directory) string\n```\nAnimPreview returns the static URL of the animated WebP preview image for an ANSImation if it exists on disk, or an empty string otherwise.\n\n```go\nfunc AssetSrc(abs, dir, unid, ext string) string\n```\nAssetSrc returns a URL to an artifact asset with an cache busting hash. The named dir is the directory where the asset is stored, the unid is the unique identifier of the asset, and the ext is the file extension of the expected asset.\n\n```go\nfunc BytesHuman(i int64) string\n```\nBytesHuman returns the file size for the file record.\n\n```go\nfunc CleanFname(s string) (string, error)\n```\nCleanFname runs the string such as a filename through a HTML template to remove any possible XSS problems such as \\\u003c \u003e characters.\n\n```go\nfunc CleanHTML(html string) string\n```\nCleanHTML removes all HTML tags from content, returning plain text.\n\n```go\nfunc DemozooGetLink(filename, filesize, demozoo, unid any) template.HTML\n```\nDemozooGetLink returns a HTML link to the Demozoo download links. The filename and filesize are used to determine if the file exists. The demozoo is the ID for the production on Demozoo. The unid is the unique identifier for the file record.\n\n```go\nfunc DownloadInBytes(v any) template.HTML\n```\nDownloadInBytes returns a human readable string of the file size. The value must be an integer or a null.Int64.\n\n```go\nfunc Hash(s string) string\n```\nHash creates a stable hash ID from a string and returns it as base64.\n\n```go\nfunc ImageSample(unid string, preview dir.Directory) template.HTML\n```\nImageSample returns a HTML image tag for the given unid. The preview is the directory where the preview images are stored.\n\n```go\nfunc ImageSampleStat(unid string, preview dir.Directory) bool\n```\nImageSampleStat returns true if the image sample file exists and is not a 0 byte file. The preview is the directory where the preview images are stored.\n\n```go\nfunc ImageXY(sl *slog.Logger, name string) [2]string\n```\nImageXY returns the named image filesize and dimensions as a styled string array. The dimensions are returned as a string in the format \"width x height\". If the file does not exist, an empty string array is returned.\n\nFor example, the returned values are:\n\n\t[\"4,163\", \"500x500\"]\n\nHowever, if the file does not exist, the returned values are:\n\n\t[\"0\", \"\"]\n\n```go\nfunc LinkID(id any, elem string) (string, error)\n```\nLinkID creates a URL to link to the record. The id is obfuscated to prevent direct linking. The elem is the element to link to, such as 'f' for file or 'd' for download.\n\n```go\nfunc LinkPreviewTip(name, platform string) string\n```\nLinkPreviewTip returns a tooltip to describe the preview link. The name is the filename of the file to preview and does not require path information. The platform is the platform or format of the file.\n\n```go\nfunc LinkRelations(val string) template.HTML\n```\nLinkRelations returns a collection of HTML anchor links that point to artifacts.\n\nThe val string is a list of artifact descriptions and their URL ID separated by a semicolon \";\". Multiple artifact entries are separated by a pipe \"|\".\n\nFor example, \"NFO;9f1c2|Intro;a92116e\".\n\n```go\nfunc LinkRelr(name string) (string, error)\n```\nLinkRelr returns a link to the named group page.\n\nProviding the name \"a group\" will return \"/g/a-group\".\n\n```go\nfunc LinkSites(val string) template.HTML\n```\nLinkSites returns a collection of HTML anchor links that point to websites.\n\nThe val string is a list of website descriptions and their URL ID separated by a semicolon \";\". Multiple website entries are separated by a pipe \"|\".\n\nFor example, \"Site;example.com|Documentation;example.com/doc\".\n\n```go\nfunc MIME(sl *slog.Logger, name string) string\n```\nMIME returns the [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) for the named file.\n\n```go\nfunc MagicAsTitle(sl *slog.Logger, name string) string\n```\nMagicAsTitle returns the magic number description for the named file.\n\n```go\nfunc MagicString(r io.ReadSeeker, sign magicnumber.Signature) string\n```\nMagicString returns the short magic number description, refining ANSI text as static, blinking, or an ANSImation using ansimate, and appending the inner signature for single-file PKLITE compressed COM executables.\n\n```go\nfunc MagicTitle(r io.ReadSeeker, sign magicnumber.Signature) string\n```\nMagicTitle returns the magic number description, refining ANSI escaped text as static, blinking, or an ANSImation using ansimate, and appending the inner signature for single-file PKLITE compressed COM executables.\n\n```go\nfunc MakeLink(id, name, class string, performant bool) (string, error)\n```\nMakeLink returns a HTML anchor link to the named group page. When the performant flag is false, the link will apply additional typography to the group name. But this should not be used for large lists of links as it will significantly slow down the page rendering.\n\nFor example supplying the name \"tport\"\n\n  - with performant false will return a link displaying \"tPORt\"\n  - with performant true will return a link displaying \"Tport\"\n\n```go\nfunc MkdirStale(sl *slog.Logger, src string) string\n```\nMkdirStale makes and/or returns a distinct directory path in the system temporary directory that is used to extract the contents a file download archive.\n\nTo make the directory distinct it is prefixed with the basename of the src file. The returned path should be removed after use.\n\n```go\nfunc OpenGraphImg(unid string, preview, thumbnail dir.Directory) string\n```\nOpenGraphImg returns a URI for a thumbnail that is intended to be used in the 'og:image' content metadata attribute.\n\n```go\nfunc RTF(b []byte) bool\n```\nRTF detects if the content is likely RTF format by checking for a RTF header pattern. RTF files typically start with {\\\\rtf followed by version number.\n\n```go\nfunc ReleaserPair(a, b any) [2]string\n```\nReleaserPair returns the primary and secondary releaser groups as two strings.\n\n```go\nfunc Releasers(prime, second string, magazine bool) template.HTML\n```\nReleasers returns a HTML links for the primary and secondary group names.\n\n```go\nfunc Screenshot(unid, desc string, preview dir.Directory) template.HTML\n```\nScreenshot returns a image element with screenshots for the given unid. If a webp or avif image is available, and a legacy png or jpg image is available, a picture element is used to provide multiple sources for the image. Otherwise, a single img element is used.\n\nThe unid is the filename of the screenshot image without an extension. The desc is the description of the image used for the alt attribute in the img tag. The preview is the directory where the preview images are stored.\n\nSupported formats are webp, png, jpg and avif.\n\n```go\nfunc StatHumanize(name string) (date, bytes, size string)\n```\nStatHumanize returns the last modified date, size in bytes and size formatted of the named file. If the file does not exist, the string \"file not found\" is returned.\n\nAn example of the returned values are:\n\n\t\"2024-Sep-03\", \"4,163\", \"4.2 kB\"\n\n```go\nfunc StripRTF(b []byte) []byte\n```\nStripRTF removes RTF control words and formatting from text content. This handles RTF version 1.0 standard patterns comprehensively.\n\nThis first runs [RTF](#RTF) and when false returns b unmodified.\n\n```go\nfunc Thumb(unid, desc string, thumbnail dir.Directory, bottom bool) template.HTML\n```\n\n```go\nfunc ThumbSample(unid string, thumbnail dir.Directory) template.HTML\n```\nThumbSample returns a HTML image tag for the given unid. The unid is the filename of the thumbnail image without an extension. The thumbDir is the directory where the thumbnail images are stored.\n\n```go\nfunc Updated(t any, s string) string\n```\nUpdated returns a string of the time since the given time t. If the time is not valid, an empty string is returned. An example of the returned string is:\n\n\t\"Time 1 day ago\"\n\n","path":"github.com/Defacto2/server/handler/internal/simple","name":"simple","synopsis":"Package simple provides functions for handling string or integer input data.","isRedistributable":true}
