Coder Social home page Coder Social logo

billinghamj / vrm-node Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 3.0 19 KB

Coerces, validates and prettifies vehicle registration marks (VRMs)

Home Page: https://www.npmjs.com/package/vrm

License: MIT License

JavaScript 100.00%
vrm dvla nodejs javascript vehicle

vrm-node's Introduction

vrm

Coerces, validates and prettifies vehicle registration marks (VRMs). Presently, only UK DVLA registration plate formats are supported. Please open an issue if you'd like to see support added for other driving authorities' formats - I'd be keen to work with you to enable this.

import VRM from 'vrm';

console.log(VRM.coerce('Lbo7 se0')); // => [{ format: 'gb_2001', vrm: 'LB07SEO', prettyVrm: 'LB07 SEO' }]
console.log(VRM.coerce('Lbo7 se0', ['gb_2001'])); // => [{ format: 'gb_2001', vrm: 'LB07SEO', prettyVrm: 'LB07 SEO' }]
console.log(VRM.coerce('Lbo7 se0', ['gb_1903'])); // => []
console.log(VRM.info('LB07SEO')); // => { format: 'gb_2001', vrm: 'LB07SEO', prettyVrm: 'LB07 SEO' }
console.log(VRM.info('LB07SEO', 'gb_2001')); // => { format: 'gb_2001', vrm: 'LB07SEO', prettyVrm: 'LB07 SEO' }
console.log(VRM.info('LB07SEO', 'gb_1903')); // => null

Installation

$ npm install vrm

API

VRM.coerce(input[, allowedFormats])

Coerces the input into a set of possible VRMs which the input could represent. See more information below about why this is needed.

The returned array contains the VRM details for each given format, sorted in order of likelihood, where the most likely format is the first value.

If the allowed formats are specified, coercion will be limited to these formats. Any other formats will not be checked.

Returns an empty array if the input is invalid or cannot be coerced into any of the formats checked.

Throws if any of the allowed formats are not known.

VRM.info(normalizedVRM[, format])

Verifies that the given VRM matches one of the known formats and returns the relevant VRM details. Only normalized VRMs are accepted.

If the format is specified, only that format is checked.

Returns null if the VRM does not match any of the formats checked.

Throws if the provided format is not known.

Notes

Formats

The known formats are referenced as the following strings:

  • gb_1903 - AB 1234 - the first number-plates issued under the "Motor Car Act"
  • gb_1932 - ABC 123 - after the above format began to run out
  • gb_1963 - ABC 123A - ditto
  • gb_1983 - A123 ABC - ditto
  • gb_2001 - AB12 ABC - the current GB format
  • ni_1903 - AZ 1234 - roughly equivalent to gb_1903
  • ni_1966 - AAZ 1234 - similar to gb_1932, the current NI format
  • diplomatic - 123 D 123 - used for diplomats (D) and accredited personnel (X)
  • military - AB 12 AB - used for military vehicles

VRM Details

The VRM details objects returned include the following information:

{
	format: 'gb_2001', // required, string - format referenced as-above
	vrm: 'LB07SEO', // required, string - vrm in upper case, no spaces, no special chars, etc.
	prettyVrm: 'LB07 SEO', // optional, string - vrm spaced as legally defined
}

More information is likely to be added to this object over time. These changes would not be considered as 'breaking'.

Coercion

UK registration plates use a particular official typeface which was designed by Charles Wright. Bizarrely, it uses exactly the same physical shape for I and 1, and for O and 0. This means that the exact VRM can be ambiguous and people often mistype the VRM into forms. Additionally, it presents some difficulties for automatic number plate recognition (ANPR) systems.

The coerce method handles this. It returns an array because (occasionally) multiple formats can be possible.

The returned array is ordered with the original input first if it is valid, followed by the other valid options with the newer formats coming first. This behavior could change though, so don't rely on it.

Possible Additions

If there is demand for it, two other bits of functionality could be provided:

  • normalization: normalizing an arbitrary string input without coercing it (this happens internally anyway)
  • extending info: exposing the data contained within a given VRM - e.g. the 2001 UK format contains information about the area and year of registration

Data Sources

Support

Please open an issue on this repository.

Authors

License

MIT licensed - see LICENSE file

vrm-node's People

Contributors

billinghamj avatar dependabot-preview[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vrm-node's Issues

Consider hardcoded format requires for client-side support

First of all, thanks for this nice library. It works great server-side, but it doesn't support client-side because of the use of fs.

Is there any reason why it can't require the VRM formats like below?

const formats = [
	require('./diplomatic.js'),
	require('./gb-1903.js'),
	require('./gb-1932.js'),
	require('./gb-1963.js'),
	require('./gb-1983.js'),
	require('./gb-2001.js'),
	require('./military.js'),
	require('./ni-1903.js'),
	require('./ni-1966.js')
];

Discovering the formats dynamically is better, but the list of formats seems pretty static.

null response for valid VRMs

Hi, thanks for creating this, it's great.

I'm having an issue with two VRMs (out of a dataset of ~10,000), where the info method is returning null, despite the VRMs being valid.

The two VRMs are VIP1 and Q362KUA, both of which are registered vehicles in the UK.

You can verify these vehicles are registered at https://vehicleenquiry.service.gov.uk/ (VIP1 is a Rolls Royce and Q362KUA is a Caterham).

Q362KUA is a Q registration number (see https://www.gov.uk/vehicle-registration/q-registration-numbers), but should match the gb_1983 format.

VIP1 looks like the gb_1932 format.

Do you know why these VRMs return null?

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.