utils

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 12 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 CamelCaseString added in v0.3.1

func CamelCaseString(str string) string

CamelCaseString converts a pascal case string to camel case

func CamelCaseToWords added in v0.2.14

func CamelCaseToWords(str string) string
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 DecodeDOI added in v0.2.14

func DecodeDOI(doi string) int64
Example
package main

import (
	"fmt"

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

func main() {
	i := utils.DecodeDOI("https://doi.org/10.73731/rxadv-a6v29")
	fmt.Println(i)
}
Output:
10.73731

func EncodeDOI added in v0.2.14

func EncodeDOI(prefix string) string
Example
package main

import (
	"fmt"

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

func main() {
	s := utils.EncodeDOI("10.73731")
	fmt.Println(s)
}
Output:
https://doi.org/10.73731/rxadv-a6v29

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 TitleCase added in v0.2.8

func TitleCase(str string) string

TitleCase capitalizes the first letter of a string without changing the rest

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 ValidateID added in v0.2.14

func ValidateID(id string) (string, string)

ValidateID validates an identifier and returns the type Can be DOI, UUID, ISSN, ORCID, ROR, URL

func ValidateISSN added in v0.2.14

func ValidateISSN(issn string) (string, bool)

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

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

func ValidateUUID added in v0.2.14

func ValidateUUID(uuid string) (string, bool)

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

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

func GetROR added in v0.2.14

func GetROR(ror string) (ROR, error)

GetROR

Jump to

Keyboard shortcuts

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