-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add utility function “splitToTwoLines” for label printer
- Loading branch information
Showing
6 changed files
with
172 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const PUNCTUATION_REGEX = /[ ,-/() ,。/、()]/; | ||
export const LINE_SPLITTING_PUNCTUATION_REGEX = /[,-/(,。/、(]/; | ||
export const T_PUNCTUATION_REGEX = /[ ,-/ ,。/]/; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { breakWords, countChars, splitToTwoLines } from './print-utils'; | ||
|
||
describe('countChars', () => { | ||
it('will return correct char size for CJK characters', async () => { | ||
expect(countChars('你好')).toBe(4); | ||
expect(countChars('你好,world')).toBe(11); | ||
expect(countChars('你好,世界')).toBe(10); | ||
expect(countChars('你好,世界!')).toBe(12); | ||
expect(countChars('你好,世界。')).toBe(12); | ||
}); | ||
}); | ||
|
||
describe('breakWords', () => { | ||
it('will break words', async () => { | ||
expect(breakWords('hello world')).toStrictEqual(['hello', 'world']); | ||
}); | ||
}); | ||
|
||
describe('splitToTwoLines', () => { | ||
it('splits a string into two lines', async () => { | ||
expect(splitToTwoLines('Hello World', 12)).toStrictEqual([ | ||
'Hello World', | ||
'', | ||
]); | ||
expect(splitToTwoLines('Hello World', 8)).toStrictEqual(['Hello', 'World']); | ||
}); | ||
|
||
it('splits a string with punctuation into two lines', async () => { | ||
expect( | ||
splitToTwoLines('SKÅDIS Pegboard, white, 56x56 cm', 15), | ||
).toStrictEqual(['SKÅDIS Pegboard', 'white, 56x56 cm']); | ||
|
||
expect( | ||
splitToTwoLines('SKÅDIS Pegboard, white, 56x56 cm', 16), | ||
).toStrictEqual(['SKÅDIS Pegboard', 'white, 56x56 cm']); | ||
|
||
expect(splitToTwoLines('SKÅDIS Pegboard, 56x56 cm', 24)).toStrictEqual([ | ||
'SKÅDIS Pegboard', | ||
'56x56 cm', | ||
]); | ||
|
||
expect( | ||
splitToTwoLines('SKÅDIS Pegboard, 56x56 cm, white', 24), | ||
).toStrictEqual(['SKÅDIS Pegboard', '56x56 cm, white']); | ||
|
||
expect( | ||
splitToTwoLines('SKÅDIS Pegboard (56x56 cm, white)', 24), | ||
).toStrictEqual(['SKÅDIS Pegboard', '(56x56 cm, white)']); | ||
|
||
// Not supported yet | ||
// expect( | ||
// splitToTwoLines('SKÅDIS Pegboard (56x56 cm, white)', 30), | ||
// ).toStrictEqual(['SKÅDIS Pegboard', '(56x56 cm, white)']); | ||
|
||
expect( | ||
splitToTwoLines('SKÅDIS Pegboard - 56x56 cm - white', 24), | ||
).toStrictEqual(['SKÅDIS Pegboard', '56x56 cm - white']); | ||
}); | ||
}); |
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
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
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
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