Skip to content

Instantly share code, notes, and snippets.

@Vladmel1234
Last active September 16, 2023 08:48
Show Gist options
  • Save Vladmel1234/1ce78694d98497e83026296f916ba527 to your computer and use it in GitHub Desktop.
Save Vladmel1234/1ce78694d98497e83026296f916ba527 to your computer and use it in GitHub Desktop.
Write to file node
const fs = require('fs');
const { promisify } = require('util');
import _ from 'lodash';
const promisifiedWriteFile = promisify(fs.writeFile);
const main = [
{
category: 'Bitcoin Payments',
links: [
{
slug: 'bitcoin',
payment: 'credit-card',
url: '/crypto/exchanges/bitcoin/credit-card',
text: 'Buy Bitcoin with Credit Card',
},
{
slug: 'bitcoin',
payment: 'paypal',
url: '/crypto/exchanges/bitcoin/paypal',
text: 'Buy Bitcoin with Paypal',
},
{
slug: 'bitcoin',
payment: 'debit-card',
url: '/crypto/exchanges/bitcoin/debit-card',
text: 'Buy Bitcoin with Debit Card',
},
{
slug: 'bitcoin',
payment: 'wire-transfer',
url: '/crypto/exchanges/bitcoin/wire-transfer',
text: 'Buy Bitcoin with Wire Transfer',
},
{
slug: 'bitcoin',
payment: 'cash',
url: '/crypto/exchanges/bitcoin/cash',
text: 'Buy Bitcoin with Cash',
},
{
slug: 'bitcoin',
payment: 'skrill',
url: '/crypto/exchanges/bitcoin/skrill',
text: 'Buy Bitcoin with Skrill',
},
{
slug: 'bitcoin',
payment: 'neteller',
url: '/crypto/exchanges/bitcoin/neteller',
text: 'Buy Bitcoin with Neteller',
},
{
slug: 'bitcoin',
payment: 'ethereum',
url: '/crypto/exchanges/bitcoin/ethereum',
text: 'Buy Bitcoin with Ethereum',
},
]
},
{
category: 'Buy Bitcoin',
links: [
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/united-kingdom',
text: 'Buy Bitcoin in United Kingdom',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/united-states',
text: 'Buy Bitcoin in United States',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/australia',
text: 'Buy Bitcoin in Australia',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/canada',
text: 'Buy Bitcoin in Canada',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/new-zealand',
text: 'Buy Bitcoin in New Zealand',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/singapore',
text: 'Buy Bitcoin in Singapore',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/south-africa',
text: 'Buy Bitcoin in South Africa',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/india',
text: 'Buy Bitcoin in India',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/ireland',
text: 'Buy Bitcoin in Ireland',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/hong-kong',
text: 'Buy Bitcoin in Hong Kong',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/italy',
text: 'Buy Bitcoin in Italy',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/spain',
text: 'Buy Bitcoin in Spain',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/france',
text: 'Buy Bitcoin in France',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/germany',
text: 'Buy Bitcoin in Germany',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/netherlands',
text: 'Buy Bitcoin in Netherlands',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/sweden',
text: 'Buy Bitcoin in Sweden',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/norway',
text: 'Buy Bitcoin in Norway',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/philippines',
text: 'Buy Bitcoin in Philippines',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/qatar',
text: 'Buy Bitcoin in Qatar',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/korea',
text: 'Buy Bitcoin in Korea',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/kuwait',
text: 'Buy Bitcoin in Kuwait',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/dubai',
text: 'Buy Bitcoin in Dubai',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/japan',
text: 'Buy Bitcoin in Japan',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/united-arab-emirates',
text: 'Buy Bitcoin in United Arab Emirates',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/denmark',
text: 'Buy Bitcoin in Denmark',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/greece',
text: 'Buy Bitcoin in Greece',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/portugal',
text: 'Buy Bitcoin in Portugal',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/brazil',
text: 'Buy Bitcoin in Brazil',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/argentina',
text: 'Buy Bitcoin in Argentina',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/russia',
text: 'Buy Bitcoin in Russia',
},
{
slug: 'bitcoin',
payment: '',
url: '/crypto/exchanges/bitcoin/turkey',
text: 'Buy Bitcoin in Turkey',
},
]
},
{
category: 'Ethereum Payments',
links: [
{
slug: 'ethereum',
payment: 'credit-card',
url: '/crypto/exchanges/ethereum/credit-card',
text: 'Buy Ethereum with Credit Card',
},
{
slug: 'ethereum',
payment: 'paypal',
url: '/crypto/exchanges/ethereum/paypal',
text: 'Buy Ethereum with Paypal',
},
{
slug: 'ethereum',
payment: 'debit-card',
url: '/crypto/exchanges/ethereum/debit-card',
text: 'Buy Ethereum with Debit Card',
},
{
slug: 'ethereum',
payment: 'wire-transfer',
url: '/crypto/exchanges/ethereum/wire-transfer',
text: 'Buy Ethereum with Wire Transfer',
},
{
slug: 'ethereum',
payment: 'cash',
url: '/crypto/exchanges/ethereum/cash',
text: 'Buy Ethereum with Cash',
},
{
slug: 'ethereum',
payment: 'skrill',
url: '/crypto/exchanges/ethereum/skrill',
text: 'Buy Ethereum with Skrill',
},
{
slug: 'ethereum',
payment: 'neteller',
url: '/crypto/exchanges/ethereum/neteller',
text: 'Buy Ethereum with Neteller',
},
{
slug: 'ethereum',
payment: 'bitcoin',
url: '/crypto/exchanges/ethereum/bitcoin',
text: 'Buy Ethereum with Bitcoin',
},
]
},
];
// change some stuff in object and return object
// const changePids = async (product) => {
// product.products.forEach((category) => {
// category.links = category.links.map((link) => {
// return {
// ...link,
// pids: [`${link.pids}`]
// };
// });
// });
// return product;
// };
// const addCategory = (obj) => {
// const products = [];
// for (const prop in obj) {
// products.push({
// category: prop,
// transifexTop: 'top-credit-cards-product',
// statesMap: true,
// postfix: 'Credit Cards',
// links: obj[prop]
// });
// }
// return products;
// };
// const group = (collection) => {
// console.log('collection ------>', collection);
// const grouped = _.groupBy(collection, 'category');
// console.log('groupedby -------->', grouped);
// return grouped;
// };
// do not forget to stringfigy before writing to text !important
// writeFile('creditcards.json', JSON.stringify(addCategory(prod)));
// or this version
const writeFile = async (dst, data, cb) => {
const procceedData = cb(data);
promisifiedWriteFile(dst, JSON.stringify(procceedData))
.then(() => console.log('done succsesfuly'))
.catch(err => console.log(err));
};
const zainBaAin = d => (
d.reduce((a, b) => {
a.push({
...b,
links: b.links.map(c => console.log(c) || ({
...c,
id: c.url.replace('/crypto/exchanges/', '').replace(/\//, '.')
})) });
return _.flatten(a);
}, [])
);
writeFile('main.json', main, zainBaAin);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment