@finos/legend-shared
Version:
Legend Studio shared utilities and helpers
68 lines • 4.46 kB
TypeScript
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { type Replacer, parse as losslessParse, isSafeNumber as lossIsSafeNumber } from 'lossless-json';
import { type LocalFile, type ParseLocalConfig, type UnparseConfig } from 'papaparse';
export declare const capitalize: (value: string) => string;
export declare const toSentenceCase: (value: string | undefined) => string;
export declare const TITLE_CASE_EXCEPTION_WORDS: string[];
export declare const toTitleCase: (value: string | undefined) => string;
export declare const prettyCONSTName: (value: string | undefined) => string;
export declare const tryToFormatJSONString: (value: string, tabSize?: number) => string;
export declare const tryToMinifyJSONString: (value: string) => string;
/**
* NOTE: this splits a string value into an array of strings by using a
* delimiter of a comma if the string is only one line. However, if the
* string has multiple lines, the delimiter will not be applied. This is so
* that for an example input of multiple lines like
* One, Comma in One
* Two
* Three
* will still equal 3 elements (['One, Comma in One', 'Two', 'Three']) rather than 4
*/
export declare const parseCSVString: (value: string) => string[] | undefined;
export declare const parseCSVFile: (file: LocalFile, config: ParseLocalConfig<unknown[], LocalFile>) => void;
export declare const csvStringify: (value: unknown[], config?: UnparseConfig) => string;
/**
* One very common use case is that we get the JSON as response from the server than we will convert this to a string and persist
* in the protocol. As such, we have to make sure this string is safe in PURE grammar format, i.e. it will escape single quotes
* properly since PURE strings are wrapped in a pair of single quotes. The following pair of escape/unescape method does the simple job of
* converting a JSON string to/from PURE grammar string
*
* NOTE: this is slightly different than escaping/unescaping JS string or normal JSON string, this is conversion is actually simplier since
* the escaping is naturally handling by string conversion in Javascript, we just need to have special handling for the escaping of single-quotes
* See https://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json
* See https://github.com/joliss/js-string-escape/blob/master/index.js
*/
export declare const fromGrammarString: (value: string) => string;
export declare const toGrammarString: (value: string) => string;
/**
* These are the sets of methods that helps with lossless conversion of JSON to/from text.
*
* The implementation of `JSON.parse` and `JSON.stringify` in Javascript is not lossless, e.g. values like 1.0 (a double) is automatically converted to 1 (an integer).
* This pairs of method will convert the JSON losslessly. One caveat is that numeric values are stored as LosslessNumber, a data type which stores the numeric value as a string.
*
* NOTE: One can perform regular operations with a LosslessNumber, and it will throw an error when this would result in losing information.
* But use this with discretion since it it does not result in the same object as `JSON.parse`
*/
export { losslessParse as parseLosslessJSON };
export { lossIsSafeNumber as isLossSafeNumber };
export declare const stringifyLosslessJSON: (val: unknown, replacer?: Replacer, space?: number | string) => string;
export declare const tryToFormatLosslessJSONString: (value: string, tabSize?: number) => string;
export declare const tryToMinifyLosslessJSONString: (value: string) => string;
export declare const indent: (value: string, indentText: string) => string;
export declare const quantify: (value: number, label: string, pluralForm?: string | undefined) => string;
export declare const quantifyList: (val: Array<unknown>, label: string, pluralForm?: string | undefined) => string;
//# sourceMappingURL=FormatterUtils.d.ts.map