1.1.22 • Published 5 years ago

medojs v1.1.22

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

Medojs

common

关键词提取

getKey((keys: Array), (list: Array), (fields: Array)); // 关键词列表 待匹配列表 待匹配字段

// 关键词列表数组前面的会优先匹配, 但是针对长度不一样的,还是会优先更长的那一个词 , 可以有3种形式,匹配此的列表

const list = [
  {
    title: "这个一个国家",
    keyword: "国家",
  },
];
const fieldsA = ["title"];
const fieldsB = ["title", "keyword"];
const keysA = [
  {
    meta: "A",
    list: ["国家"],
  },
];
const keysB = [["国家", "一个"], ["一个"]];
const keysC = ["国家", "一个"];

const resA = getKey(keysA, list, fieldsA); // {"0":{"title":{"list":[[4,5,"A","国家"]]}}}
const resB = getKey(keysA, list, fieldsB); // {"0":{"title":{"list":[[4,5,"A","国家"]]},"keyword":{"list":[[0,1,"A","国家"]]}}}
const resC = getKey(keysB, list, fieldsB); // {"0":{"title":{"list":[[4,5,0,"国家"],[2,3,0,"一个"]]},"keyword":{"list":[[0,1,0,"国家"]]}}}
const resD = getKey(keysC, list, fieldsB); // {"0":{"title":{"list":[[4,5,"string","国家"],[2,3,"string","一个"]]},"keyword":{"list":[[0,1,"string","国家"]]}}}

MD5

md5((str: string));

深拷贝

deepCopy((obj: Object));

数组对象化

objectArr((arr: Array), (key: String), (bool: Any));

const arrD = [1, 2, 3];
const arrE = [{ a: 1 }];
console.log(arrObject(arrD)); // { '1': true, '2': true, '3': true }
console.log(arrObject(arrE, "a")); // { '1': { a: 1 } }
console.log(arrObject(arrE, "a", false)); // { '1': false }

数组去重

uniqueArr((arr: Array)); // 简单类型去重 new Set

const arrC = [1, 2, 3, 4, "", "  ", false, null, NaN];
console.log(arrUnique(arrC)); // [1, 2, 3, 4, "", "  ", false, null, NaN]
console.log(arrUnique(arrC, true)); // [ 1, 2, 3, 4 ]

数组合并

concatArr((arr: Array));

const arrA = [1, 2, [3, 4]];
const arrB = [5, 6, [7, 8]];
console.log(arrConcat(arrA, arrB)); // [ 1, 2, [ 3, 4 ], 5, 6, [ 7, 8 ] ]
console.log(arrConcat([arrA, arrB])); // [ 1, 2, [ 3, 4 ], 5, 6, [ 7, 8 ] ]

nodejs

定制打印

customLog;
customLog.success();
customLog.start();
// https://github.com/klaussinani/signale/blob/master/docs/readme.zh_CN.md
// https://github.com/klaussinani/signale/blob/ac40b9a0203334de256d1f097dc59b2af1e80bb0/src/types.js

elastic

const { esScroll, esClient } = require("../nodejs").elastic;
// esClient nodejs 客户端
// https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/master/index.html
async function init() {
  const query = {
    query: {
      match_phrase: {
        title: "小细胞肺癌",
      },
    },
  };
  const config = ["wf_new", "10s", 10000, query];
  const count = await esScroll.count("wf_new", query); // 584
  const data = await esScroll(...config);
  //   {
  //     date: '2016-11-01',
  //     tier: '7',
  //     rank: '2/4',
  //     id: 'zl201609016',
  //     title: '非小细胞肺癌对EGFR-TKIs产生获得性耐药后发生小细胞肺癌转化的研究进展',
  //     keyword: '癌,非小细胞肺,受体,表皮生长因子,抗药性,肿瘤,细胞转化,肿瘤',
  //     uniqueId: '001528d89462296d9688f9e0a6a4adea',
  //     DID: 'a0452cf44295283a5926b12a64bd547d',
  //     md5: '98bb214bcb2aaf8'
  //   }
  config.push(1);
  const dataB = await esScroll(...config);
  //   {
  //     _index: 'wf_new',
  //     _type: '_doc',
  //     _id: 'IuOTH3MBG2Bo3g5gyVz4',
  //     _score: 22.218872,
  //     _source: {
  //       date: '2016-11-01',
  //       tier: '7',
  //       rank: '2/4',
  //       id: 'zl201609016',
  //       title: '非小细胞肺癌对EGFR-TKIs产生获得性耐药后发生小细胞肺癌转化的研究进展',
  //       keyword: '癌,非小细胞肺,受体,表皮生长因子,抗药性,肿瘤,细胞转化,肿瘤',
  //       uniqueId: '001528d89462296d9688f9e0a6a4adea',
  //       DID: 'a0452cf44295283a5926b12a64bd547d',
  //       md5: '98bb214bcb2aaf8'
  //     }
  //   }
}

文件操作

const fileAction = new FileAction(dir); // dir 根目录,定位 rpath
fileAction.rPath(); // 定位到根目录
fileAction.read(); // 递归读取
fileAction.remove(); // 递归删除
fileAction.mkdir(); // 递归创建

限制 HTTP 请求数

const medoLimitHttp = new LimitHttp(count); // 每分钟请求数
const bool = medoLimitHttp.add(name); // name 用户名,返回是否还有请求次数

mongoose

// 比较多,有时间再写
1.1.22

5 years ago

1.1.21

5 years ago

1.1.19

5 years ago

1.1.20

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.11

5 years ago

1.0.12

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago