utils

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package utils provides utility functions for commonmeta.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFromFormat

func FindFromFormat(p params) string

FindFromFormat finds the commonmeta read format

func FindFromFormatByDict

func FindFromFormatByDict(dct map[string]interface{}) string

FindFromFormatByDict finds the commonmeta reader from format by dictionary

func FindFromFormatByExt

func FindFromFormatByExt(ext string) string

FindFromFormatByExt finds the commonmeta reader from format by file extension

func FindFromFormatByFilename

func FindFromFormatByFilename(filename string) string

FindFromFormatByFilename finds the commonmeta reader from format by filename

func FindFromFormatByID

func FindFromFormatByID(id string) string

FindFromFormatByID finds the commonmeta reader from format by id

func FindFromFormatByString

func FindFromFormatByString(str string) string

FindFromFormatByString finds the commonmeta reader from format by string

func ISSNAsURL added in v0.2.1

func ISSNAsURL(issn string) string

ISSNAsURL returns the ISSN expressed as URL

Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/utils"
)

func main() {
	s := utils.ISSNAsURL("2146-8427")
	fmt.Println(s)
}
Output:

https://portal.issn.org/resource/ISSN/2146-8427

func NormalizeCCUrl

func NormalizeCCUrl(url string) (string, bool)

NormalizeCCUrl returns the normalized Creative Commons License URL

func NormalizeID

func NormalizeID(pid string) string

NormalizeID checks for valid DOI or HTTP(S) URL and normalizes them

func NormalizeORCID

func NormalizeORCID(orcid string) string

NormalizeORCID returns a normalized ORCID URL

func NormalizeROR

func NormalizeROR(ror string) string

NormalizeROR returns a normalized ROR URL

func NormalizeURL added in v0.2.1

func NormalizeURL(str string, secure bool, lower bool) (string, error)

NormalizeURL normalizes URL

func Sanitize

func Sanitize(html string) string

Sanitize removes all HTML tags except for a whitelist of allowed tags. Used for title and description fields.

Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/utils"
)

func main() {
	s := utils.Sanitize("<p>The Origins of SARS-CoV-2: A <i>Critical</i> <a href=\"index.html\">Review</a></p>")
	fmt.Println(s)
}
Output:

The Origins of SARS-CoV-2: A <i>Critical</i> Review

func URLToSPDX added in v0.2.1

func URLToSPDX(url string) string

URLToSPDX provides the SPDX license ID given a Creative Commons URL

func UnescapeUTF8 added in v0.2.1

func UnescapeUTF8(inStr string) (outStr string, err error)

UnescapeUTF8 unescapes UTF-8 characters

Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/utils"
)

func main() {
	s, err := utils.UnescapeUTF8("capable of signi\"cance.")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(s)
}
Output:

capable of signi"cance.

func ValidateORCID

func ValidateORCID(orcid string) (string, bool)

ValidateORCID validates an ORCID

func ValidateROR

func ValidateROR(ror string) (string, bool)

ValidateROR validates a ROR

Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/utils"
)

func main() {
	s, _ := utils.ValidateROR("https://ror.org/0342dzm54")
	fmt.Println(s)
}
Output:

0342dzm54

func ValidateURL added in v0.2.1

func ValidateURL(str string) string

ValidateURL validates a URL and checks if it is a DOI

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL