Summary: More is more. Just moving code, no further changes. Reviewed By: nikoant Differential Revision: D22374891 fbshipit-source-id: 65c9af8b4b34ee8e16aeae5705528093e1c800cc
40 lines
799 B
TypeScript
40 lines
799 B
TypeScript
/**
|
|
* 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
|
|
*/
|
|
|
|
export function getLineCount(str: string): number {
|
|
let count = 1;
|
|
if (!(typeof str === 'string')) {
|
|
return 0;
|
|
}
|
|
for (let i = 0; i < str.length; i++) {
|
|
if (str[i] === '\n') {
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
export function keepKeys<A>(obj: A, keys: Array<string>): A {
|
|
const result: A = {} as A;
|
|
for (const key in obj) {
|
|
if (keys.includes(key)) {
|
|
result[key] = obj[key];
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function pad(chunk: any, len: number): string {
|
|
let str = String(chunk);
|
|
while (str.length < len) {
|
|
str = `0${str}`;
|
|
}
|
|
return str;
|
|
}
|