{"id":16125697,"url":"https://github.com/dy/to-uint8","last_synced_at":"2025-09-12T22:31:39.955Z","repository":{"id":57377432,"uuid":"157136051","full_name":"dy/to-uint8","owner":"dy","description":"Convert input argument to Uint8Array","archived":false,"fork":false,"pushed_at":"2018-11-13T18:52:26.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T00:08:21.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-12T00:42:23.000Z","updated_at":"2019-07-23T18:58:34.000Z","dependencies_parsed_at":"2022-09-26T16:41:48.403Z","dependency_job_id":null,"html_url":"https://github.com/dy/to-uint8","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fto-uint8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fto-uint8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fto-uint8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fto-uint8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/to-uint8/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232792154,"owners_count":18577263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T21:30:45.931Z","updated_at":"2025-01-06T22:04:56.242Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# to-uint8 [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://travis-ci.org/dy/to-uint8.svg?branch=master)](https://travis-ci.org/dy/to-uint8)\n\nConvert input array to uint8 array, detecting floats if required. Useful to ensure that an input array contains pixels/colors.\n\n[![npm install to-uint8](https://nodei.co/npm/to-uint8.png?mini=true)](https://npmjs.org/package/to-uint8/)\n\n```js\nvar u8 = require('to-uint8')\n\nvar pixels = u8([[0,0,0,1], [1,1,1,1]]) // \u003cuint8 0,0,0,255, 255,255,255,255\u003e\n```\n\n## `u8data = u8(data, detectFloat=true)`\n\nReturn Uint8Array `u8data` with input `data` values, possibly converted from floats, if required. `data` can be an Array, Array of Arrays, TypedArray, Buffer, ArrayBuffer, base64 string or any other container.\n\n```js\nu8(new Uint16Array([0, 1, 2])) // \u003cuint8 0, 1, 2\u003e\nu8(new Float32Array([0, .5, 1])) // \u003cuint8 0, 127, 255\u003e\nu8(new Float64Array([0, .5, 1])) // \u003cuint8 0, 127, 255\u003e\nu8([0, .5, 1]) // \u003cuint8 0, 127, 255\u003e\nu8([[0,0,0,0], [1,1,1,1]]) // \u003cuint8 0,0,0,0, 255,255,255,255\u003e\n\n// untyped array with int-ish values doesn't get converted\nu8([0, 1, 255]) // \u003cuint8 0, 1, 255\u003e\n\n// unless passed a flag to force conversion\nu8([0, 1, 255], false) // \u003cuint8 0, 255, 255\u003e\n\n// bad data returns null\nu8(/abc/) // null\n```\n\n## See also\n\n* [to-array-buffer](https://ghub.io/to-array-buffer) − convert anything to ArrayBuffer\n* [to-float32](https://ghub.io/to-float32) − convert anything to float32.\n\n## License\n\n(c) 2018 Dmitry Yv. MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fto-uint8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Fto-uint8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fto-uint8/lists"}