@cobalt-ui/utils
Advanced tools
Comparing version 0.5.0 to 0.5.1
# @cobalt-ui/utils | ||
## 0.5.1 | ||
### Patch Changes | ||
- ea165fd: Minor improvement to indent util | ||
## 0.5.0 | ||
@@ -4,0 +10,0 @@ |
@@ -1,21 +0,2 @@ | ||
export interface IndentOptions { | ||
/** default: space */ | ||
character?: string; | ||
/** default: 2 */ | ||
count?: number; | ||
/** default: false */ | ||
includeEmptyLines?: boolean; | ||
} | ||
/** | ||
* Indent | ||
* The main difference between this and the "indent-string" package | ||
* is that this saves your indent options, making it easier to configure. | ||
* Also, it normalizes indent, making it serve as both indent and dedent. | ||
*/ | ||
export declare class Indenter { | ||
private char; | ||
private count; | ||
private includeEmptyLines; | ||
constructor(opts?: IndentOptions); | ||
indent(str: string, level: number): string; | ||
} | ||
/** indent string by level */ | ||
export declare function indent(input: string, level?: number): string; |
@@ -1,36 +0,9 @@ | ||
const TRAILING_SPACE_RE = /\s*$/; | ||
/** | ||
* Indent | ||
* The main difference between this and the "indent-string" package | ||
* is that this saves your indent options, making it easier to configure. | ||
* Also, it normalizes indent, making it serve as both indent and dedent. | ||
*/ | ||
export class Indenter { | ||
char = ' '; | ||
count = 2; | ||
includeEmptyLines = false; | ||
constructor(opts) { | ||
if (typeof opts?.character === 'string') | ||
this.char = opts.character; | ||
if (typeof opts?.count === 'number') | ||
this.count = opts.count; | ||
if (typeof opts?.includeEmptyLines === 'boolean') | ||
this.includeEmptyLines = opts.includeEmptyLines; | ||
/** indent string by level */ | ||
export function indent(input, level = 0) { | ||
let startingWS = ''; | ||
for (let n = 0; n < level; n++) { | ||
startingWS += ' '; | ||
} | ||
indent(str, level) { | ||
const { char, count, includeEmptyLines } = this; | ||
const prefix = new Array(count * level + 1).join(char); | ||
return str | ||
.split('\n') | ||
.map((ln) => { | ||
// handle empty line | ||
const isEmptyLine = !ln.trim(); | ||
if (isEmptyLine) | ||
return includeEmptyLines ? prefix : ''; | ||
// indent | ||
return `${prefix}${ln.replace(TRAILING_SPACE_RE, '')}`; | ||
}) | ||
.join('\n'); | ||
} | ||
return `${startingWS}${input.trim()}`; | ||
} | ||
//# sourceMappingURL=indent.js.map |
@@ -37,4 +37,6 @@ /** UTF-8 char ranges */ | ||
export function objKey(name, wrapper = "'") { | ||
if (name[0] === '0' && name.length > 1) | ||
return `${wrapper}${name}${wrapper}`; // zero-prefixed numbers get wrapper | ||
return VALID_KEY.test(name) ? name : `${wrapper}${name}${wrapper}`; | ||
} | ||
//# sourceMappingURL=string.js.map |
{ | ||
"name": "@cobalt-ui/utils", | ||
"description": "Generic codegen utilities", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Drew Powers", |
@@ -1,44 +0,8 @@ | ||
export interface IndentOptions { | ||
/** default: space */ | ||
character?: string; | ||
/** default: 2 */ | ||
count?: number; | ||
/** default: false */ | ||
includeEmptyLines?: boolean; | ||
} | ||
const TRAILING_SPACE_RE = /\s*$/; | ||
/** | ||
* Indent | ||
* The main difference between this and the "indent-string" package | ||
* is that this saves your indent options, making it easier to configure. | ||
* Also, it normalizes indent, making it serve as both indent and dedent. | ||
*/ | ||
export class Indenter { | ||
private char = ' '; | ||
private count = 2; | ||
private includeEmptyLines = false; | ||
constructor(opts?: IndentOptions) { | ||
if (typeof opts?.character === 'string') this.char = opts.character; | ||
if (typeof opts?.count === 'number') this.count = opts.count; | ||
if (typeof opts?.includeEmptyLines === 'boolean') this.includeEmptyLines = opts.includeEmptyLines; | ||
/** indent string by level */ | ||
export function indent(input: string, level = 0): string { | ||
let startingWS = ''; | ||
for (let n = 0; n < level; n++) { | ||
startingWS += ' '; | ||
} | ||
indent(str: string, level: number): string { | ||
const {char, count, includeEmptyLines} = this; | ||
const prefix = new Array(count * level + 1).join(char); | ||
return str | ||
.split('\n') | ||
.map((ln) => { | ||
// handle empty line | ||
const isEmptyLine = !ln.trim(); | ||
if (isEmptyLine) return includeEmptyLines ? prefix : ''; | ||
// indent | ||
return `${prefix}${ln.replace(TRAILING_SPACE_RE, '')}`; | ||
}) | ||
.join('\n'); | ||
} | ||
return `${startingWS}${input.trim()}`; | ||
} |
@@ -41,3 +41,4 @@ /** UTF-8 char ranges */ | ||
export function objKey(name: string, wrapper = "'"): string { | ||
if (name[0] === '0' && name.length > 1) return `${wrapper}${name}${wrapper}`; // zero-prefixed numbers get wrapper | ||
return VALID_KEY.test(name) ? name : `${wrapper}${name}${wrapper}`; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13794
184