pax_global_header00006660000000000000000000000064133233400300014501gustar00rootroot0000000000000052 comment=ae0a176ad9f7c3340957d20c8f57770139ecabd2 text-hex-1.0.0/000077500000000000000000000000001332334003000132455ustar00rootroot00000000000000text-hex-1.0.0/.gitignore000066400000000000000000000000151332334003000152310ustar00rootroot00000000000000node_modules text-hex-1.0.0/LICENSE000066400000000000000000000021311332334003000142470ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2015 Arnout Kazemier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. text-hex-1.0.0/README.md000066400000000000000000000003051332334003000145220ustar00rootroot00000000000000# text-hex Transforms a given piece of text to a hex color. ## Install ``` npm install text-hex ``` ## Usage ```js var hex = require('text-hex'); console.log(hex('foo')); ``` ## License MIT text-hex-1.0.0/index.js000066400000000000000000000007351332334003000147170ustar00rootroot00000000000000'use strict'; /*** * Convert string to hex color. * * @param {String} str Text to hash and convert to hex. * @returns {String} * @api public */ module.exports = function hex(str) { for ( var i = 0, hash = 0; i < str.length; hash = str.charCodeAt(i++) + ((hash << 5) - hash) ); var color = Math.floor( Math.abs( (Math.sin(hash) * 10000) % 1 * 16777216 ) ).toString(16); return '#' + Array(6 - color.length + 1).join('0') + color; }; text-hex-1.0.0/package.json000066400000000000000000000012001332334003000155240ustar00rootroot00000000000000{ "name": "text-hex", "version": "1.0.0", "description": "Generate a hex color from the given text", "main": "index.js", "scripts": { "test": "mocha --reporter spec --ui bdd test.js" }, "repository": { "type": "git", "url": "https://github.com/3rd-Eden/text-hex" }, "keywords": [ "css", "color", "hex", "text" ], "author": "Arnout Kazemier", "license": "MIT", "bugs": { "url": "https://github.com/3rd-Eden/text-hex/issues" }, "homepage": "https://github.com/3rd-Eden/text-hex", "devDependencies": { "assume": "2.1.x", "mocha": "5.2.x", "pre-commit": "1.2.x" } } text-hex-1.0.0/test.js000066400000000000000000000004431332334003000145630ustar00rootroot00000000000000describe('text-hex', function () { 'use strict'; var assume = require('assume') , hex = require('./'); it('is a 6 digit hex', function () { assume(hex('a')).to.have.length(7); // including a # assume(hex('a244fdafadfa4 adfau8fa a u adf8a0')).to.have.length(7); }); });