Examples tested against actual runtime. CI re-verifies continuously. Only documented examples are tested.
How to use
Install via yarn add locutus and import:
import { setcookie } from 'locutus/php/network/setcookie'.
Or with CommonJS: const { setcookie } = require('locutus/php/network/setcookie')
Use a bundler that supports tree-shaking so you only ship the functions you actually use.
Vite,
webpack,
Rollup, and
Parcel
all handle this. For server-side use this is less of a concern.
Examples
These examples are extracted from test cases that automatically verify our functions against their native counterparts.
#
code
expected result
1
setcookie('author_name', 'Kevin van Zonneveld')
true
Dependencies
This function uses the following Locutus functions:
// php/network/setrawcookie (Locutus dependency module) functionsetrawcookie(name, value, expires, path, domain, secure) { // discuss at: https://locutus.io/php/setrawcookie/ // original by: Brett Zamir (https://brett-zamir.me) // original by: setcookie // improved by: Kevin van Zonneveld (https://kvz.io) // input by: Michael // note 1: This function requires access to the `window` global and is Browser-only // bugfixed by: Brett Zamir (https://brett-zamir.me) // example 1: setrawcookie('author_name', 'Kevin van Zonneveld') // returns 1: true
Locutus is a community effort following
The McDonald's Theory:
we ship first iterations, hoping others will improve them.
If you see something that could be better, we'd love your contribution.