Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flat-string): add new package for simplifies the complex C structures that are part of a combined JavaScript string #1

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <ali.mihandoost@gmail.com>",
"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": []
}
Loading