librejsgopher

package module
Version: v0.0.0-...-63bf967 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2016 License: Apache-2.0 Imports: 4 Imported by: 2

README

LibreJS-Gopher

LibreJS-Gopher is a Go package (as well as offering binary) that handles:

  1. The management and organization of OSI-approved and LibreJS licenses and their known (if any) magnet links for usage with LibreJS.
  2. The checking of licensing information of files.
  3. The wrapping of JavaScript files with LibreJS compliant license header and footers.

Current Stable Release: 0.2

Contributing

This project leverages CodeUtils for development and adopts the CodeUtils Usage Spec. To learn how to contribute to this project and set up CodeUtils, read here.

Binary

Downloading

You can download the pre-compiled binary via the latest stable release here, it is available in the "binary" folder of the tarball.

Compiling

Requirements:

  • Download and build nflag.

Instructions:

Go to binary folder and run the following: go build -o libregopher libregopher.go

Usage

You can see the usage of the binary by running:

./libregopher or ./libregopher --help

Package

Import

You can import and use this software by using the line:

import "github.com/JoshStrobl/librejs-gopher"

Don't have it? Use:

go get github.com/JoshStrobl/librejs-gopher
Usage
Variables

The following variables are exposed and useful when leveraging LibreJS-Gopher.

Name Description Type
LicenseMap LicenseMap is a map of license names to magnet URLs map[string]string
Structs

The following structs are used and exposed throughout the package

LibreJSMetaInfo: This structure contains the name and associated magnet link.

type LibreJSMetaInfo struct {
    License string
    Magnet  string
}
Funcs

The following functions are available for usage by LibreJS-Gopher.

AddLicense

This function will add a valid LibreJS short-form header and footer to the file. You can set to write the file automatically. We will always return new file content or an error.

func AddLicenseInfo(license string, file string, writeContentAutomatically bool) (string, error)

Notes:

  1. license must correspond with a valid license exposed by LicenseMap.
  2. license is automatically parsed using ParseLicenseName()

Example:

// --- Faux file content ---
// potato potato potato

newFileContent, addError := AddLicenseInfo("Apache-2.0", "potato.js", true)

// --- New File content ---

// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt Apache-2.0
// potato potato potato
// @license-end
AddLicenseInfo

This function is a backwards-compatible function. Originally landing in 0.1, this function was responsible for adding the license to the JavaScript file. That function has since been renamed to AddLicense and thus this function solely calls AddLicense. This function will be deprecated in 0.3.

For documentation, refer to the AddLicense documentation.

GetFileLicense

This function will get the license of the file, assuming it uses a valid LibreJS short-form header.

func GetFileLicense(file string) (LibreJSMetaInfo, error)

Example:

// --- Faux file content ---

// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
// blah blah JS blah
// @license-end

// -- Go Call --

metaInfo, error := GetFileLicense("path/to/file.min.js")

// -- metaInfo --
// type LibreJsMetaInfo struct {
// License : AGPL-3.0
// Magnet : magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt
// }
GetMagnetLink

This function will get a magnet link of the associated license exists. Returns string for magnet link, error if item does not exist.

func GetMagnetLink(license string) (string, error)

Notes:

  1. license is automatically parsed using ParseLicenseName()

Example:

// Returns string: magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt
// Returns error: nil
magnetURL, magnetGetError := librejsgopher.GetMagnetLink("Apache-2.0")
ParseLicenseName

This function will attempt to parse the provided license into a more logic naming scheme used in LicenseMap.

func ParseLicenseName(license string) string

Example:

// Returns LGPL-2.1
parsedLicenseName := ParseLicenseName("lgpl 2.1")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LicenseMap map[string]string

LicenseMap is a map of license names to magnet URLs

View Source
var LicensesCapitalizedStrings []string

LicensesCapitalizedStrings is array of strings where each string is a license name or sub-string that needs to be capitalized

Functions

func AddLicense

func AddLicense(license string, file string, writeContentAutomatically bool) (string, error)

AddLicense will add a valid LibreJS short-form header and footer to the file. You can set to write the file automatically (we will always return new file content or an error)

func AddLicenseInfo

func AddLicenseInfo(license string, file string, writeContentAutomatically bool) (string, error)

AddLicenseInfo is a backwards-compatible call that actually calls AddLicenseInfo

func FileLicenseLineParser

func FileLicenseLineParser(returnContentChannel chan LibreJSMetaInfo, lineContent string)

FileLicenseLineParser handles individual line parsing

func GetMagnetLink(license string) (string, error)

GetMagnetLink will get a magnet link of the associated license exists Returns string for magnet link, error if item does not exist

func IsLicense

func IsLicense(license string) bool

IsLicense will return whether this is a valid license in the LicenseMap or not

func ParseLicenseName

func ParseLicenseName(license string) string

ParseLicenseName will attempt to parse the provided license into a more logic naming scheme used in LicenseMap

Types

type LibreJSMetaInfo

type LibreJSMetaInfo struct {
	License string
	Magnet  string
}

LibreJSMetaInfo is a struct containing the name and associated magnet link

func GetFileLicense

func GetFileLicense(file string) (LibreJSMetaInfo, error)

GetFileLicense will get the license of the file, assuming it uses a valid LibreJS short-form header.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL