1.2.4 • Published 4 years ago

url-prop-type v1.2.4

Weekly downloads
147
License
MIT
Repository
github
Last release
4 years ago

URL Prop Type

Greenkeeper badge Build Status codecov npm npm bundle size npm-total-downloads GitHub

Introduction

This package is used to validate if a React Prop value is a valid URL. A valid URL can be a valid absolute URL (like https://github.com/jaebradley/url-prop-type) or a relative-absolute URL (starts with a /).

Currently, there is no URL prop type defined by the prop-types package. While using PropType.string works, why not be as specific as possible when validating your props?

Additionally, though it's relatively straightforward to create a custom prop type validator, if you need to implement similar prop type checking in multiple packages, you might not want to repeat yourself.

Depends on the is-url package.

Installation

npm install --save url-prop-type

Example Usage

import React from 'react';
import PropTypes from 'prop-types';
import urlPropType from 'url-prop-type';

// Create a basic Hyperlink Component
const Hyperlink = props => ( <a href={props.link}>{props.text}</a> );

Hyperlink.propTypes = {
  text: PropTypes.string.isRequired,
  link: urlPropType.isRequired, // can also specify urlPropType if it is not required
};

Alternatives

I didn't see many alternatives:

1.2.4

4 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago