forked from FINAKON/HelpProject
1. Initial Commit - a boiler plate code and POC to realize the concept of context sensitive help 2. Frontend code written in ReactJS 3. Backend code written in Java, Spring Boot Framework 4. Frontend Start: pre-requisites : node, npm npm run dev ==> to start the frontend vite server 5. Backend Start: pre-requisites : java, mvn mvn spring-boot:run ==> to start the backend server 6. Visit http://localhost:5173/ for basic demo of help, press F1 in textboxes 7. Visit http://localhost:5173/editor and enter "admin123" to add/modify texts. Happy Coding !!! Thank you, Bhargava.
75 lines
1.6 KiB
JavaScript
75 lines
1.6 KiB
JavaScript
/**
|
|
* @typedef Options
|
|
* Configuration for `stringify`.
|
|
* @property {boolean} [padLeft=true]
|
|
* Whether to pad a space before a token.
|
|
* @property {boolean} [padRight=false]
|
|
* Whether to pad a space after a token.
|
|
*/
|
|
|
|
/**
|
|
* @typedef {Options} StringifyOptions
|
|
* Please use `StringifyOptions` instead.
|
|
*/
|
|
|
|
/**
|
|
* Parse comma-separated tokens to an array.
|
|
*
|
|
* @param {string} value
|
|
* Comma-separated tokens.
|
|
* @returns {Array<string>}
|
|
* List of tokens.
|
|
*/
|
|
export function parse(value) {
|
|
/** @type {Array<string>} */
|
|
const tokens = []
|
|
const input = String(value || '')
|
|
let index = input.indexOf(',')
|
|
let start = 0
|
|
/** @type {boolean} */
|
|
let end = false
|
|
|
|
while (!end) {
|
|
if (index === -1) {
|
|
index = input.length
|
|
end = true
|
|
}
|
|
|
|
const token = input.slice(start, index).trim()
|
|
|
|
if (token || !end) {
|
|
tokens.push(token)
|
|
}
|
|
|
|
start = index + 1
|
|
index = input.indexOf(',', start)
|
|
}
|
|
|
|
return tokens
|
|
}
|
|
|
|
/**
|
|
* Serialize an array of strings or numbers to comma-separated tokens.
|
|
*
|
|
* @param {Array<string|number>} values
|
|
* List of tokens.
|
|
* @param {Options} [options]
|
|
* Configuration for `stringify` (optional).
|
|
* @returns {string}
|
|
* Comma-separated tokens.
|
|
*/
|
|
export function stringify(values, options) {
|
|
const settings = options || {}
|
|
|
|
// Ensure the last empty entry is seen.
|
|
const input = values[values.length - 1] === '' ? [...values, ''] : values
|
|
|
|
return input
|
|
.join(
|
|
(settings.padRight ? ' ' : '') +
|
|
',' +
|
|
(settings.padLeft === false ? '' : ' ')
|
|
)
|
|
.trim()
|
|
}
|