0.1.14 • Published 5 years ago

yang-lazy-util v0.1.14

Weekly downloads
3
License
ISC
Repository
-
Last release
5 years ago

yang-util-js

English | Chinese

Introduction

JavaScript commonly used tool functions

Software Architecture

es6 + typescript

installation

npm i yang-lazy-util --save or yarn add yang-lazy-util

Use

1. import { objectDiff } from 'yang-lazy-util'
2. import * as utils from 'yang-lazy-util'
3.  const utils = require('yang-lazy-util')

basic function

1. Object traversal (supports multiple levels of nested objects)

import { objectEach } from 'yang-lazy-util';

const result = {
  name: 'yang',
  age: 18,
  info: {
    money: '123',
  },
}
utils.objectEach(result, (key, value) => {
  console.log(key, value);
});

2. Object deep copy

import { objectClone } from 'yang-lazy-util';

const result = {
  name: 'yang',
  age: 18,
  info: {
    money: '123',
    wallet: {
      "money": 222,
    },
  },
}

const clone = objectClone(result);

clone.name = '123';

console.log(result.name, clone.name);
// yang 123

3. object to queryString

import { objectToQueryString } from 'yang-lazy-util';

const result = {
  name: 'yang',
  age: 18,
 }

const queryString = objectToQueryString(result);

console.log(queryString);
// name=yang&age=18

4. object to key + value string

import { objectToString } from 'yang-lazy-util';


let result = {
  name: 'yang',
  age: 18,
}

let str =  objectToString(result);

console.log(str);
//  name:yang;age:18;

// 可以自定义连接的符号
let str =  objectToString(result, '**');
name:yang**age:18**

// 通过回调函数进行自定义
 objectToString(result, '', (key, value) => {
 console.log(key, value);
 // name yang  age 18
});

5. object diff

// 注:如果有相同的key,已后一个参数为准
import { objectDiff } from 'yang-lazy-util';

let result1 = {
  name: 'yang',
  age: 18,
}

let result2 = {
  name: 'yang2',
  age: 18,
}

const result = objectDiff(result1, result2);

console.log(result); // {name: "yang2"}

let result1 = {
  name: 'yang',
}

let result2 = {
  name: 'yang2',
  age: 18
}

const result = objectDiff(result1, result2);

console.log(result); // {name: "yang2", age: 18}

6. get url params

import { getURLParameters } from 'yang-lazy-util';

let url = 'http://www.baidu.com?name=yang&test=123';

let query = getURLParameters(url);

console.log(query);
// {name: "yang", test: "123"}

There are not many methods in the tool library, and will continue to be added in the future

Issues

issues

0.1.11

5 years ago

0.1.12

5 years ago

0.1.13

5 years ago

0.1.14

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.3

5 years ago

0.1.0

5 years ago

1.0.0

5 years ago