Comparing version 1.0.1 to 1.0.2
29
index.js
const fs = require('fs'); | ||
const readline = require('readline'); | ||
const fetch = require('node-fetch'); | ||
const unzip = require('unzip'); | ||
const zip = require('node-stream-zip'); | ||
const xml2js = require('xml2js'); | ||
@@ -21,5 +21,4 @@ | ||
self.db = await self.zipInfo(fn, 'path'); | ||
if (!fs.existsSync(self.db) || force) | ||
await self.unzip(fn); | ||
self.db = await self.zipExtract(fn); | ||
@@ -36,18 +35,16 @@ return self; | ||
}, | ||
zipInfo: (fn, prop) => { | ||
zipExtract: (fn, path = './') => { | ||
var z = new zip({file: fn}); | ||
return new Promise((resolve, reject) => { | ||
fs.createReadStream(fn) | ||
.pipe(unzip.Parse()) | ||
.on('error', reject) | ||
.on('entry', entry => resolve(prop ? entry[prop] : entry)); | ||
var xfn = 'sdn.xml'; | ||
z.on('error', reject); | ||
z.on('ready', () => { | ||
z.extract(xfn, path, err => { | ||
if (err) reject(err); | ||
resolve(xfn); | ||
z.close(); | ||
}) | ||
}); | ||
}); | ||
}, | ||
unzip: (fn, path = './') => { | ||
return new Promise((resolve, reject) => { | ||
fs.createReadStream(fn) | ||
.pipe(unzip.Extract({ path })) | ||
.on('error', reject) | ||
.on('close', resolve) | ||
}); | ||
}, | ||
search: (cust, fn = self.db) => { | ||
@@ -54,0 +51,0 @@ // input data clean |
{ | ||
"name": "ofac", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A module to facilitate OFAC searches", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"node-fetch": "^2.3.0", | ||
"unzip": "^0.1.11", | ||
"node-stream-zip": "^1.8.0", | ||
"xml2js": "^0.4.19" | ||
@@ -28,0 +28,0 @@ }, |
@@ -13,14 +13,21 @@ # OFAC | ||
## Installation | ||
## Install | ||
The usual way: | ||
Fetch from from the repository | ||
``` | ||
npm install --save ofac | ||
``` | ||
And set up a usable instance like this: | ||
``` | ||
// using ES6 modules | ||
import ofaq from 'ofac'; | ||
// using CommonJS modules | ||
const ofaq = require('ofac'); | ||
``` | ||
## API | ||
In the CommonJs paradigm, we require the module and subsequently initialise it: | ||
The module must be initialised: | ||
``` | ||
const ofaq = require('ofac'); | ||
ofaq.init().then(...); | ||
@@ -27,0 +34,0 @@ ``` |
@@ -0,1 +1,2 @@ | ||
var fs = require('fs'); | ||
var assert = require('assert').strict; | ||
@@ -31,2 +32,16 @@ const ofac = require('../index.js'); | ||
describe('OFAC', () => { | ||
describe('Archive', () => { | ||
var zip = 'sdn_xml.zip', fn = 'sdn.xml'; | ||
before(() => { | ||
if (fs.existsSync(fn)) fs.unlinkSync(fn); | ||
}) | ||
it('Extraction', async () => { | ||
assert.ok(fs.existsSync(zip), 'Archive does not exist'); | ||
assert.ok(!fs.existsSync(fn), 'Extract exists'); | ||
var actual = await ofac.zipExtract(zip); | ||
assert.equal(actual, fn, 'Extracted a different file'); | ||
assert.ok(fs.existsSync(fn), 'Extract file does not exist'); | ||
}); | ||
}); | ||
describe('search', () => { | ||
@@ -33,0 +48,0 @@ before(() => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14273
193
152
2
+ Addednode-stream-zip@^1.8.0
+ Addednode-stream-zip@1.15.0(transitive)
- Removedunzip@^0.1.11
- Removedbalanced-match@1.0.2(transitive)
- Removedbinary@0.3.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffers@0.1.1(transitive)
- Removedchainsaw@0.1.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfstream@0.1.31(transitive)
- Removedglob@7.2.3(transitive)
- Removedgraceful-fs@3.0.12(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmatch-stream@0.0.2(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednatives@1.1.6(transitive)
- Removedonce@1.4.0(transitive)
- Removedover@0.0.5(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpullstream@0.4.1(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsetimmediate@1.0.5(transitive)
- Removedslice-stream@1.0.0(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedtraverse@0.3.9(transitive)
- Removedunzip@0.1.11(transitive)
- Removedwrappy@1.0.2(transitive)