diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/fbjs/lib/UnicodeBidiDirection.js.flow | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/fbjs/lib/UnicodeBidiDirection.js.flow')
-rw-r--r-- | node_modules/fbjs/lib/UnicodeBidiDirection.js.flow | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/node_modules/fbjs/lib/UnicodeBidiDirection.js.flow b/node_modules/fbjs/lib/UnicodeBidiDirection.js.flow deleted file mode 100644 index 1301fedd8..000000000 --- a/node_modules/fbjs/lib/UnicodeBidiDirection.js.flow +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @providesModule UnicodeBidiDirection - * @typechecks - * @flow - */ - -/** - * Constants to represent text directionality - * - * Also defines a *global* direciton, to be used in bidi algorithms as a - * default fallback direciton, when no better direction is found or provided. - * - * NOTE: Use `setGlobalDir()`, or update `initGlobalDir()`, to set the initial - * global direction value based on the application. - * - * Part of the implementation of Unicode Bidirectional Algorithm (UBA) - * Unicode Standard Annex #9 (UAX9) - * http://www.unicode.org/reports/tr9/ - */ - -'use strict'; - -const invariant = require('./invariant'); - -export type BidiDirection = 'LTR' | 'RTL' | 'NEUTRAL'; -export type HTMLDir = 'ltr' | 'rtl'; - -const NEUTRAL = 'NEUTRAL'; // No strong direction -const LTR = 'LTR'; // Left-to-Right direction -const RTL = 'RTL'; // Right-to-Left direction - -let globalDir: ?BidiDirection = null; - -// == Helpers == - -/** - * Check if a directionality value is a Strong one - */ -function isStrong(dir: BidiDirection): boolean { - return dir === LTR || dir === RTL; -} - -/** - * Get string value to be used for `dir` HTML attribute or `direction` CSS - * property. - */ -function getHTMLDir(dir: BidiDirection): HTMLDir { - invariant(isStrong(dir), '`dir` must be a strong direction to be converted to HTML Direction'); - return dir === LTR ? 'ltr' : 'rtl'; -} - -/** - * Get string value to be used for `dir` HTML attribute or `direction` CSS - * property, but returns null if `dir` has same value as `otherDir`. - * `null`. - */ -function getHTMLDirIfDifferent(dir: BidiDirection, otherDir: BidiDirection): ?HTMLDir { - invariant(isStrong(dir), '`dir` must be a strong direction to be converted to HTML Direction'); - invariant(isStrong(otherDir), '`otherDir` must be a strong direction to be converted to HTML Direction'); - return dir === otherDir ? null : getHTMLDir(dir); -} - -// == Global Direction == - -/** - * Set the global direction. - */ -function setGlobalDir(dir: BidiDirection): void { - globalDir = dir; -} - -/** - * Initialize the global direction - */ -function initGlobalDir(): void { - setGlobalDir(LTR); -} - -/** - * Get the global direction - */ -function getGlobalDir(): BidiDirection { - if (!globalDir) { - this.initGlobalDir(); - } - invariant(globalDir, 'Global direction not set.'); - return globalDir; -} - -const UnicodeBidiDirection = { - // Values - NEUTRAL, - LTR, - RTL, - // Helpers - isStrong, - getHTMLDir, - getHTMLDirIfDifferent, - // Global Direction - setGlobalDir, - initGlobalDir, - getGlobalDir -}; - -module.exports = UnicodeBidiDirection;
\ No newline at end of file |