Sunday 1 November 2020

split.EOL give different results in Windows

I am trying to split and join the multiple line css values into single line. For eg, we have background-image property in css files. Sometimes that property value will be linear-gradient values. Like below example

background-image: linear-gradient(
right,
#000 0%,
#fff 20%,
#ccc 40%,
#ddd 60%,
#fff 80%,
#000 100%
)

In this above example background-image value splitted into multiple lines. So, what I am trying to do is using this below JS in REACT to join into a single line for specific purpose. This below codes works fine in some Windows machines.

const EOL = require('os');

console.log(getfile.split(EOL));

In this above JS, getfile string contains multiple css files property and values. This above codes returns this below results

Console log Results in Most of the Windows Machine:

[
'background-image: linear-gradient(',
'right,',
'#000 0%,',
'#fff 20%,',
'#ccc 40%,',
'#ddd 60%,',
'#fff 80%,',
'#000 100%',
')'
]

Console log Results in One Windows Machine:

    [
    'background-image: linear-gradient(\n' +
    'right,\n' +
    '#000 0%,\n' +
    '#fff 20%,\n' +
    '#ccc 40%,\n' +
    '#ddd 60%,\n' +
    '#fff 80%,\n' +
    '#000 100%\n' +
    ')'
    ]

This split.(EOL) works in most of the windows machine. But, it didn't work properly in one windows. You can check the console results. There is an \n text added in each line and then + (plus) sign instead of , (comma) in that specific windows. Due to this results it didn't join the multiple line codes into single line in that windows machine.

I am not sure why it occurs in that specific windows machine..

FYI: Both windows machine node versions are above 12



from split.EOL give different results in Windows

No comments:

Post a Comment