npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osmvalidation

v0.0.3

Published

JavaScript library to validate various value-types of OpenStreetMap.

Downloads

3

Readme

osmValidation

JavaScript library to validate various value-types of OpenStreetMap.

Useable in PlainJS, nodeJS and jQuery.

Installation

node.js

Install osmvalidation via npm:

npm install osmvalidation
var osmValidation = require('osmvalidation');

if(osmValidation.phone('+49 123 456-789')) {
    // do stuff
    console.log(osmValidation.msg);
}

jQuery

Download osmValidation.js and include it before you use it.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>osmValidation</title>
    </head>
    <body>
        <form>
            <input type="url" />
            <input type="submit" />
        </form>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript" src="js/osmValidation.js"></script>
        <script type="text/javascript">
            $('input[type=submit]').attr('disabled','disabled');
            $('input[type=url]').onkeyup(function(){
                if($(this).osmValidate()) {
                    $('input[type="submit"]').removeAttr('disabled');
                } else {
                    $('input[type=submit]').attr('disabled','disabled');
                }
            });
        </script>
    </body>
</html>

plain js

Download osmValidation.js and include it before you use it.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>osmValidation</title>
    </head>
    <body>
        <form>
            <input id='url' type="url" />
            <input id='submit' type="submit" />
        </form>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript" src="js/osmValidation.js"></script>
        <script type="text/javascript">
            document.getElementById('submit').onclick(function(){
            	if(osmValidation.url(document.getElementById('url').value) {
                	alert("valid");
                }
            });
        </script>
    </body>
</html>

Functions

  • phone(string) Validate phonenumbers
  • mail(string) Validate mailaddresses
  • url(string) Validate urls
  • facebook(string) Validate facebook ID
  • google(string) Validate google plus ID
  • twitter(string) Validate twitter ID
  • wikipedia(string) Validate wikipedia-Page tag
  • wikidata(string) Validate wikidata-ID

You can validate a givven String as parameter. The return is a boolean (false or true). If you want more informations, you can read msg. This function returns a string with more informations about the validation. If you want to use your own error-messages: every msg-string is a public string-constant of osmValidation. You can compare the return with the constant.

Available constants:

  • PLAIN_FLAG empty string, default message
  • PHONE_EMERGENCY phonenumber is a valid emergency number
  • PHONE_VALID phonenumber is a valid international number
  • PHONE_INVALID number is not a emergency number or an international phonenumber (+\d{1,4} \d+( \d+(-\d+)))
  • MAIL_VALID email is valid
  • MAIL_INVALID email is invalid
  • URL_PROTOCOLL_INVALID URL has no or wrong protocoll. At this time, I allow only http or https
  • URL_LOCAL_ADDRESS URL to a local service is not useful
  • URL_HOST_INVALID Host is not a ipv4- or ipv6-address and it has no fqdn
  • URL_INVALID URL seems broken
  • URL_VALID URL is valid
  • FACEBOOK_ID_ONLY correct facebook ID
  • FACEBOOK_URL_VALID correct facebook-page URL
  • FACEBOOK_URL_INVALID Neither a valid facebook ID nor a plain link (without parameter) to a page
  • TWITTER_ID_ONLY correct twitter ID
  • TWITTER_URL_VALID correct twitter-page URL
  • TWITTER_URL_INVALID Neither a valid twitter ID nor a plain link (without parameter) to a page
  • GOOGLE_ID_ONLY correct google ID
  • GOOGLE_NAME_ONLY correct google plus name
  • GOOGLE_URL_VALID correct google-page URL
  • GOOGLE_URL_INVALID Neither a valid google ID, name nor a plain link (without parameter) to a page
  • WIKIPEDIA_INCLUDING_LANG correct wikipedia page-name including language-tag
  • WIKIPEDIA_EXCLUDING_LANG correct wikipedia page-name without language-tag
  • WIKIPEDIA_URL correct wikipedia url
  • WIKIPEDIA_INVALID Wikipedia-Tag not valid
  • WIKIDATA_VALID_TAG correct wikidata tag
  • WIKIDATA_INVALID Wikidata-Tag not valid

jQuery

There is a special jQuery-Function. You can validate an object by the function osmValidate(). It use the type- or data-type-attribute of the object as identifier for the validation-function. It returns a boolean, NOT the object itself!