npm 上 lc_utils 这个包的源代码

Overview

lc_utils JavaScript开发中常用的工具

获取lc_utils

// npm 全局安装
npm install lc_utils -g
// npm 当前依赖
npm install lc_utils
// yarn 全局安装
yarn global add lc_utils 
// yarn 当前依赖
yarn add lc_utils

简介

​ lc_utils这个工具库主要是集成在开发过程中一些比较常见需求,但是实现起来需要一些比较繁琐的代码。比如查找一个数组中指定项。单纯的基础数据类型的数组还好,如果是一个object的数组。匹配起来就比较麻烦一些。

功能清单

1、lc_utils.is_exist // 数组查询指定项
2、lc_utils.thousands // 为数字或者字符串添加千分位
3、lc_utils.toJson // 自动转换JSON格式的数据
4、lc_utils.getDate // 获取格式化日期

功能示例

​ 1、lc_utils.is_exist 数组查询指定项

// 使用方式
import lc_utils from 'lc_utils';

// 查询的数组
let arr = [{name: 'lc'}, {name: 'lc2'}, {name: 'lc3'}, {name: 'lc4'}];
// 条件: 查询数组中 name 等于 lc 的那一项

// 参数1 = 查询数组
// 参数2 = 匹配内容
// 参数3 = 匹配字段
let res = lc_utils.is_exist(arr, 'lc', 'name');

// res 返回结果是一个对象
{
  match: 'lc',// 查询项
  key: 'name',// 查询字段
  is_exist: true,// 是否存在
  arr: [ { name: 'lc' }, { name: 'lc2' }, { name: 'lc3' }, { name: 'lc4' } ],// 原数组
  index: 0,// 匹配的索引位置
}


// 可以用于普通查询
let intArr = [1,2,3,4,5,6];
// 查询条件: 查找 4 
let res = lc_utils.is_exist(arr, 4);
// 查询结果   
{ match: 4, is_exist: true, arr: [ 1, 2, 3, 4, 5, 6 ], index: 3 }

​ 2、lc_utils.thousands 数字千分位

// 使用方式
import lc_utils from 'lc_utils';
// 参数 number|string
let res = lc_utils.thousands(12334.123);
// res = 12,334.123
let res = lc_utils.thousands('12334.123');
// res = 12,334.123

​ 3、lc_utils.toJson 自动转换json格式的数据,可以自动检测数据类型,对应转成对象或者json字符串

// 使用方式
import lc_utils from 'lc_utils';
let json = '{"name":"lc"}';
let res = lc_utils.toJson(json);
// res = { name: 'lc' };
let obj = { name: 'lc' };
res = lc_utils.toJson(obj);
// res = '{"name":"lc"}'

​ 4、lc_utils.getDate 获取指定格式的日期字符串,根据不同的格式获取自由组合

// 使用方式
import lc_utils from 'lc_utils';
// 获取年
let res = lc_utils.getDate('Y');// res = 2021
// 获取月
res = lc_utils.getDate('M'); // res = 04
// 获取日
res = lc_utils.getDate('D'); // res = 27
// 获取小时
res = lc_utils.getDate('h'); // res = 11
// 获取分钟
res = lc_utils.getDate('m'); // res = 10
// 获取秒
res = lc_utils.getDate('s'); // res = 33

// 参数1说明
Y = 
M = 
D = 
h = 小时
m = 分钟
s = 秒数
// 可以任意自由组合以及连接符

res = lc_utils.getDate('Y-M-D'); // res = 2021-04-27
res = lc_utils.getDate('Y/M/D'); // res = 2021/04/27
res = lc_utils.getDate('Y M D'); // res = 2021 04 27
res = lc_utils.getDate('Y-M-D h:m:s'); // res = 2021-04-27 11:10:33

// 参数2说明
res = lc_utils.getDate('Y-M-D', new Date());// res = 2021-04-27
// 参数二是一个时间对象,或者时间戳或者是正确的时间格式的字符串,可以根据用户传入的不同时间来获取格式化的日期

联系方式

邮箱: [email protected]
公众号: 二哥前端学习之路

​ 该工具库会持续更新,如果哪里写的不好的,请联系我。或者您有更好的一些思路。以及开发过程中遇到一些适合添加到工具库中的也请您联系我。

Npm上的地址

https://www.npmjs.com/package/lc_utils
You might also like...

Package manager faster than NPM

Pine Script holder that runs faster than NPM and yarn Pine is a npm and yarn run like module, that allows you to organize your scripts and run them FA

Jul 10, 2021

Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Nom Does this ever happen to you? You happily code away on a project, navigating the command line like a pro, testing, error logging, installing packa

Apr 26, 2022

NPM Package that simplifies Auth with Google OAuth2 🔐

NPM Package that simplifies Auth with Google OAuth2 🔐

Node Google OAuth2 🔐 A simple authentication flow for Google OAuth2 Explore the docs » Report Bug Table of Contents About The Project Getting Started

Jun 17, 2022

Gerçekten her yeni özellik için npm'de hazır bir modül aramayın, gerek yok, lütfen. DiscordJS ile çok temel bir POST request yapabilirsiniz.

