mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
chore(utils): improve stripWhitespace
utility (#9668)
This commit is contained in:
parent
17bbb21b5e
commit
0145578493
@ -29,7 +29,8 @@ const WHITESPACE_REPLACEMENTS = [
|
|||||||
[/{\n{2,}/g, '{\n'], // strip start padding from blocks
|
[/{\n{2,}/g, '{\n'], // strip start padding from blocks
|
||||||
[/\n{2,}([ \t\f\r]*})/g, '\n$1'], // strip end padding from blocks
|
[/\n{2,}([ \t\f\r]*})/g, '\n$1'], // strip end padding from blocks
|
||||||
[/\n{3,}/g, '\n\n'], // strip multiple blank lines (1 allowed)
|
[/\n{3,}/g, '\n\n'], // strip multiple blank lines (1 allowed)
|
||||||
[/\n{2,}$/g, '\n'] // strip blank lines EOF (0 allowed)
|
[/^\n+/, ''], // strip blank lines at the beginning of a string
|
||||||
|
[/\n{2,}$/, '\n'] // strip blank lines at the end of a string
|
||||||
]
|
]
|
||||||
|
|
||||||
export const stripWhitespace = function stripWhitespace (string) {
|
export const stripWhitespace = function stripWhitespace (string) {
|
||||||
|
@ -36,12 +36,12 @@ describe('util: lang', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('should strip white spaces in given argument', () => {
|
test('should strip white spaces in given argument', () => {
|
||||||
expect(stripWhitespace('foo')).toEqual('foo')
|
expect(stripWhitespace('foo\t\r \f\nbar')).toEqual('foo\nbar')
|
||||||
expect(stripWhitespace('foo\t\r\f\n')).toEqual('foo\n')
|
expect(stripWhitespace('foo{\n\n\nbar')).toEqual('foo{\nbar')
|
||||||
expect(stripWhitespace('foo{\n\n\n')).toEqual('foo{\n')
|
expect(stripWhitespace('foo\n\n\n\t \r\f}')).toEqual('foo\n\t \r\f}')
|
||||||
expect(stripWhitespace('\n\n\n\f\r\f}')).toEqual('\n\f\r\f}')
|
|
||||||
expect(stripWhitespace('foo\n\n\nbar')).toEqual('foo\n\nbar')
|
expect(stripWhitespace('foo\n\n\nbar')).toEqual('foo\n\nbar')
|
||||||
expect(stripWhitespace('foo\n\n\n')).toEqual('foo\n')
|
expect(stripWhitespace('\n\nfoo\n')).toEqual('foo\n')
|
||||||
|
expect(stripWhitespace('foo\n\n')).toEqual('foo\n')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should encode html', () => {
|
test('should encode html', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user