1.0.0 • Published 6 years ago

cubaprovincias v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

What is «cubaprovincias»

This is a Cuban phone number's parser utility for nodejs.

Very useful, not only for work with phone numbers, also, if need Cuban provinces as uniform data. For example: "choose region from the list", while database has a number field named «province».

Install

Install is pretty difficult because is completely different to the common way. (sarcasm)

npm install cubaprovincias

If everything was fine, you should have cubaprovincias recorded in you storage device. Search for the string «cubaprovincias» in your package.json and node_modules directory.

Warning: No more jokes after the below line

Usage

I prefer call «CubanNumber» to instances, because work with phone numbers (almost the time).

// call «CubanNumber» to instances, because work with phone numbers
const CubanNumber = require('cubaprovincias')

// or if you does not need phone number framework
const Provinces = require('cubaprovincias').prototype.provinces

Provinces and Prefix

Does you need prefix-province relation? That info your are looking for, is just an {} in the class.

const Provinces = require('cubaprovincias').prototype.provinces
Provinces[7] // 'La Habana'
Provinces[24] // 'Holguín'
Provinces[32] // 'Camagüey'

Prefix number 5, is reserved for cell phone numeration in Cuba.

Provinces[5] // '(Cell Phone)'

Parsing a phone number.

Processing a number means "get their local dialing prefix and province name", regardless input format. Assuming "input" is a common fancy format but not your own weird custom format.

// load it
const CubanNumber = require('cubaprovincias')

// working with a cell phone
let number = new CubanNumber('+53 (5) 234 56-78')
number.getPrefix() // 5
number.getProvince() // '(Cell Phone)'
number.flatNumber() // '52345678'


// reverse payment incoming number
// (just like is displayed in the caller id)
let incoming = new CubanNumber('99535270405099')
entrante.getProvince() // '(Cell Phone)'
entrante.flatNumber() // '52704050'

// reverse payment outgoing number
// *99 prefixed when you are dialing
let dialing = new CubanNumber('*9952704050')
dialing.getProvince() // '(Cell Phone)'
dialing.flatNumber() // '52704050'


// Havana number, with  international prefix, +53 or 00
// no matter how fancy writing, it can be converted to local number
(new CubanNumber('007 [870] 3344')).flatNumber() // '78703344'
(new CubanNumber('+53 (7) 870 33-44')).flatNumber() // '78703344'


// a number with international dialing prefix, get province name
(new CubanNumber('+53 (7) 870 33-44')).getProvince() // 'La Habana'

// get the local dialing prefix as number
// Warning, it RETURNS a Number (NOT a String)
(new CubanNumber('007 [870] 3344')).getPrefix() // 7


// a number from Artemisa (or Mayabeque) just like you dial it
// from fixed phones. Note that, 47 represents both provinces
// Mayabeque and Artemisa, so, I'm using «/» to represent that duality.
(new CubanNumber('047-876-123')).getProvince() // 'Mayabeque/Artemisa'

That's all.