jonathanpalma / sivar-utils

TS/JS utils para el desarrollo de sistemas salvadoreños 🇸🇻
https://jonathanpalma.github.io/sivar-utils
MIT License
36 stars 8 forks source link

Tracker for current/new ideas #4

Open ricardoerl opened 4 years ago

ricardoerl commented 4 years ago

I bet there are more ideas on how to keep expanding the library. We can use this issue as initial tracker.

If you like the idea, we can discuss the proposals in the thread and I can update the list here. Then we can migrate the list to the Projects tab or even have it in the readme.

Util Status
isDUI Published
isNIT Published
isPhoneNumber In progress
getPhoneNumberDetails In progress
isPassport Proposal
isPassportFormat Proposal
jonathanpalma commented 4 years ago

Hey @ricardoerl, I like the idea of discussing proposals in this thread, I guess then we can create "feature requests" using the issue template that is already place, so later these can be tracked using Projects.

I was thinking on a couple ones

leosuncin commented 4 years ago

I found the registry of residential and mobile phone numbers, with a scrapping script pull the data and save to CSV or JSON to be used or something more simple like a regex

function isPhoneNumber(phone) {
  const phoneNumberRegex = /^[267]\d{3}-\d{4}$/;
  return phoneNumberRegex.test(phone);
}
jonathanpalma commented 4 years ago

Hey @leosuncin, that's a great one.

What do you think about integrating both of them?

isPhoneNumber

Verifies that given Phone Number format is valid

getPhoneNumberDetails

Get phone numbers details using the information provided by SIGET (we can even use the isMobilePhoneNumber / isResidentialPhoneNumber functions to have a single one for both scenarios residential and mobile)

i.e. getPhoneNumberDetails('7742-0000')

{
  type: 'mobile',
  numberingPlan: {
    owner: 'CTE TELECOM PERSONAL, S.A. de C.V.',
    from: '7740-0000',
    to: '7744-9999',
    qty: 50000,
    resolution: 'T-22-2001',
    assignmentDate: '09/01/2001' // we could even use ISO-format
  }
}

Please let me know if you have any comments or suggestions and we can create a feature request

leosuncin commented 4 years ago

I can open a pull request to add the new to functions, but about the scrapping script I have two proposals:
 

Create a new project

Due the different scope of the new challenge would be a good idea create a new repository with the source code, then run it within a CI environment (maybe Github Actions) every month or so, to scrap the data from the SIGET website and store it in a CSV, JSON and SQLite to be consume it later on, this can be done through a web service, hubdb or Github API.

Add script to this repository

Almost the same above but using only JSON with nanosql to query the data due it works in Node.js and browser.

jonathanpalma commented 4 years ago

@leosuncin I would prefer to keep it under the same repository to take advantage of the infrastructure that is already in place. (This repository is currently using CircleCI)

My only concern is related to the way of storing/consuming these resources.

Consuming

To be consumed from an external resource

Pros

Cons

To be included within the lib as a minified asset

Pros

Cons

Storing

At this moment in which we haven't discussed any other feature where we would need to heavy filter/process data, I don't see the need to implement a DB. Instead, I would suggest applying some normalization (we could even use something like normalizr) and make the calculations using plain algorithms. However, if there is any reason why you think we should use a DB, I am open to discuss it.

Thank you again for your contribution, I am looking forward to your comments ✌️

leosuncin commented 4 years ago

I'm not sure if normalize the data could help cause the keys are a range 7740-0000-7744-9999. I believe a DB library (like NanoSQL or lowdb) would help to query the data.

I don't think the library size could be an issue thanks to bundlers like Rollup, moreover phone number libraries are commonly heavy.

The main pain point is the support for frontend and backend environment, file access in browser is not possible (at least not cross-browser) maybe split the data in JSON files by ranges and lazy loading the required files.
 

async function getPhoneNumberDetails(phone) {
    if (phone > 77400000 && phone < 77449999) {
        const data = await import('./77400000-77449999');
        return data;
    }
    // other ranges
}
jonathanpalma commented 4 years ago

@leosuncin sounds great!

Can you please submit the feature request for both isPhoneNumber and getPhoneNumberDetails so we can have better tracking of them?

jonathanpalma commented 4 years ago

Before I forget it 👀

@all-contributors please add @ricardoerl for ideas

allcontributors[bot] commented 4 years ago

@jonathanpalma

I've put up a pull request to add @ricardoerl! :tada:

alepaz commented 4 years ago

Hey, @ricardoerl I'd like to add the idea and create the PR to validate a passport:

I have thought in the following methods:

isPassport(passport, DUI) this method will have to check first if the DUI is valid and is going to use isPassportFormat

isPassportFormat(passport) this method is only going to validate though regex if the passport is valid

@leosuncin do you know if there any page, repository in which I can check the rules of a passport, or validate that a passport always has the format "A[Your DUI without the validate digit]"?