From 08fa77696185de7e094c16d4dcc93d759187efbd Mon Sep 17 00:00:00 2001 From: Samuel Kopp <62482066+boywithkeyboard@users.noreply.github.com> Date: Fri, 16 Jun 2023 20:30:22 +0200 Subject: [PATCH] update examples in readme (#381) * update examples in readme * remove example for deno * add note for npm package --- README.md | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7592403..876d37e 100644 --- a/README.md +++ b/README.md @@ -116,36 +116,27 @@ end Alternatively you can use the `disposable_mail` gem: https://github.com/oesgalha/disposable_mail. -### NodeJs -contributed by [@martin-fogelman](https://github.com/martin-fogelman) +### Node.js +contributed by [@boywithkeyboard](https://github.com/boywithkeyboard) -```Node -'use strict'; +```js +import { readFile } from 'node:fs/promises' -const readline = require('readline'), - fs = require('fs'); +let blocklist -const input = fs.createReadStream('./disposable_email_blocklist.conf'), - output = [], - rl = readline.createInterface({input}); +async function isDisposable(email) { + if (!blocklist) { + const content = await readFile('disposable_email_blocklist.conf', { encoding: 'utf-8' }) -// PROCESS LINES -rl.on('line', (line) => { - console.log(`Processing line ${output.length}`); - output.push(line); -}); - -// SAVE AS JSON -rl.on('close', () => { - try { - const json = JSON.stringify(output); - fs.writeFile('disposable_email_blocklist.json', json, () => console.log('--- FINISHED ---')); - } catch (e) { - console.log(e); + blocklist = content.split('\r\n').slice(0, -1) } -}); + + return blocklist.includes(email.split('@')[1]) +} ``` +Alternatively you can use the [is-disposable library](https://github.com/boywithkeyboard/is-disposable). + ### C# ```C# private static readonly Lazy> _emailBlockList = new Lazy>(() =>