gautamkrishnar/naughtychecker.js

Get online resource, fallback to local if not able to get it?

Closed this issue ยท 6 comments

To get the latest blns.json the lib should always call https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.json at the beginning.

Suggested logic change:

  1. Request master to get the latest blns.json
  2. if useLocal is true or network fail, fallback to the local blns.json
  3. if success, cache the result after download
  4. return Promise or throw Error

Suggested API:

// Options:
{
  useLocal: false // default false
}

nc.validate(text, [options]) โ‡’ Promise
nc.validateAll([text], [options]) โ‡’ Promise

Sample Code:

// ES7 syntax
import nc from 'naughtychecker'

const sampleFunction = async () => {
  try {
    const pass = await nc.validate('text')
    // pass
  catch (e) {
    // handle error
  }
}

@siutsin Looking great... Can you please open a PR with the changes, if you are interested in working on this...

Sure, I can help on this. Before I start, would like to know how I can contribute:

  1. Is there any coding style? Personally, I will use standardjs as I am just too lazy to define...
  2. Add CI and test cases?
  3. Should I use yarn as package manager instead of npm?
  4. This change is API breaking; I updated the first post to make it a bit more future proof.

a quick preview: https://github.com/siutsin/naughtychecker.js/tree/feature/promisifyLibrary

Can you push a develop branch so I don't have to send the PR to master?

Sure... I will make further changes to make it compatible with the previous version...
Develop branch created... ๐Ÿ‘
Thank you for your interest in contributing... Currently i dont follow any style guides. You can use standardjs if you want. Currently there is also no tests specified for the project, you can add those as well. ๐Ÿ˜„

Please dont forget to remove the .idea folder generated by the IDE before opening a pull request ๐Ÿ˜„

#3 created. Removed .idea.