dzamiy-npm
v1.0.2
Published
This is a simple utility package that provides functions for text formatting and array sorting. It demonstrates how to create and publish an npm package, and leverages the powerful Lodash library for text formatting and sorting tasks.
Readme
dzamiy-npm
This is a simple utility package that provides functions for text formatting and array sorting. It demonstrates how to create and publish an npm package, and leverages the powerful Lodash library for text formatting and sorting tasks.
这是一个简单的工具包,提供了用于文本格式化和数组排序的功能。它利用了强大的 Lodash 库来完成这些任务。该包易于使用,并展示了如何创建和发布一个 npm 包。
Features / 功能
capitalizeWords(text): Takes a string as input and capitalizes the first letter of each word. This can be useful for formatting titles or headers.capitalizeWords(text):接受一个字符串作为输入,并将每个单词的首字母大写。这对于格式化标题或头部非常有用。sortArray(arr): Takes an array and sorts its elements in ascending order. This can be used to sort numbers or strings.sortArray(arr):接受一个数组并将其元素按升序排列。可以用来对数字或字符串进行排序。
Installation / 安装
To install this package, run the following command in your terminal:
要安装此包,请在终端中运行以下命令:
npm install dzamiy-npmUsage / 使用方法 Once installed, you can use the package in your JavaScript code. Here’s how:
安装后,您可以在 JavaScript 代码中使用此包。使用方法如下: Import the package / 导入包
import MyUtility from 'dzamiy-npm';Example 1: Capitalize Words / 示例 1:首字母大写 The capitalizeWords function capitalizes the first letter of each word in a sentence. This is particularly useful for formatting titles or strings where each word needs to start with an uppercase letter.
capitalizeWords 函数将句子中每个单词的首字母转换为大写。这在格式化标题或需要将每个单词的首字母大写的字符串时特别有用。 const formattedText = MyUtility.capitalizeWords('hello world');
console.log(formattedText); // Output: "Hello World"Example 2: Sort an Array / 示例 2:排序数组 The sortArray function sorts an array of numbers or strings in ascending order.
sortArray 函数将一个数字或字符串数组按升序排序。 const sortedArray = MyUtility.sortArray([5, 3, 8, 1]);
console.log(sortedArray); // Output: [1, 3, 5, 8]