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

sky-core

v0.14.2

Published

Javascript toolkit core library

Downloads

61

Readme

sky-core

sky-core是一个处理浏览器兼容问题的polyfill库和工具库。

为什么把polyfill库和工具库写成同个库?

  1. 浏览器的许多新增函数本就是工具函数
  2. 许多工具函数的封装本就是处理兼容问题
  3. 部分新增功能不能完美实现,有时必须使用函数调用

特色

  • 可打包为 IE9以下专用版、IE9+非IE版、ESM版、通用版 这4个版本。在现代浏览器中就不会载入多余的兼容代码了。
  • 包含许多Web API的polyfill。比如document.head等。
  • 可以配合Typescript和Babel使用。
  • 包含无污染版,和有污染版。如果一个有的库需要polyfill,有的不需要,则可以使用无污染版。

安装

npm i sky-core

使用

直接引入

import "sky-core/polyfill/document/head";

console.log(document.head);

结合rollup插件自动引入polyfill

//rollup.config.js
import polyfill from "rollup-plugin-polyfill-inject";

export default {
	input: 'src/index.js',
	output: {
		file: 'dist/index.js',
		format: 'iife'
	},
	plugins: [
		polyfill({
			"modules": {
				".includes": [
					"sky-core/polyfill/Array/prototype/includes",
					"sky-core/polyfill/String/prototype/includes"
				],
				"Set":"sky-core/polyfill/Set",
				"Map":"sky-core/polyfill/Map",
			},
		})
	]
}
//before
console.log([].includes('a'));
//after
import "sky-core/polyfill/Array/prototype/includes";
import "sky-core/polyfill/String/prototype/includes";

console.log([].includes('a'));

结合rollup插件只在部分时候无污染引入polyfill

//rollup.config.js
import inject from "@rollup/plugin-inject";

export default {
	input: 'src/index.js',
	output: {
		file: 'dist/index.js',
		format: 'iife'
	},
	plugins: [
		inject({
			"modules": {
				"XMLHttpRequest":"sky-core/pure/XMLHttpRequest"
			},
			include:["**/ajax.js"]
		})
	]
}
//browser.js
export const isIE6=!window.XMLHttpRequest;
//XMLHttpRequest will NOT replace to polyfill
//ajax.js
export function get(url){
	//XMLHttpRequest will replace to polyfill
	var xhr=new XMLHttpRequest();
	return new Promise(function(){
		//...
	});
}

约定

在低版本浏览器下,部分功能是不能完全实现的。因此需要按照以下约定开发从而避免出现浏览器差异。

对象的特殊的成员

你的对象不允许占用“__proto__”、“constructor”这2个成员变量。否则原型相关功能可能运行不正确。如:Object.getPrototypeOf。

Symbol成员表示

本项目将使用“@@”开头表示Symbol。如果您使用在对象中使用“@@”开头的成员,在Object.keys等函数中将被跳过。

不可枚举成员表示

本项目将使用“__”开头命名不可枚举成员。且Symbol作key必须是不可枚举的。如果您使用在对象中使用“__”开头的成员或Symbol,在Object.keys等函数中将被跳过。

不可在业务代码中使用defineProperty

defineProperty无法polyfill,因此不允许在业务代码中使用defineProperty。在框架中可以根据浏览器兼容情况进行降级处理。

不支持的功能

  • 不支持IE11开发工具仿真IE8及以下版本(真机支持)。
  • 不支持伪装成Native函数,函数toString()不会返回“native code”。
  • 不支持function .prototype .name。
  • 不支持不可枚举
  • Symbol WellKnow 只支持hasInstance、iterator