mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
65e58f26e1
Summary: Changes `react-native/normalize-color` to be useable from Node.js by making the following changes: 1. Rename `base.js` to `index.js` so importing is more convenient. 2. Move Flow definitions into a seprate library definition flow so `index.js` can be consumed directly. I also made a few improvements to the actual implementation: 1. Avoid allocating `matchers` for non-strings. 2. Avoid allocating an object of all the color keywords. This will reduce memory usage (in exchange for slightly larger compiled bytecode). Changelog: [General][Changed] - react-native/normalize-color now supports Node.js Reviewed By: lunaleaps Differential Revision: D30595908 fbshipit-source-id: e6279e9ff815d8d1f489811187deabfdf53b8fbf
35 lines
891 B
JavaScript
Executable File
35 lines
891 B
JavaScript
Executable File
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
/* eslint no-bitwise: 0 */
|
|
|
|
import _normalizeColor from '@react-native/normalize-color';
|
|
|
|
import type {ColorValue} from './StyleSheet';
|
|
import type {ProcessedColorValue} from './processColor';
|
|
|
|
function normalizeColor(
|
|
color: ?(ColorValue | ProcessedColorValue),
|
|
): ?ProcessedColorValue {
|
|
if (typeof color === 'object' && color != null) {
|
|
const {normalizeColorObject} = require('./PlatformColorValueTypes');
|
|
const normalizedColor = normalizeColorObject(color);
|
|
if (normalizedColor != null) {
|
|
return color;
|
|
}
|
|
}
|
|
|
|
if (typeof color === 'string' || typeof color === 'number') {
|
|
return _normalizeColor(color);
|
|
}
|
|
}
|
|
|
|
module.exports = normalizeColor;
|