Giter Site home page Giter Site logo

licia's Introduction

中文

Licia

NPM version Build status Test coverage Size License Join the chat at https://gitter.im/liriliri/licia

Licia is a utility library that focus on getting daily works done. Unlike other libraries such as underscore, mout, which strictly separates its functions into several categories like array, string and function etc. licia is just a deadly simple collection of over 400 micro modules dealing problems in different aspects.

Benefits

Installing one library brings you tons of useful utilities:

  • A dom module with jQuery coding style.
  • A cookie library.
  • dateFormat that is good enough to handle most date related work.
  • A Promise polyfill.
  • A micro event emitter library.
  • Ajax and its Promise version fetch.
  • Useful functions from underscore, such as shuffle, unique.
  • mkdir, like mkdirp the module that has many dependents in npm.
  • ...

Usage

Just install licia and use it like any other npm utility modules such as lodash.

npm i licia --save
const uuid = require('licia/uuid');

console.log(uuid()); // -> 0e3b84af-f911-4a55-b78a-cedf6f0bd815

Looking for Licia modules written in ES6 or smaller bundle sizes? Check out licia-es. There is also an online tool to build a customized utility library, check here.

Contribution

Read Contributing Guide for development setup instructions.

licia's People

Contributors

linkkingjay avatar modderme123 avatar surunzi avatar zhang0zgc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

licia's Issues

Licia is unfriendly to rollup's tree shaking

Everything is included in the bundle when using default entry "node.js".

index.js

import { delay, noop } from "licia";
delay(noop, 666);

rollup.config.js

import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
export default {
  input: "index.js",
  output: { format: "iife", file: "bundle.js" },
  plugins: [resolve(), commonjs()]
}

If the only needed modules are imported, the bundle would contain extra wrapper code for commonjs.

index.js:

import delay from "licia/delay";
import noop from "licia/noop";

delay(noop, 666);

bundle.js:

(function () { 'use strict';

	function createCommonjsModule(fn, module) {
		return module = { exports: {} }, fn(module, module.exports), module.exports;
	}

	var restArgs = createCommonjsModule(function (module, exports) {
	exports = function(fn, startIdx) {
	    startIdx = startIdx == null ? fn.length - 1 : +startIdx;
	    return function() {
	        var len = Math.max(arguments.length - startIdx, 0);
	        var rest = new Array(len);
	        var i;

	        for (i = 0; i < len; i++) {
	            rest[i] = arguments[i + startIdx];
	        }

	        switch (startIdx) {
	            case 0:
	                return fn.call(this, rest);

	            case 1:
	                return fn.call(this, arguments[0], rest);

	            case 2:
	                return fn.call(this, arguments[0], arguments[1], rest);
	        }

	        var args = new Array(startIdx + 1);

	        for (i = 0; i < startIdx; i++) {
	            args[i] = arguments[i];
	        }

	        args[startIdx] = rest;
	        return fn.apply(this, args);
	    };
	};

	module.exports = exports;
	});

	var delay = createCommonjsModule(function (module, exports) {
	exports = restArgs(function(fn, wait, args) {
	    return setTimeout(function() {
	        return fn.apply(null, args);
	    }, wait);
	});

	module.exports = exports;
	});

	var noop = createCommonjsModule(function (module, exports) {
	exports = function() {};

	module.exports = exports;
	});

	delay(noop, 666);

}))

Not a big deal, but it could be better to support ESModule.

类jquery 的选择器$无法使用

无法使用$('selector')的形式获取dom节点;

我这里是用的webpack进行打包webpack-dev-server运行在浏览器端,用licia来选择元素,

选择元素:
image
使用licia方法:es6或者commonjs都不行
image

报错:
image
image

请问是什么原因啊?是不是我的使用方法不对啊?

Licia Docs: 'matcher' fn repl+example correction

https://licia.liriliri.io/docs.html#matcher

current example in docs:

const objects = [
    {a: 1, b: 2, c: 3 },
    {a: 4, b: 5, c: 6 }
];
// filter(objects, matcher({a: 4, c: 6 }));

should be:

const objects = [
    {a: 1, b: 2, c: 3 },
    {a: 4, b: 5, c: 6 }
];
filter(objects, matcher({a: 4, c: 6 })); // ->{a:4, b:5, c:6}

current repl boilerplate:

// You can't require modules that are supposed to run in browsers only.

var matcher = require("licia/matcher");

const objects = [
    {a: 1, b: 2, c: 3 },
    {a: 4, b: 5, c: 6 }
];
// filter(objects, matcher({a: 4, c: 6 }));

should be:

// You can't require modules that are supposed to run in browsers only.

var matcher = require("licia/matcher");
var filter = require("licia/filter");

const objects = [
    {a: 1, b: 2, c: 3 },
    {a: 4, b: 5, c: 6 }
];
filter(objects, matcher({a: 4, c: 6 }));

[isArgs] -- unnecessary IIFE example

  (function() {
     isArgs(arguments); // -> true
 })();

it returns undefined, not true in repl.

in run kit it can do without IIFE

isArgs(arguments); // -> true

works

Docs - timeAgo func example comment correction

const now = new Date().getTime();
timeAgo(now - 1000 * 6); // -> right now
timeAgo(now + 1000 * 15); // -> in 15 minutes
timeAgo(now - 1000 * 60 * 60 * 5, now); // -> 5 hours ago

should be:

const now = new Date().getTime();
timeAgo(now - 1000 * 6); // -> 6 seconds ago
timeAgo(now + 1000 * 60 * 15); // -> in 15 minutes
timeAgo(now - 1000 * 60 * 60 * 5, now); // -> 5 hours ago

The package is vulnerable to Prototype Pollution.

The function extendDeep could be tricked into adding or modifying properties of Object.prototype using a constructor payload.

POC

const licia = require('licia');
const payload = '{"__proto__":{"a0":true}}'

function check() {
    licia.extendDeep({}, JSON.parse(payload));
    if (({})[`a0`] === true) {
          console.log(`Vulnerable to Prototype Pollution via ${payload}`)
  }
}

check();

Details

Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as proto, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.

无用代码导致运行错误

src/prefix.js 最下面的几行代码,应该是冗余代码,没有用处。主要是用了createElement 这个小程序中没有的方法,使用 $ 会导致运行错误

const prefixes = ['O', 'ms', 'Moz', 'Webkit'];
const regPrefixes = /^(O)|(ms)|(Moz)|(Webkit)|(-o-)|(-ms-)|(-moz-)|(-webkit-)/g;
const style = document.createElement('p').style;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.