Files
react-native/packages/react-native-codegen/src/generators/Utils.js
T
Scott Kyle 269fa37bb8 Indent C++ method declarations
Summary:
This moves the `indent` function into a `Utils` module so it can be also used to properly indent the abstract methods declarations in a C++ TurboModule spec.

Changelog:
Internal

Reviewed By: nlutsenko

Differential Revision: D34704456

fbshipit-source-id: 88a3a672e4860927b5dd1f5107f40da7b5a83e51
2022-03-07 19:21:51 -08:00

34 lines
700 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
'use strict';
function capitalize(string: string): string {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function indent(nice: string, spaces: number): string {
return nice
.split('\n')
.map((line, index) => {
if (line.length === 0 || index === 0) {
return line;
}
const emptySpaces = new Array(spaces + 1).join(' ');
return emptySpaces + line;
})
.join('\n');
}
module.exports = {
capitalize,
indent,
};