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:
- Request master to get the latest
blns.json
- if
useLocal
istrue
or network fail, fallback to the localblns.json
- if success, cache the result after download
- return
Promise
orthrow 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:
- Is there any coding style? Personally, I will use
standardjs
as I am just too lazy to define... - Add CI and test cases?
- Should I use
yarn
as package manager instead ofnpm
? - 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 ๐