client.api.channels("847172505260261449").messages.post({ data: {"content":"Aşağıdaki menüden kendinize oyun seçebilirsiniz. Bir oyunun rolünü almak i

Nov 29, 2022

portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project Those days of manually updating portfolio website after every new project made are gone ⚡ Yesss . . . you read that right. 😉 portfo

Aug 3, 2021

Example for @Nuggies-bot NPM

giveaways-example Example for @Nuggies-bot NPM setup create a file named .env copy the content of .env.example paste your mongoDB URI and bot token ho

Jan 3, 2023

Instruction how to install laravel echo and pusher without vuejs or even npm

This 2 .js files are used to listen from server broadcasting with laravel-websockets, so that you don't need the use of Vue.js in your laravel app Fol

Sep 28, 2022

best discord selfbot with discord.js-selfbot npm

Discord-Afk-Selfbot best discord selfbot with discord.js-selfbot npm How to start the Bot step by step : Step 1 === Open a CMD the npm init step 2 ==

Aug 18, 2022

"To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. It is created with HTML , CSS , JS and webpack and NPM.

My Todo List "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as com

Mar 29, 2022

Base62-token.js - Generate & Verify GitHub-style & npm-style Base62 Tokens

base62-token.js Generate & Verify GitHub-style & npm-style Secure Base62 Tokens Works in Vanilla JS (Browsers), Node.js, and Webpack. Online Demo See

Jun 11, 2022

A NPM package powered by Yeoman that generates a scaffolding boilerplate for back-end workflow with Node.js.

generator-noderplate Generate Node.js starter files with just one command! We have deployed a npm package that will generate a boilerplate for nodejs

Jan 24, 2022

Instruções para configuração do NPM

Instruções para configuração do NPM

setup-npm Quando trabalhamos com NodeJS, e ao criarmos um novo projeto, existe sempre aquelas configurações que são básicas para configuração do ambie

Dec 8, 2022

Demonstration of how you build full-stack, typed, NPM packages, the right way

NPM Packages - The Right way This repository aims to demonstrate how to build NPM packages the right way. my-package should import the shared code, bu

Nov 27, 2022

Detect npm packages by author name in your package-lock.json or yarn.lock.

detect-package-by-author Detect npm packages by author name in your package-lock.json or yarn.lock. Install Install with npm: # Not Yet Publish # npm

Jan 11, 2022

A simple npm script to generate an .editorconfig file.

Create EditorConfig A simple npm script to generate an .editorconfig file. You don't know EditorConfig? Check out the official documentation! Usage Si

Dec 7, 2022

wasteof-client is an npm package for wasteof.money

wasteof-client is an npm package for wasteof.money

Jun 16, 2022

mineboty is an npm package to make minecraft bot in a minute

mineboty is an npm package to make minecraft bot in a minute . it will help you to make best in pvp will also guard the place

Jan 1, 2023

Bys is an npm/yarn library to merge your js and ts files into one file.

Bundle your scripts (bys) Bys is an npm/yarn library to merge your js and ts files into one file. Installation Use the npm or yarn package manager to

Dec 8, 2022

A Compiler npm Package.

vcompiler 🎉 Version 1.x is live ! 🎉 Introducation It is the npm package for the compilation of the code. Currently it supports the following program

May 30, 2022
Owner
诚信赢天下
一个喜欢学习开发的小菜鸟,期待与各位大佬一起讨论学习。
诚信赢天下
This repository is moving to: https://github.com/npm/cli

We've moved! Hi! This repository is no longer being used and has been archived for historical purposes. ?? CLI Source Code & Pull Requests now live at

npm 17.4k Jan 9, 2023
A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

nwb nwb is a toolkit for: Quick Development with React, Inferno, Preact or vanilla JavaScript Developing: React Apps Preact Apps Inferno Apps Vanilla

Jonny Buchanan 5.5k Jan 3, 2023
700+ Pure CSS, SVG & Figma UI Icons Available in SVG Sprite, styled-components, NPM & API

700+ Pure CSS, SVG & Figma UI Icons Available in SVG Sprite, styled-components, NPM & API

Astrit Malsija 8.9k Jan 2, 2023
Task toolkit. For when `npm run` isn't enough and everything else is too much.

For when npm run isn't enough and everything else is too much. Ygor is a no-frills toolkit consisting of a task runner and a file transformer. Enjoy a

Shannon Moeller 68 Nov 12, 2022
A better `npm publish`

np A better npm publish Why Interactive UI Ensures you are publishing from your release branch (main and master by default) Ensures the working direct

Sindre Sorhus 6.9k Jan 2, 2023
Check NPM package licenses

NPM License Checker As of v17.0.0 the failOn and onlyAllow arguments take semicolons as delimeters instead of commas. Some license names contain comma

Dav Glass 1.5k Dec 29, 2022
:eyeglasses: Node.js module that tells you when your package npm dependencies are out of date.

Node.js module that tells you when your package npm dependencies are out of date. Getting Started Install Node.js. Install david: cd /your/project/dir

Alan Shaw 953 Dec 25, 2022
Open the npm page, Yarn page, or GitHub repo of a package

npm-home Open the npm page, Yarn page, or GitHub repo of a package Install $ npm install --global npm-home Usage $ npm-home --help Usage $ npm

Sindre Sorhus 180 Dec 18, 2022
Check whether a package or organization name is available on npm

npm-name Check whether a package or organization name is available on npm Install $ npm install npm-name Usage import npmName from 'npm-name'; // Ch

Sindre Sorhus 157 Nov 13, 2022
Uses marked-terminal to render a README.md for any npm module in the terminal.

modhelp Uses marked-terminal to render a README.md for any npm module in the terminal. Now with built-in pager! Page up/down, arrow keys to scroll lin

Jason Livesay 23 Feb 8, 2022