Created
April 18, 2018 14:22
-
-
Save himanshub16/0c528da5a8714d8ad56907da93c7ae85 to your computer and use it in GitHub Desktop.
Script to convert integer IFSC codes to string in Razorpay's IFSC database
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
const ifsc = require('./IFSC') | |
const fs = require('fs') | |
const validate = require('./node/index').validate | |
const ifsc_size = 7 | |
let newIfsc = {} | |
function pad(n, width, z) { | |
z = z || '0' | |
n = String(n) | |
return n.length >= width ? n : (new Array(width - n.length + 1)).join(z) + n | |
} | |
for (let bankCode of Object.keys(ifsc)) { | |
let newBranchCodes = ifsc[bankCode].map(x => pad(x, ifsc_size)) | |
newIfsc[bankCode] = newBranchCodes | |
} | |
let failedifsc = [] | |
for (let bankCode of Object.keys(newIfsc)) { | |
let failedHere = newIfsc[bankCode].filter(x => validate(x)) | |
failedifsc.push(...failedHere) | |
} | |
console.log(failedifsc.length, 'ifscs failed to validate') | |
fs.writeFileSync('newIfsc.json', JSON.stringify(newIfsc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment