Skip to content

Instantly share code, notes, and snippets.

@Gabriellopes232
Last active February 12, 2023 15:09
Show Gist options
  • Save Gabriellopes232/65b9266114cddfadb9fce8906bc8fd16 to your computer and use it in GitHub Desktop.
Save Gabriellopes232/65b9266114cddfadb9fce8906bc8fd16 to your computer and use it in GitHub Desktop.
script to check information from two worksheets
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