GithubHelp home page GithubHelp logo

juancarlospaco / parselicense Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 86 KB

Parse Standard SPDX Licenses from string to Enum

Home Page: https://juancarlospaco.github.io/parselicense

License: MIT License

Nim 100.00%
license-checking license-management spdx-license spdx-licenses spdx nim nim-lang

parselicense's Introduction

parseLicense

  • Parse Standard SPDX Licenses from string to Enum. parseLicense(s: string): License.
  • Tests. Documentation. Examples. Works at compile-time. Fast algo. $ Dollar for human-friendly Standard name.

Use

  static:
    const wtfplTxt = """DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <[email protected]>

Everyone is permitted to copy and distribute verbatim or modified copies of
this license document, and changing it is allowed as long as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

   0. You just DO WHAT THE FUCK YOU WANT TO.
"""
    doAssert parseLicense(wtfplTxt, default = Licenses.Mit) == Licenses.WTFPL
    doAssert parseLicense(wtfplTxt).get() == Licenses.WTFPL


    const zeroBsdTxt = """Copyright (C) 2006 by Rob Landley <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
    doAssert parseLicense(zeroBsdTxt, default = Licenses.Mit) == Licenses.ZeroBSD
    doAssert parseLicense(zeroBsdTxt).get() == Licenses.ZeroBSD


    const fairTxt = """Fair License <Copyright Information>

Usage of the works is permitted provided that this instrument is retained
with the works, so that any entity that uses the works is notified of this
instrument.

DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
"""
    doAssert parseLicense(fairTxt, default = Licenses.Mit) == Licenses.Fair
    doAssert parseLicense(fairTxt).get() == Licenses.Fair

    const beerwareTxt = """"THE BEER-WARE LICENSE" (Revision 42):

<[email protected]> wrote this file. As long as you retain this notice you can
do whatever you want with this stuff. If we meet some day, and you think this
stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
"""
    doAssert parseLicense(beerwareTxt, default = Licenses.Mit) == Licenses.Beerware
    doAssert parseLicense(beerwareTxt,).get() == Licenses.Beerware


    const curlTxt = """COPYRIGHT AND PERMISSION NOTICE Copyright (c) 1996 - 2015, Daniel Stenberg,
<[email protected]>.

All rights reserved.

Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.
"""
    doAssert parseLicense(curlTxt, default = Licenses.Mit) == Licenses.Curl
    doAssert parseLicense(curlTxt,).get() == Licenses.Curl


  ## Works with lowercased and uppercased Licenses.
  const iscTxt = toLowerAscii("""ISC License Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC")

Copyright (c) 1995-2003 by Internet Software Consortium

Permission to use, copy, modify, and /or distribute this software for any
purpose with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
""")
  doAssert parseLicense(iscTxt, default = Licenses.Mit) == Licenses.Isc
  doAssert parseLicense(iscTxt,).get() == Licenses.Isc


  ## Works with invalid Data (Not a License).
  doAssert parseLicense("Invalid data", default = Licenses.Mit) == Licenses.Mit
  doAssert parseLicense("Invalid data").isNone()

JavaScript

Note

I am looking for a better algo that is small code and more efficient and precise, I search and only found modules on other languages that compare whole strings, or compare string lenghts, or compare filenames, or huge try...except chains of that. My algo is what antivirus do basically, it wont need all license files shipped to compare to, if you have a better algo that is faster smaller code and works at compile-time, just send a pull request, and it will be merged.

parselicense's People

Contributors

juancarlospaco avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

pombredanne

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.