spacetrim
Advanced tools
Comparing version 0.9.27 to 0.11.0
@@ -1,4 +0,4 @@ | ||
var nonce = "38ea8d83-fe54-47cd-9519-90a90c58596f_" + Math.floor(Math.random() * 100000); | ||
var SPACE = "__SPACE_" + nonce + "__"; | ||
var NEWLINE = "__NEWLINE_" + nonce + "__"; | ||
var NONCE = "38ea8d83-fe54-47cd-9519-90a90c58596f"; | ||
var SPACE = "__SPACE_" + NONCE + "__"; | ||
var NEWLINE = "__NEWLINE_" + NONCE + "__"; | ||
@@ -9,7 +9,7 @@ /** | ||
function protectBlockContent(blockContent) { | ||
return blockContent | ||
.split('\n') | ||
.join(NEWLINE) | ||
.split(' ') | ||
.join(SPACE); | ||
if (typeof blockContent !== 'string') { | ||
// Note: This can happen when using in javascript and not in typescript | ||
throw new TypeError("spaceTrim nested block expected string, but got " + typeof blockContent); | ||
} | ||
return blockContent.split('\n').join(NEWLINE).split(' ').join(SPACE); | ||
} | ||
@@ -45,3 +45,5 @@ | ||
/** | ||
* topTrim trims given string from top | ||
* Trims given string from top | ||
* | ||
* @private withing the repository | ||
*/ | ||
@@ -75,3 +77,5 @@ function topTrim(content) { | ||
/** | ||
* verticalTrim trims given string from top and bottom | ||
* Trims string from top and bottom new lines | ||
* | ||
* @private withing the repository | ||
*/ | ||
@@ -88,3 +92,7 @@ function verticalTrim(content) { | ||
/** | ||
* Trimming string from all 4 sides | ||
* Trims string from all 4 sides | ||
* | ||
* Note: `spaceTrimSimple` does not support nested blocks, `spaceTrim` does | ||
* | ||
* @private withing the repository | ||
*/ | ||
@@ -152,4 +160,14 @@ function spaceTrimSimple(content) { | ||
} | ||
else if (content instanceof Promise) { | ||
return content | ||
.then(function (value) { | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
throw new TypeError("spaceTrim expected string or Promise<string>, but got " + typeof value); | ||
}) | ||
.then(restoreBlockContent); | ||
} | ||
else { | ||
return content.then(restoreBlockContent); | ||
throw new TypeError("spaceTrim expected string or Promise<string>, but got " + typeof content); | ||
} | ||
@@ -166,3 +184,3 @@ } | ||
else { | ||
throw new Error(spaceTrim("\n spaceTrim expected\n\n ")); | ||
throw new TypeError("spaceTrim expected string or function as first argument, but got " + typeof contentOrcreateContent); | ||
} | ||
@@ -174,3 +192,3 @@ } | ||
export { spaceTrim as default, spaceTrim, spaceTrimSimple, topTrim, verticalTrim }; | ||
export { spaceTrim as default, spaceTrim }; | ||
//# sourceMappingURL=index.js.map |
import { spaceTrim } from './spaceTrim'; | ||
import { spaceTrimSimple } from './spaceTrimSimple'; | ||
import { topTrim } from './topTrim'; | ||
import { verticalTrim } from './verticalTrim'; | ||
export default spaceTrim; | ||
export { spaceTrim, spaceTrimSimple, verticalTrim, topTrim }; | ||
export { spaceTrim }; |
/** | ||
* Trims whitespace from all 4 sides with nested substrings | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function spaceTrimNested(createContent: (block: (blockContent: string) => string) => string): string; | ||
export declare function spaceTrimNested(createContent: (block: (blockContent: string) => string) => Promise<string>): Promise<string>; |
/** | ||
* Trimming string from all 4 sides | ||
* Trims string from all 4 sides | ||
* | ||
* Note: `spaceTrimSimple` does not support nested blocks, `spaceTrim` does | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function spaceTrimSimple(content: string): string; |
/** | ||
* topTrim trims given string from top | ||
* Trims given string from top | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function topTrim(content: string): string; |
/** | ||
* verticalTrim trims given string from top and bottom | ||
* Trims string from top and bottom new lines | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function verticalTrim(content: string): string; |
@@ -7,5 +7,5 @@ (function (global, factory) { | ||
var nonce = "38ea8d83-fe54-47cd-9519-90a90c58596f_" + Math.floor(Math.random() * 100000); | ||
var SPACE = "__SPACE_" + nonce + "__"; | ||
var NEWLINE = "__NEWLINE_" + nonce + "__"; | ||
var NONCE = "38ea8d83-fe54-47cd-9519-90a90c58596f"; | ||
var SPACE = "__SPACE_" + NONCE + "__"; | ||
var NEWLINE = "__NEWLINE_" + NONCE + "__"; | ||
@@ -16,7 +16,7 @@ /** | ||
function protectBlockContent(blockContent) { | ||
return blockContent | ||
.split('\n') | ||
.join(NEWLINE) | ||
.split(' ') | ||
.join(SPACE); | ||
if (typeof blockContent !== 'string') { | ||
// Note: This can happen when using in javascript and not in typescript | ||
throw new TypeError("spaceTrim nested block expected string, but got " + typeof blockContent); | ||
} | ||
return blockContent.split('\n').join(NEWLINE).split(' ').join(SPACE); | ||
} | ||
@@ -52,3 +52,5 @@ | ||
/** | ||
* topTrim trims given string from top | ||
* Trims given string from top | ||
* | ||
* @private withing the repository | ||
*/ | ||
@@ -82,3 +84,5 @@ function topTrim(content) { | ||
/** | ||
* verticalTrim trims given string from top and bottom | ||
* Trims string from top and bottom new lines | ||
* | ||
* @private withing the repository | ||
*/ | ||
@@ -95,3 +99,7 @@ function verticalTrim(content) { | ||
/** | ||
* Trimming string from all 4 sides | ||
* Trims string from all 4 sides | ||
* | ||
* Note: `spaceTrimSimple` does not support nested blocks, `spaceTrim` does | ||
* | ||
* @private withing the repository | ||
*/ | ||
@@ -159,4 +167,14 @@ function spaceTrimSimple(content) { | ||
} | ||
else if (content instanceof Promise) { | ||
return content | ||
.then(function (value) { | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
throw new TypeError("spaceTrim expected string or Promise<string>, but got " + typeof value); | ||
}) | ||
.then(restoreBlockContent); | ||
} | ||
else { | ||
return content.then(restoreBlockContent); | ||
throw new TypeError("spaceTrim expected string or Promise<string>, but got " + typeof content); | ||
} | ||
@@ -173,3 +191,3 @@ } | ||
else { | ||
throw new Error(spaceTrim("\n spaceTrim expected\n\n ")); | ||
throw new TypeError("spaceTrim expected string or function as first argument, but got " + typeof contentOrcreateContent); | ||
} | ||
@@ -183,5 +201,2 @@ } | ||
exports.spaceTrim = spaceTrim; | ||
exports.spaceTrimSimple = spaceTrimSimple; | ||
exports.topTrim = topTrim; | ||
exports.verticalTrim = verticalTrim; | ||
@@ -188,0 +203,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
import { spaceTrim } from './spaceTrim'; | ||
import { spaceTrimSimple } from './spaceTrimSimple'; | ||
import { topTrim } from './topTrim'; | ||
import { verticalTrim } from './verticalTrim'; | ||
export default spaceTrim; | ||
export { spaceTrim, spaceTrimSimple, verticalTrim, topTrim }; | ||
export { spaceTrim }; |
/** | ||
* Trims whitespace from all 4 sides with nested substrings | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function spaceTrimNested(createContent: (block: (blockContent: string) => string) => string): string; | ||
export declare function spaceTrimNested(createContent: (block: (blockContent: string) => string) => Promise<string>): Promise<string>; |
/** | ||
* Trimming string from all 4 sides | ||
* Trims string from all 4 sides | ||
* | ||
* Note: `spaceTrimSimple` does not support nested blocks, `spaceTrim` does | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function spaceTrimSimple(content: string): string; |
/** | ||
* topTrim trims given string from top | ||
* Trims given string from top | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function topTrim(content: string): string; |
/** | ||
* verticalTrim trims given string from top and bottom | ||
* Trims string from top and bottom new lines | ||
* | ||
* @private withing the repository | ||
*/ | ||
export declare function verticalTrim(content: string): string; |
{ | ||
"name": "spacetrim", | ||
"version": "0.9.27", | ||
"version": "0.11.0", | ||
"description": "Spacetrim is trimming string from all 4 sides. It is very helpful to keep pretty code indentation without keeping a strange spaces inside a strings.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -6,3 +6,2 @@ # ✂️ Space trim | ||
[![License of ✂️ Space trim](https://img.shields.io/github/license/hejny/spacetrim.svg?style=flat)](https://github.com/hejny/spacetrim/blob/main/LICENSE) | ||
@@ -18,11 +17,16 @@ [![NPM Version of ✂️ Space trim](https://badge.fury.io/js/spacetrim.svg)](https://www.npmjs.com/package/spacetrim) | ||
Spacetrim is trimming string from all 4 sides.<br/> | ||
It is very helpful to keep pretty code indentation without keeping a strange spaces inside a strings. | ||
Spacetrim is trimming string from all 4 sides. | ||
It is very helpful to keep pretty code indentation without keeping strange spaces inside a string. | ||
<!--Wallpaper--> | ||
<!--⚠️WARNING: This section was generated by https://github.com/hejny/batch-project-editor/blob/main/src//workflows/315-ai-generated-wallpaper/4-aiGeneratedWallpaperUseInReadme.ts so every manual change will be overwritten.--> | ||
<!-- | ||
[![Wallpaper of ✂️ Space trim](assets/ai/wallpaper/gallery/425d6259-2bb1-4173-99f8-a19c6b8254a5-0_0.png)](https://www.midjourney.com/app/jobs/425d6259-2bb1-4173-99f8-a19c6b8254a5) | ||
--> | ||
<!--/Wallpaper--> | ||
- ░ is whitespace and spaceTrim will trim the string at the boundaries ╔═╗ | ||
> ░ is whitespace and `spaceTrim` will trim the string at the boundaries ╔═╗ | ||
@@ -47,9 +51,9 @@ ``` | ||
```typescript | ||
import { spaceTrim } from 'spacetrim'; | ||
import spaceTrim from 'spacetrim'; | ||
const trimmed = spaceTrim(` | ||
Hello | ||
Space | ||
Trim | ||
Hello | ||
Space | ||
Trim | ||
@@ -149,18 +153,8 @@ | ||
<a href="https://collboard.com/"> | ||
<img src="https://collboard.fra1.cdn.digitaloceanspaces.com/assets/18.12.1/logo-small.png" alt="Collboard logo" width="50" /> | ||
</a> | ||
| ||
<a href="https://czech.events/"> | ||
<img src="https://czech.events/design/logos/czech.events.transparent-logo.png" alt="Czech.events logo" width="50" /> | ||
</a> | ||
| ||
<a href="https://sigmastamp.ml/"> | ||
<img src="https://www.sigmastamp.ml/sigmastamp-logo.white.svg" alt="SigmaStamp logo" width="50" /> | ||
</a> | ||
[Become a partner](https://www.pavolhejny.com/contact/) | ||
<!--/Partners--> |
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
40278538
1041
157