Skip to content

Commit

Permalink
Merge pull request #1 from Alwatr/feat/flat-string
Browse files Browse the repository at this point in the history
feat(flat-string): add new package for simplifies the complex C structures that are part of a combined JavaScript string
  • Loading branch information
AliMD authored Dec 20, 2023
2 parents 4be5b28 + ebfdcb3 commit f004d55
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/flat-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Flat String

This function simplifies the complex C structures that are part of a combined JavaScript string.

If you're frequently combining strings and then using that combined string somewhere else, you might discover that running your string through `flatString` significantly enhances performance.

In simpler terms, `flatString` is a function that optimizes the way strings are stored in memory in JavaScript. When you concatenate strings, JavaScript internally creates a complex structure to save memory. However, when you need to use this string, for example, to write it to a file or send it over the network, this complex structure needs to be flattened, which can take time. By using `flatString`, you flatten the string right after concatenation, making the subsequent use of the string faster.
36 changes: 36 additions & 0 deletions packages/flat-string/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@alwatr/flat-string",
"version": "1.0.0",
"description": "The `flat-string` function Flattens the underlying C structures of a concatenated JavaScript string.",
"keywords": [
"string",
"flat",
"optimize",
"concat",
"concatenation",
"util",
"typescript",
"esm",
"alwatr"
],
"main": "main.js",
"type": "module",
"types": "main.d.ts",
"author": "S. Ali Mihandoost <[email protected]>",
"license": "MIT",
"files": [
"**/*.{d.ts.map,d.ts,js.map,js,html,md}"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/Alwatr/nanolib",
"directory": "packages/flat-string"
},
"homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/flat-string#readme",
"bugs": {
"url": "https://github.com/Alwatr/nanolib/issues"
}
}
15 changes: 15 additions & 0 deletions packages/flat-string/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This function simplifies the complex C structures that are part of a combined JavaScript string.
*
* @param str The string to flatten.
* @returns The flattened string.
* @example
* ```typescript
* flatString(myStr);
* ```
*/
export const flatString = (str: string): string => {
// @ts-expect-error because it alters wrong compilation errors.
str | 0;
return str;
};
13 changes: 13 additions & 0 deletions packages/flat-string/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@alwatr/tsconfig-base",

Check failure on line 2 in packages/flat-string/tsconfig.json

View workflow job for this annotation

GitHub Actions / Build & Lint Typescript

File '@alwatr/tsconfig-base' not found.
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "."
},

"include": ["src/**/*.ts"],
"exclude": [],
"references": []
}

0 comments on commit f004d55

Please sign in to comment.