npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@less-is-more/less-js

v1.4.39-0

Published

Fast develop kit for nodejs

Downloads

27

Readme

lim-js

介绍

快捷处理函数 nodejs、js。基本实现一行搞定。 [email protected]

安装使用

npm install @less-is-more/less-js

开始

  1. 生成数据库映射对象,可以使用 sequelize-automatic。具体请查看其官方 npm 说明。
  2. src下建立index.js文件,可参考
const { Router, Db, Redis } = require("@less-is-more/less-js");
const ApiController = require("./api/api-controller");
const process = require("process");

exports.init = (context, callback) => {
  Db.init(
    process.env.dbHost,
    process.env.dbDatabase,
    process.env.dbUser,
    process.env.dbPassword
  );
  Redis.init(process.env.redisUrl, "default", process.env.redisPassword);
  callback(null, "");
};
exports.handler = (req, res, context) => {
  res.setHeader("content-type", "application/json");
  const targets = {
    "/api": new ApiController(),
  };
  Router.route(targets, req, res, context);
};
  1. 自动生成增删查改。在项目根的命令行执行,然后选择数据库表
less-js-gen

功能块

具体每个函数有具体说明每个参数的作用,以下不再重复。

Route

简单路由。通常放在函数入口 index 中。 Controller 里面需要执行 send 或者直接 return 一个值(值会自动转换文本,来符合 send 的标准)。

// ProductController为类实现
let targets = {
  "/product": ProductController,
  "/order": OrderController,
};
Router.route(targets, req, res);

Cache

缓存,有数据就返回,没有就调用函数并保存结果。 使用 redis 作为缓存,需要初始化 没有使用 annotation,在 mocha 测试快速。

const { Cache, Redis } = require(" @less-is-more/less-js");
// 初始化一次就可以,可以放公用
Redis.init("地址", "用户名", "密码");

let testFunction = (a, b) => {
  console.log(a + b);
  return a + b + "";
};
// 调用
const result = await Cache.get("test", 20, testFunction, testFunction, 1, 2);

Db

数据库暂时支持 mysql。 使用到 sequelize,对象和查询方法可以参考官方文档

const { Db } = require(" @less-is-more/less-js");
// 初始化一次就可以,可以放公用
Db.init("地址", "数据库", "用户", "密码");
// 简单查询
let data = await Db.find(Menu, { ordering: "1" });
// 带分页
let data = await Db.find(Menu, { ordering: "2" }, [["id", "desc"]], 2, 3);
// 指定返回列
let data = await Db.find(Menu, { ordering: "0" }, [["id", "desc"]], 1, 10, [
  "id",
]);
// 添加,Product是生成对象,可以参考sequelize-automate
Db.add(Product, {
  code: "test",
  name: "产品",
});
// 修改
Db.update(Menu, { name: "test name2", ordering: "2" }, { id: 7 });
// 删除。限制了一条记录
Db.delOne(Menu, { code: "abc" });

Redis

简单封装。命令和官方一样。

const { Redis } = require(" @less-is-more/less-js");
// 初始化一次就可以,可以放公用
Redis.init("地址", "用户名", "密码");
// exec命令,调用官方命令,参数顺序一样
let result = await Redis.exec("get", "test");

Param

参数处理工具。检查参数,错误抛 Error,成功返回参数集合 基本沿用 validator 的方法,https://www.npmjs.com/package/validator check 方法新增 isNotEmpty, require。支持多个,空格隔开。默认 is 类的方法不含空

let params = await Param.checkParams([
  ["返回参数key", value, "isNotEmpty", "错误显示的内容"],
  ["返回参数key2", value2, "isNotEmpty", "错误显示的内容2"],
]);
// 检查是否空
Param.isBlank(value);

Sms

暂时支持阿里云的短信服务

// 初始化一次就可以,可以放公用
Sms.init("key", "secret", "token");
Sms.debug(true);
Sms.send("手机号码", { info: "短信参数" }, "签名", "短信编号");