Install via yarn add locutus and import:
import { convert_uuencode } from 'locutus/php/strings/convert_uuencode'.
Or with CommonJS: const { convert_uuencode } = require('locutus/php/strings/convert_uuencode')
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
convert_uuencode("test\ntext text\r\n")
"0=&5S=`IT97AT('1E>'0-\"@\n`\n"
Dependencies
This function uses the following Locutus functions:
let c = 0 let u = 0 let a = 0 let encoded = '' let tmp1 = '' let tmp2 = '' letbytes: number[] = []
// divide string into chunks of 45 characters const chunk = function () { bytes = source .substr(u, 45) .split('') .map((char) => char.charCodeAt(0)) return bytes.length || 0 }
while ((c = chunk()) !== 0) { u += 45
// New line encoded data starts with number of bytes encoded. encoded += chr(c + 32)
// Convert each char in bytes[] to a byte for (const byte of bytes) { tmp1 = byte.toString(2) while (tmp1.length < 8) { tmp1 = '0' + tmp1 } tmp2 += tmp1 }
while (tmp2.length % 6) { tmp2 = tmp2 + '0' }
for (let i = 0; i <= tmp2.length / 6 - 1; i++) { tmp1 = tmp2.substr(a, 6) if (tmp1 === '000000') { encoded += chr(96) } else { encoded += chr(parseInt(tmp1, 2) + 32) } a += 6 } a = 0 tmp2 = '' encoded += '\n' }
let c = 0 let u = 0 let a = 0 let encoded = '' let tmp1 = '' let tmp2 = '' let bytes = []
// divide string into chunks of 45 characters const chunk = function () { bytes = source .substr(u, 45) .split('') .map((char) => char.charCodeAt(0)) return bytes.length || 0 }
while ((c = chunk()) !== 0) { u += 45
// New line encoded data starts with number of bytes encoded. encoded += chr(c + 32)
// Convert each char in bytes[] to a byte for (const byte of bytes) { tmp1 = byte.toString(2) while (tmp1.length < 8) { tmp1 = '0' + tmp1 } tmp2 += tmp1 }
while (tmp2.length % 6) { tmp2 = tmp2 + '0' }
for (let i = 0; i <= tmp2.length / 6 - 1; i++) { tmp1 = tmp2.substr(a, 6) if (tmp1 === '000000') { encoded += chr(96) } else { encoded += chr(parseInt(tmp1, 2) + 32) } a += 6 } a = 0 tmp2 = '' encoded += '\n' }
functionisPhpScalar(value: PhpInput): value is PhpScalar { returntypeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' }
let c = 0 let u = 0 let a = 0 let encoded = '' let tmp1 = '' let tmp2 = '' letbytes: number[] = []
// divide string into chunks of 45 characters const chunk = function () { bytes = source .substr(u, 45) .split('') .map((char) => char.charCodeAt(0)) return bytes.length || 0 }
while ((c = chunk()) !== 0) { u += 45
// New line encoded data starts with number of bytes encoded. encoded += chr(c + 32)
// Convert each char in bytes[] to a byte for (const byte of bytes) { tmp1 = byte.toString(2) while (tmp1.length < 8) { tmp1 = '0' + tmp1 } tmp2 += tmp1 }
while (tmp2.length % 6) { tmp2 = tmp2 + '0' }
for (let i = 0; i <= tmp2.length / 6 - 1; i++) { tmp1 = tmp2.substr(a, 6) if (tmp1 === '000000') { encoded += chr(96) } else { encoded += chr(parseInt(tmp1, 2) + 32) } a += 6 } a = 0 tmp2 = '' encoded += '\n' }
let c = 0 let u = 0 let a = 0 let encoded = '' let tmp1 = '' let tmp2 = '' let bytes = []
// divide string into chunks of 45 characters const chunk = function () { bytes = source .substr(u, 45) .split('') .map((char) => char.charCodeAt(0)) return bytes.length || 0 }
while ((c = chunk()) !== 0) { u += 45
// New line encoded data starts with number of bytes encoded. encoded += chr(c + 32)
// Convert each char in bytes[] to a byte for (const byte of bytes) { tmp1 = byte.toString(2) while (tmp1.length < 8) { tmp1 = '0' + tmp1 } tmp2 += tmp1 }
while (tmp2.length % 6) { tmp2 = tmp2 + '0' }
for (let i = 0; i <= tmp2.length / 6 - 1; i++) { tmp1 = tmp2.substr(a, 6) if (tmp1 === '000000') { encoded += chr(96) } else { encoded += chr(parseInt(tmp1, 2) + 32) } a += 6 } a = 0 tmp2 = '' encoded += '\n' }
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.