Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
js-polyfills
Advanced tools
Note that my general approach to polyfills is not to produce 100% compliant behavior, but to provide a broad subset of functionality so that, where possible, cooperative code can be written to take advantage of new APIs. No assumptions should be made about security or edge cases. It is preferrable to use a shim where it is possible to create one on supported browsers. If not possible, a helper should be used that lets the same code be used in all browsers.
I use these in various pages on my sites; most are by me, or I have at least tweaked them. A more comprehensive list can be found at The All-In-One Entirely-Not-Alphabetical No-Bullshit Guide to HTML5 Fallbacks by Paul Irish.
ECMAScript 5 - Most recent standard, supported by all modern browsers. Frozen.
ECMAScript 6 - Based on nearly complete draft standard. Should be stable apart from bug fixes.
ECMAScript 7 - At the initial proposal/strawman stage. Here there be dragons.
JavaScript 1.X String Extras - ref
trimLeft
, trimRight
, quote
script - tests - living standard
document.head
(for IE8-)section
, aside
, etc), to fix parsing (for IE8-)dataset
and data-*
attributes spec (for IE8+, not available in IE7-)
str = element.dataset[key]
- yields undefined if data-key attribute not presentelement.dataset[key] = str
- fails unless data-key attribute already presentencodedString = window.btoa(binaryString)
- Base64 EncodebinaryString = window.atob(encodedString)
- Base64 Decodescript - tests - living standard
element = document.querySelector(selector)
elementArray = document.querySelectorAll(selector)
elementArray = document.getElementsByClassName(classNames)
(for IE8-)Node.ELEMENT_NODE
, etc (for IE8-)DOMException.INDEX_SIZE_ERR
(for IE8-)EventTarget
is window
, document
, or any element:
EventTarget.addEventListener(event, handler)
- for IE8+EventTarget.removeEventListener(event, handler)
- for IE8+Event.target
Event.currentTarget
Event.eventPhase
Event.bubbles
Event.cancelable
Event.timeStamp
Event.defaultPrevented
Event.stopPropagation()
Event.cancelBubble()
window.addEvent(EventTarget, event, handler)
window.removeEvent(EventTarget, event, handler)
classList
spec, relList
spec
tokenList = elem.classList
- for IE8+tokenList = elem.relList
- for IE8+tokenList.length
tokenList.item(index)
tokenList.contains(token)
tokenList.add(token)
tokenList.remove(token)
tokenList.toggle(token)
tokenList = window.getClassList(element)
tokenList = window.getRelList(element)
script - tests - living standard
Example:
fetch('http://example.com/foo.json')
.then(function(response) { return response.json(); })
.then(function(data) { console.log(data); });
Supported:
new Headers()
, append(name, value)
, delete(name)
, get(name)
, getAll(name)
, has(name)
, set(name, value)
, [Symbol.iterator]()
arrayBuffer()
, blob()
, formData()
, json()
, text()
- but conversions are limitednew Request(input, init)
, method
, headers
, body
, url
new Response(body, init)
, headers
, url
, status
, statusText
, body
fetch(input, init)
script - tests - living standard
XMLHttpRequest
(for IE6-)FormData
(for IE9-)id = window.requestAnimationFrame()
window.cancelAnimationFrame(id)
id = setImmediate(callback, args...)
clearImmediate(id)
Polyfill for width
and height
in getBoundingClientRect()
in IE8-
script - tests - living standard
var url = new URL(url, base);
var value = url.searchParams.get(name);
var valueArray = url.searchParams.getAll(name);
url.searchParams.append(name, valueOrValues);
url.searchParams.delete(name);
URL objects have properties:
href
, origin
, protocol
, username
, password
, host
, hostname
, port
, pathname
, search
, searchParams
, hash
URLSearchParams objects have:
append(name, value)
delete(name)
get(name)
getAll(name)
has(name)
set(name, value)
[Symbol.iterator]()
- if definedscript - demo page - draft spec
// Adds the following properties to each KeyboardEvent:
event.code
event.key
event.location
// You can get a label for the key using:
KeyboardEvent.queryKeyCap(code);
// IE7- only: In your keydown/keyup handler, call this in your handler
// before accessing the `code`, `key`, or `location` properties:
window.identifyKey(keyboardEvent);
script - demo page - spec - uses freegeoip.net
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
var watchId = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
navigator.geolocation.clearWatch(watchId);
FAQs
Collection of Web polyfills.
The npm package js-polyfills receives a total of 7,698 weekly downloads. As such, js-polyfills popularity was classified as popular.
We found that js-polyfills demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.