1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 'use strict';
- var GROUP_LEFT_TO_RIGHT,
- GROUP_RIGHT_TO_LEFT,
- EXPRESSION_LEFT_TO_RIGHT,
- EXPRESSION_RIGHT_TO_LEFT;
- /*
- * Character ranges of left-to-right characters.
- */
- GROUP_LEFT_TO_RIGHT = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
- '\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
- '\uFE00-\uFE6F\uFEFD-\uFFFF';
- /*
- * Character ranges of right-to-left characters.
- */
- GROUP_RIGHT_TO_LEFT = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
- /*
- * Expression to match a left-to-right string.
- *
- * Matches the start of a string, followed by zero or
- * more non-right-to-left characters, followed by a
- * left-to-right character.
- */
- EXPRESSION_LEFT_TO_RIGHT = new RegExp(
- '^[^' + GROUP_RIGHT_TO_LEFT + ']*[' + GROUP_LEFT_TO_RIGHT + ']'
- );
- /*
- * Expression to match a right-to-left string.
- *
- * Matches the start of a string, followed by zero or
- * more non-left-to-right characters, followed by a
- * right-to-left character.
- */
- EXPRESSION_RIGHT_TO_LEFT = new RegExp(
- '^[^' + GROUP_LEFT_TO_RIGHT + ']*[' + GROUP_RIGHT_TO_LEFT + ']'
- );
- /**
- * Detect the direction of text.
- *
- * @param {string} value - value to stringify and check.
- * @return {string} - One of `"rtl"`, `"ltr"`, or
- * `"neutral"`.
- */
- function direction(value) {
- value = value.toString();
- if (EXPRESSION_RIGHT_TO_LEFT.test(value)) {
- return 'rtl';
- }
- if (EXPRESSION_LEFT_TO_RIGHT.test(value)) {
- return 'ltr';
- }
- return 'neutral';
- }
- /*
- * Expose `direction`.
- */
- module.exports = direction;
|