GithubHelp home page GithubHelp logo

fossabot / doi-regex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from regexhq/doi-regex

0.0 1.0 0.0 80 KB

Regular expression for matching DOIs

License: MIT License

JavaScript 18.01% CSS 7.55% HTML 74.43%

doi-regex's Introduction

doi-regex

Build Status FOSSA Status

Regular expression for matching DOIs

Parts of a DOI:

  • Directory Identifier: 10
  • Registrant code: . + [0-9]{4,}
  • Registrant subdivision (optional): . + [0-9]+
  • Suffix: / + any character, case insensitive for ASCII chars (but capitalised in the registry), with some characters that should be escaped
    Recommended encoding: "{}^[]`|\\&\/\'<>
    Mandatory encoding: %"#? and space.

From: http://www.doi.org/doi_handbook/2_Numbering.html#2.2

Install

$ npm install --save doi-regex

Usage

var doiRegex = require('doi-regex');

// contains a DOI
doiRegex().test('unicorn 10.1000/xyz000');
//=> true

// is a DOI address
doiRegex({exact: true}).test('unicorn 10.1000/xyz000');
//=> false

doiRegex.declared({exact: true}).test('doi:10.1000/xyz000');
//=> true

doiRegex.groups().test('10.1000/xyz1000.a001');
//=> ['10.1000/xyz1000', '10.1000/xyz1000', '.a001']

'unicorn 10.1000/xyz000 cake 10.1000/xyz001 rainbow'.match(doiRegex());
//=> ['10.1000/xyz000', '10.1000/xyz000']

API

doiRegex(options)

Returns a regex for matching a DOI.

doiRegex.declared(options)

Returns a regex for matching a DOI that has been declared with a doi: string in front.

doiRegex.groups(doi)

Returns a regex match object with a final string as the first two indices, and any suffixes that are commonly used for supplemental information if they are attached to the doi. For instance, 10.1000/journal.pone.0000000.g001 would return 10.1000/journal.pone.0000000 and .g001.

options.exact

Type: boolean
Default: false (Matches any DOI in a string)

Only match an exact string.
Useful with RegExp#test to check if a string is an DOI.

CLI

A CLI file has been provided. Run any of the examples provided above using your own DOI. For instance:

$ node cli-index.js -e 10.000/xyz1000
//=> true

Possible Flags:

  • -e, --exact Find an exact match
  • -d, --declared Find a DOI with a 'doi:' prefix
  • -m, --match Find all matches within the given string
  • -g, --groups Find the stripped DOI and any suffix it might have
  • -h, --help Display usage

Contribute

Please do!

License

MIT © Richard Littauer

FOSSA Status

doi-regex's People

Contributors

fossabot avatar greenkeeper[bot] avatar katrinleinweber avatar richardlitt avatar

Watchers

 avatar

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.