zip-to-timezone
Advanced tools
Comparing version 1.0.25 to 1.0.26
44
index.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var service_1 = require("./service"); | ||
Object.defineProperty(exports, "ZipToTz", { enumerable: true, get: function () { return service_1.ZipToTz; } }); | ||
exports.ZipToTz = void 0; | ||
const fs = require('fs'); | ||
const yaml = require('js-yaml'); | ||
class ZipToTz { | ||
short(zip) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.getTimeZone(zip, 'timezones_to_zipcodes'); | ||
}); | ||
} | ||
full(zip) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.getTimeZone(zip, 'timezones_to_zipcodes(full name)'); | ||
}); | ||
} | ||
getTimeZone(zip, fileName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const value = zip.replace(/\s/g, ''); | ||
if (!Number.isInteger(Number(value)) || value.length != 5) { | ||
console.log('Invalid format or zipCode length'); | ||
} | ||
const filePath = process.cwd(); | ||
let fileContents = yield fs.readFileSync(`${filePath}/node_modules/zip-to-timezone/src/.${fileName}.yml`, 'utf8'); | ||
let data = yaml.safeLoad(fileContents); | ||
for (const [timezone] of Object.entries(data)) { | ||
const found = data[timezone].find(element => element === value); | ||
if (found) | ||
return timezone; | ||
} | ||
return 'Not found'; | ||
}); | ||
} | ||
} | ||
exports.ZipToTz = ZipToTz; | ||
//# sourceMappingURL=index.js.map |
29
index.ts
@@ -1,1 +0,28 @@ | ||
export {ZipToTz} from './service'; | ||
const fs = require('fs'); | ||
const yaml = require('js-yaml'); | ||
export class ZipToTz { | ||
async short(zip: string): Promise<string> { | ||
return await this.getTimeZone(zip, 'timezones_to_zipcodes'); | ||
} | ||
async full(zip: string): Promise<any> { | ||
return await this.getTimeZone(zip, 'timezones_to_zipcodes(full name)'); | ||
} | ||
private async getTimeZone(zip: string, fileName: string): Promise<string> { | ||
const value = zip.replace(/\s/g, ''); | ||
if (!Number.isInteger(Number(value)) || value.length != 5) { | ||
console.log('Invalid format or zipCode length') | ||
} | ||
const filePath = process.cwd(); | ||
let fileContents = await fs.readFileSync(`${filePath}/node_modules/zip-to-timezone/src/.${fileName}.yml`, 'utf8'); | ||
let data = yaml.safeLoad(fileContents); | ||
for (const [timezone] of Object.entries(data)) { | ||
const found = data[timezone].find(element => element === value) | ||
if (found) | ||
return timezone | ||
} | ||
return 'Not found' | ||
} | ||
} |
{ | ||
"name": "zip-to-timezone", | ||
"version": "1.0.25", | ||
"version": "1.0.26", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
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
1643494
8
91