Documentation
¶
Overview ¶
Package utils provides utility functions for commonmeta.
Index ¶
- func CamelCaseString(str string) string
- func CamelCaseToWords(str string) string
- func CheckORCIDNumberRange(orcid string) bool
- func CommunitySlugAsURL(slug string, host string) string
- func DecodeID(id string) (int64, error)
- func DedupeSlice[T comparable](sliceList []T) []T
- func FindFromFormat(p Params) string
- func FindFromFormatByExt(ext string) string
- func FindFromFormatByFilename(filename string) string
- func FindFromFormatByID(id string) string
- func FindFromFormatByMap(m map[string]interface{}) string
- func FindFromFormatByString(str string) string
- func GetLanguage(lang string, format string) string
- func ISSNAsURL(issn string) string
- func KebabCaseToCamelCase(str string) string
- func KebabCaseToPascalCase(str string) string
- func NormalizeCCUrl(url_ string) (string, bool)
- func NormalizeID(pid string) string
- func NormalizeORCID(orcid string) string
- func NormalizeOrganizationID(id string) string
- func NormalizePersonID(id string) string
- func NormalizeROR(ror string) string
- func NormalizeString(s string) (string, error)
- func NormalizeURL(str string, secure bool, lower bool) (string, error)
- func NormalizeWorkID(id string) string
- func ParseString(s interface{}) string
- func SPDXToURL(id string) string
- func Sanitize(html string) string
- func SplitString(str string, n int, s string) string
- func StringToSlug(str string) string
- func TitleCase(str string) string
- func URLToSPDX(url string) string
- func UnescapeUTF8(inStr string) (outStr string, err error)
- func ValidateCrossrefFunderID(fundref string) (string, bool)
- func ValidateGRID(grid string) (string, bool)
- func ValidateID(id string) (string, string)
- func ValidateIDCategory(id string) (string, string, string)
- func ValidateISNI(isni string) (string, bool)
- func ValidateISSN(issn string) (string, bool)
- func ValidateORCID(orcid string) (string, bool)
- func ValidateRID(rid string) (string, bool)
- func ValidateROR(ror string) (string, bool)
- func ValidateURL(str string) string
- func ValidateUUID(uuid string) (string, bool)
- func ValidateWikidata(wikidata string) (string, bool)
- func WordsToCamelCase(str string) string
- type Params
- type ROR
Examples ¶
- CamelCaseToWords
- CommunitySlugAsURL
- DecodeID
- FindFromFormatByExt
- FindFromFormatByFilename
- FindFromFormatByID
- FindFromFormatByMap
- GetLanguage
- GetROR
- ISSNAsURL
- KebabCaseToCamelCase
- KebabCaseToPascalCase
- NormalizeCCUrl
- NormalizeID
- NormalizeORCID
- NormalizeOrganizationID
- NormalizeROR
- NormalizeString
- NormalizeURL
- SPDXToURL
- Sanitize
- SplitString
- StringToSlug
- URLToSPDX
- UnescapeUTF8
- ValidateCrossrefFunderID
- ValidateGRID
- ValidateID
- ValidateIDCategory
- ValidateISNI
- ValidateISSN
- ValidateORCID
- ValidateRID
- ValidateROR
- ValidateUUID
- ValidateWikidata
- WordsToCamelCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelCaseString ¶ added in v0.3.1
CamelCaseString converts a pascal case string to camel case
func CamelCaseToWords ¶ added in v0.2.14
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.CamelCaseToWords("earthAndRelatedEnvironmentalSciences") fmt.Println(s) }
Output: Earth and related environmental sciences
func CheckORCIDNumberRange ¶ added in v0.19.0
check if ORCID is in the range 0000-0001-5000-0007 and 0000-0003-5000-0001 or between 0009-0000-0000-0000 and 0009-0010-0000-0000
func CommunitySlugAsURL ¶ added in v0.5.16
CommunitySlugAsURL returns the InvenioRDM community slug expressed as globally unique URL
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.CommunitySlugAsURL("irights", "rogue-scholar.org") fmt.Println(s) }
Output: https://rogue-scholar.org/api/communities/irights
func DecodeID ¶ added in v0.6.30
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.DecodeID("https://doi.org/10.59350/b8pcg-q9k70") fmt.Println(s) }
Output: 387298385203
func DedupeSlice ¶
func DedupeSlice[T comparable](sliceList []T) []T
DedupeSlice removes duplicates from a slice https://stackoverflow.com/questions/66643946/how-to-remove-duplicates-strings-or-int-from-slice-in-go/76948712#76948712
func FindFromFormat ¶
FindFromFormat finds the commonmeta read format
func FindFromFormatByExt ¶
FindFromFormatByExt finds the commonmeta reader from format by file extension
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.FindFromFormatByExt(".bib") fmt.Println(s) }
Output: bibtex
func FindFromFormatByFilename ¶
FindFromFormatByFilename finds the commonmeta reader from format by filename
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.FindFromFormatByFilename("CITATION.cff") fmt.Println(s) }
Output: cff
func FindFromFormatByID ¶
FindFromFormatByID finds the commonmeta reader from format by id
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.FindFromFormatByID("https://api.rogue-scholar.org/posts/4e4bf150-751f-4245-b4ca-fe69e3c3bb24") fmt.Println(s) }
Output: jsonfeed
func FindFromFormatByMap ¶ added in v0.6.48
FindFromFormatByMap finds the commonmeta reader from format by map
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { f := map[string]any{ "schemaVersion": "http://datacite.org/schema/kernel-4", } s := utils.FindFromFormatByMap(f) fmt.Println(s) }
Output: datacite
func FindFromFormatByString ¶
FindFromFormatByString finds the commonmeta reader from format by string
func GetLanguage ¶ added in v0.5.1
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.GetLanguage("de", "iso639-3") fmt.Println(s) }
Output: deu
func ISSNAsURL ¶ added in v0.2.1
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 KebabCaseToCamelCase ¶ added in v0.6.10
KebabCaseToCamelCase converts a kebab case string to camel case
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.KebabCaseToCamelCase("earth-and-related-environmental-sciences") fmt.Println(s) }
Output: earthAndRelatedEnvironmentalSciences
func KebabCaseToPascalCase ¶ added in v0.6.10
KebabCaseToPascalCase converts a kebab case string to pascal case
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.KebabCaseToPascalCase("earth-and-related-environmental-sciences") fmt.Println(s) }
Output: EarthAndRelatedEnvironmentalSciences
func NormalizeCCUrl ¶
NormalizeCCUrl returns the normalized Creative Commons License URL
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, ok := utils.NormalizeCCUrl("https://creativecommons.org/licenses/by/4.0") fmt.Println(s, ok) }
Output: https://creativecommons.org/licenses/by/4.0/legalcode true
func NormalizeID ¶
NormalizeID checks for valid DOI or HTTP(S) URL and normalizes them
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.NormalizeID("10.1101/097196") fmt.Println(s) }
Output: https://doi.org/10.1101/097196
func NormalizeORCID ¶
NormalizeORCID returns a normalized ORCID URL
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.NormalizeORCID("0000-0002-1825-0097") fmt.Println(s) }
Output: https://orcid.org/0000-0002-1825-0097
func NormalizeOrganizationID ¶ added in v0.19.0
NormalizeOrganizationID normalizes organization ID
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.NormalizeOrganizationID("https://ror.org/0342dzm54") fmt.Println(s) }
Output: https://ror.org/0342dzm54
func NormalizePersonID ¶ added in v0.19.0
NormalizePersonID normalizes person ID
func NormalizeROR ¶
NormalizeROR returns a normalized ROR URL
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.NormalizeROR("http://ror.org/0342dzm54") fmt.Println(s) }
Output: https://ror.org/0342dzm54
func NormalizeString ¶ added in v0.10.3
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.NormalizeString("Investigación-Digital💿") fmt.Println(s) }
Output: Investigacion-Digital💿
func NormalizeURL ¶ added in v0.2.1
NormalizeURL normalizes URL
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.NormalizeURL("http://elifesciences.org/Articles/91729", true, true) fmt.Println(s) }
Output: https://elifesciences.org/articles/91729
func NormalizeWorkID ¶ added in v0.19.0
NormalizeWorkID normalizes work ID
func ParseString ¶ added in v0.6.10
func ParseString(s interface{}) string
ParseString parses an interface into a string
func SPDXToURL ¶ added in v0.6.49
SPDXToURL provides the SPDX license URL given a Creative Commons SPDX ID
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.SPDXToURL("CC-BY-4.0") fmt.Println(s) }
Output: https://creativecommons.org/licenses/by/4.0/legalcode
func Sanitize ¶
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 SplitString ¶ added in v0.19.0
func SplitString adds a hyphen every n characters
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.SplitString("0000000121122291", 4, " ") fmt.Println(s) }
Output: 0000 0001 2112 2291
func StringToSlug ¶ added in v0.10.3
StringToSlug makes a string lowercase and removes non-alphanumeric characters
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.StringToSlug("Investigación-Digital💿") fmt.Println(s) }
Output: investigaciondigital
func TitleCase ¶ added in v0.2.8
TitleCase capitalizes the first letter of a string without changing the rest
func URLToSPDX ¶ added in v0.2.1
URLToSPDX provides the SPDX license ID given a Creative Commons URL
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.URLToSPDX("https://creativecommons.org/licenses/by/4.0/legalcode") fmt.Println(s) }
Output: CC-BY-4.0
func UnescapeUTF8 ¶ added in v0.2.1
UnescapeUTF8 unescapes UTF-8 characters
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.UnescapeUTF8("capable of signi\"cance.") fmt.Println(s) }
Output: capable of signi"cance.
func ValidateCrossrefFunderID ¶ added in v0.19.0
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateCrossrefFunderID("https://doi.org/10.13039/501100001659") fmt.Println(s) }
Output: 501100001659
func ValidateGRID ¶ added in v0.19.0
ValidateGRID validates a GRID ID GRID ID is a string prefixed with grid followed by dot number dot string
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateGRID("https://www.grid.ac/institutes/grid.1017.7") fmt.Println(s) }
Output: grid.1017.7
func ValidateID ¶ added in v0.2.14
ValidateID validates an identifier and returns the type Can be DOI, UUID, ISSN, ORCID, ROR, URL, RID, Wikidata, ISNI or GRID
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, t := utils.ValidateID("https://ror.org/0342dzm54") fmt.Println(s, t) }
Output: 0342dzm54 ROR
func ValidateIDCategory ¶ added in v0.19.0
ValidateIDCategory validates an identifier and returns the identifier, type, and category Category can be work, person, organization, contributor (person or organization), or all
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { _, _, s := utils.ValidateIDCategory("https://ror.org/0342dzm54") fmt.Println(s) }
Output: Organization
func ValidateISNI ¶ added in v0.19.0
ValidateISNI validates an ISNI ISNI is a 16-character string in blocks of four optionally separated by hyphens or spaces and NOT between 0000-0001-5000-0007 and 0000-0003-5000-0001, or between 0009-0000-0000-0000 and 0009-0010-0000-0000 (the ranged reserved for ORCID).
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateISNI("https://isni.org/isni/000000012146438X") fmt.Println(s) }
Output: 000000012146438X
func ValidateISSN ¶ added in v0.2.14
ValidateISSN validates an ISSN
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateISSN("https://portal.issn.org/resource/ISSN/2146-8427") fmt.Println(s) }
Output: 2146-8427
func ValidateORCID ¶
ValidateORCID validates an ORCID ORCID is a 16-character string in blocks of four separated by hyphens between 0000-0001-5000-0007 and 0000-0003-5000-0001, or between 0009-0000-0000-0000 and 0009-0010-0000-0000.
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateORCID("https://orcid.org/0000-0002-1825-0097") fmt.Println(s) }
Output: 0000-0002-1825-0097
func ValidateRID ¶ added in v0.6.65
ValidateRID validates a RID RID is the unique identifier used by the InvenioRDM platform
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateRID("nryd8-14284") fmt.Println(s) }
Output: nryd8-14284
func ValidateROR ¶
ValidateROR validates a ROR ID. The ROR ID starts with 0 followed by a 6-character alphanumeric string which is base32-encoded and a 2-digit checksum.
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
ValidateURL validates a URL and checks if it is a DOI
func ValidateUUID ¶ added in v0.2.14
ValidateUUID validates a UUID
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateUUID("2491b2d5-7daf-486b-b78b-e5aab48064c1") fmt.Println(s) }
Output: 2491b2d5-7daf-486b-b78b-e5aab48064c1
func ValidateWikidata ¶ added in v0.19.0
ValidateWikidata validates a Wikidata item ID Wikidata item ID is a string prefixed with Q followed by a number
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s, _ := utils.ValidateWikidata("https://www.wikidata.org/wiki/Q7186") fmt.Println(s) }
Output: Q7186
func WordsToCamelCase ¶ added in v0.6.49
CamelCaseString converts a pascal case string to camel case
Example ¶
package main import ( "fmt" "github.com/front-matter/commonmeta/utils" ) func main() { s := utils.WordsToCamelCase("Earth and related environmental sciences") fmt.Println(s) }
Output: earthAndRelatedEnvironmentalSciences
Types ¶
type ROR ¶ added in v0.2.14
type ROR struct { ID string `json:"id"` Name string `json:"name"` Types []string `json:"types"` ExternalIds struct { FundRef struct { Preferred string `json:"preferred"` All []string `json:"all"` } `json:"FundRef"` } `json:"external_ids"` }
ROR represents a Research Organization Registry (ROR) record