Last active
February 12, 2023 15:09
-
-
Save Gabriellopes232/65b9266114cddfadb9fce8906bc8fd16 to your computer and use it in GitHub Desktop.
script to check information from two worksheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readFileSync, writeFileSync } from 'fs' | |
function readCSV(path) { | |
const fileSystem = readFileSync(path, { encoding: 'utf-8' }) | |
const plateRegex = new RegExp(/[A-Z]{3}[0-9][0-9A-Z][0-9]{2}/g) | |
const plates = fileSystem.toString().match(plateRegex) | |
return plates; | |
} | |
const worksheetsPlates1 = readCSV('./planilhas-placas1.csv') | |
const worksheetsPlates2 = readCSV('./planilhas-placas2.csv') | |
const filterWorksheetsExist = worksheetsPlates2.filter((plate) => worksheetsPlates1.includes(plate)) | |
const filterWorksheetsNotExist = worksheetsPlates2.filter((plate) => !worksheetsPlates1.includes(plate)) | |
console.log(filterWorksheetsExist) | |
console.log(filterWorksheetsNotExist) | |
const transformExistJSON = JSON.stringify(filterWorksheetsExist, 2) | |
const transformNotExistJSON = JSON.stringify(filterWorksheetsNotExist, 2) | |
writeFileSync('placas-validas.json', transformExistJSON) | |
writeFileSync('placas-invalidas.json', transformNotExistJSON) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment