{"_id":"utf8-binary-cutter","_rev":"25-31f42ee491befc78bf720813e6e93029","name":"utf8-binary-cutter","description":"truncate UTF-8 strings to a given binary size","dist-tags":{"latest":"0.9.2"},"versions":{"0.8.0":{"name":"utf8-binary-cutter","version":"0.8.0","description":"truncate UTF-8 strings to a given binary size","main":"main.js","scripts":{"test":"mocha tests/ --recursive"},"repository":{"type":"git","url":"git://github.com/lemonde/utf8-binary-cutter.git"},"keywords":["utf-8","truncate"],"author":{"name":"Yvem","email":"jutard@lemonde.fr"},"license":"public domain","bugs":{"url":"https://github.com/lemonde/utf8-binary-cutter/issues"},"homepage":"https://github.com/lemonde/utf8-binary-cutter","dependencies":{"lodash":"^1.9.1"},"devDependencies":{"chai":"^1.9.1","lodash":"latest","mocha":"^1.20.1","sinon":"^1.10.2","sinon-chai":"^2.5.0"},"gitHead":"c6dd36a21f42a2d9e40005ce0370ea28a22bd4b0","_id":"utf8-binary-cutter@0.8.0","_shasum":"f971913a6a9f5f432e9a5fee703cbd6fdb22a2fd","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"offirmo","email":"offirmo.net@gmail.com"},"maintainers":[{"name":"offirmo","email":"offirmo.net@gmail.com"}],"dist":{"shasum":"f971913a6a9f5f432e9a5fee703cbd6fdb22a2fd","tarball":"https://registry.npmjs.org/utf8-binary-cutter/-/utf8-binary-cutter-0.8.0.tgz","integrity":"sha512-XrGJUXY2Mwc7HQeTaK1Z1AVB4LatPleP54PZcnqmsxsiJhfuXvnCwrjurAWLcdVskE2mS5BcAnhJfgIeqr1iEA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIByRewWTN04u/zOMRBquuMxsAB95YWcpIfxZzh+TolUCAiEAmFvmSQ/Pe46awB2tXrA2dKhJslfYsMjZljGdECh69x4="}]},"directories":{}},"0.8.1":{"name":"utf8-binary-cutter","version":"0.8.1","description":"truncate UTF-8 strings to a given binary size","main":"main.js","scripts":{"test":"mocha tests/ --recursive"},"repository":{"type":"git","url":"git://github.com/lemonde/utf8-binary-cutter.git"},"keywords":["utf-8","truncate"],"author":{"name":"Yvem","email":"jutard@lemonde.fr"},"license":"public domain","bugs":{"url":"https://github.com/lemonde/utf8-binary-cutter/issues"},"homepage":"https://github.com/lemonde/utf8-binary-cutter","dependencies":{"lodash":"2.4.1"},"devDependencies":{"chai":"~1.10.0","mocha":"~2.0.1","sinon":"~1.12.1","sinon-chai":"~2.6.0"},"gitHead":"255525e73c933f32162795e161e1fe21f339973f","_id":"utf8-binary-cutter@0.8.1","_shasum":"d413b9c2d634ed825d6964ec6e5fc9980ee64848","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"offirmo","email":"offirmo.net@gmail.com"},"maintainers":[{"name":"offirmo","email":"offirmo.net@gmail.com"}],"dist":{"shasum":"d413b9c2d634ed825d6964ec6e5fc9980ee64848","tarball":"https://registry.npmjs.org/utf8-binary-cutter/-/utf8-binary-cutter-0.8.1.tgz","integrity":"sha512-H4l+GNg//6sqa1I70TiPg2F7WtxahnUcDtdtX+Gfwl5rnwbrns1thAgecQrdwt2BQZFgdbIn9AW8tl+M//nM+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBGB6jn22C+id6/A8u+PV9mB7zMit6gtYnEZ4hu/u9iCAiApeb68Fh4y3EFV22URGbPlb4wtGaOEjbQO0koI6SMn4w=="}]},"directories":{}},"0.9.0":{"name":"utf8-binary-cutter","version":"0.9.0","description":"truncate UTF-8 strings to a given binary size","main":"main.js","scripts":{"test":"mocha tests/ --recursive"},"repository":{"type":"git","url":"git://github.com/lemonde/utf8-binary-cutter.git"},"keywords":["utf-8","truncate"],"author":{"name":"Yvem","email":"jutard@lemonde.fr"},"license":"public domain","bugs":{"url":"https://github.com/lemonde/utf8-binary-cutter/issues"},"homepage":"https://github.com/lemonde/utf8-binary-cutter","dependencies":{"lodash":"2.4.1"},"devDependencies":{"chai":"~1.10.0","mocha":"~2.0.1","sinon":"~1.12.1","sinon-chai":"~2.6.0"},"gitHead":"ba9686ae0100811efffd921fa6f007d9a97852e3","_id":"utf8-binary-cutter@0.9.0","_shasum":"b465d5a1b81a4ce1e669610af3267af1d649b96e","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"offirmo","email":"offirmo.net@gmail.com"},"maintainers":[{"name":"offirmo","email":"offirmo.net@gmail.com"}],"dist":{"shasum":"b465d5a1b81a4ce1e669610af3267af1d649b96e","tarball":"https://registry.npmjs.org/utf8-binary-cutter/-/utf8-binary-cutter-0.9.0.tgz","integrity":"sha512-/Jig4TI9PfVtE7tWpxlmTgSP4Uu+Aacts2i4VJo6wPjwBUivWyhDiGhU3F2C8il5nTfTykI/i0JjO0+OWEd4yA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZKIX6ekrkXTzT7Hzgrwoh74FpGuwrbFHasbqYeiEwCgIgKyFEd07yAyF/9EmgDMIoLKFNkL7/8sTHyjD0rwy0GsM="}]},"directories":{}},"0.9.1":{"name":"utf8-binary-cutter","version":"0.9.1","description":"truncate UTF-8 strings to a given binary size","main":"main.js","scripts":{"test":"mocha tests/ --recursive"},"repository":{"type":"git","url":"git://github.com/lemonde/utf8-binary-cutter.git"},"keywords":["utf-8","truncate"],"author":{"name":"Yvem","email":"jutard@lemonde.fr"},"license":"public domain","bugs":{"url":"https://github.com/lemonde/utf8-binary-cutter/issues"},"homepage":"https://github.com/lemonde/utf8-binary-cutter","dependencies":{"lodash":"2.4.1"},"devDependencies":{"chai":"~1.10.0","mocha":"~2.0.1","sinon":"~1.12.1","sinon-chai":"~2.6.0"},"gitHead":"4180df76edec2c6c22672467dbb73ffdd31b8644","_id":"utf8-binary-cutter@0.9.1","_shasum":"75bf459851561c83abea9a98b9a17368c32c5a0e","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"offirmo","email":"offirmo.net@gmail.com"},"maintainers":[{"name":"offirmo","email":"offirmo.net@gmail.com"}],"dist":{"shasum":"75bf459851561c83abea9a98b9a17368c32c5a0e","tarball":"https://registry.npmjs.org/utf8-binary-cutter/-/utf8-binary-cutter-0.9.1.tgz","integrity":"sha512-xADayk4oViAgsqD35JXDgoBbON5XaQQH8PmdLxxV+UF5fLZUJZvicFKe45ZSbEaE08XvCslg9HvXKg/Gkwea+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCinCrsGCF1dd9a/Bnv3mF782WG089LS+5999adPsrXJQIhAJEFmPwPX9J/7Tlc08egxlrT4qoCiurUjvQKfOmt86LY"}]},"directories":{}},"0.9.2":{"name":"utf8-binary-cutter","version":"0.9.2","description":"truncate UTF-8 strings to a given binary size","main":"main.js","scripts":{"test":"mocha tests/ --recursive"},"repository":{"type":"git","url":"git://github.com/lemonde/utf8-binary-cutter.git"},"keywords":["utf-8","truncate"],"author":{"name":"Yvem","email":"jutard@lemonde.fr"},"license":"public domain","bugs":{"url":"https://github.com/lemonde/utf8-binary-cutter/issues"},"homepage":"https://github.com/lemonde/utf8-binary-cutter","dependencies":{"lodash":"^4.17.10"},"devDependencies":{"chai":"~1.10.0","mocha":"~2.0.1","sinon":"~1.12.1","sinon-chai":"~2.6.0"},"gitHead":"9f8b2955bd888c73b7cdb3f1fc5de910a150ff25","_id":"utf8-binary-cutter@0.9.2","_npmVersion":"5.6.0","_nodeVersion":"8.9.1","_npmUser":{"name":"lemonde","email":"npm@lemonde.fr"},"dist":{"integrity":"sha512-lS/2TaA9idsyafus4+WaB+C/AfL3JD85C/sgMJBpplZay1G5SwTQcxmd4jiJLI1VxSJr6a3yuNicBxD+iU2MKQ==","shasum":"c2d28c7f3fd0387e5e162862d32e34090e2b96d9","tarball":"https://registry.npmjs.org/utf8-binary-cutter/-/utf8-binary-cutter-0.9.2.tgz","fileCount":11,"unpackedSize":39871,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbI9n5CRA9TVsSAnZWagAAHTgP/2EFnSS5ueHV+uBcazGa\nTXWgLKm/botY1sjiX9DWDtZtG22Z/1qRtEhmmBqtTMAWxTA5Wu/i6uyr9wXP\n2Dxyqhg47mH398V3NErVUOFkH/RccWmNMVAXSCDwbDpYw8fUtxOlXRbc5g57\nEExnGvdCtp4TAFPLW41BG16k8uLQORam1Xn4R0f7O9Lor0760wIIDw1jccmU\nwmlUjIkE8yhNeJksk/QgaIt2LPPHp44Paq/Yg3Ll738EzTpQIu3U74PY3ICF\nCVMgWmNb3CxAcElhfBBDhDWhAXjpcqE6jIiUcn1iiYTSjAYMadJqRcD1F8xC\nPTaIab0KHZF/QIxrhafgg7liW6G2FtkkK/S+Pb9g23UdFiCf6n7gfdiGfIJJ\njgk56sXS0A+5oXxcZs+aZxl3dxn48XnO5m1F+MsMrkT6jN7pJbuMP9tNjuXa\nja59KAxNyEmhhL2fM2u6YE2b8cR2ce0y9AIY1SLMLYND2bN8zNcV5hK7l25y\ntF8oYHI0kAJokXNwzYq0i1SX4JxcsDGPDOlvY4j+NFKl6I1LctTi3lC+z+nB\nuoBSlUtK3zbAYHp3/FrrZT2SIvw7S3dxrB81MeNXwQWz3QmD+4wsmZZWzt4I\nttLdyaEOCXG8SRQuxLB06kT5gTTQoezQlKO+uFvBrvDirsj1BDqrxJThtdp4\nEt+F\r\n=Aefm\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB+J5W326MkllIO7XpVy3A2kUjM6ZpssNs1xkwG/gLPXAiEAzrh4GXr2nQ8plP+flGmt711x9xag7ilAM8sBQ8AonzE="}]},"maintainers":[{"name":"jbustin","email":"justin.bourrousse@ymail.com"},{"name":"lemonde","email":"npm@lemonde.fr"},{"name":"offirmo","email":"offirmo.net@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utf8-binary-cutter_0.9.2_1529076215850_0.7173056010479559"},"_hasShrinkwrap":false}},"readme":"utf8-binary-cutter\n==================\n\n[![a cutter](https://raw.githubusercontent.com/lemonde/utf8-binary-cutter/master/doc/1390-Straight-cutter-18mm.jpg)](https://github.com/lemonde/utf8-binary-cutter)\n\nA small node.js lib to truncate UTF-8 strings to a given binary size. Useful when dealing with old systems handling UTF-8 as ascii/latin-1, for ex. MySQL or Oracle database.\n\nInteresting reads :\n* [About MySQL, UTF-8 and saving headaches](http://melp.nl/2011/01/about-mysql-utf-8-and-saving-headaches/)\n* [Getting out of MySQL Character Set Hell](https://www.bluebox.net/insight/blog-article/getting-out-of-mysql-character-set-hell)\n\nUsage\n=====\n* Works on UTF-8 strings (javascript strings are UTF-8 unless you're doing fancy things)\n\n```javascript\nvar Cutter = require('utf8-binary-cutter');\n```\n\n* `getBinarySize()` : returns the binary size of the given string\n\n```javascript\nvar utf8String = 'abc☃☃☃'; // abc then 3 times the UTF-8 « snowman » char which takes 3 bytes\n\nconsole.log( Cutter.getBinarySize( utf8String ) );  // 12 = 1 + 1 + 1 + 3 + 3 + 3\n```\n\n* `truncateToBinarySize()` truncate so that final binary size is lower or equal than the given limit :\n\n```javascript\nvar utf8String = 'abc☃☃☃'; // abc then 3 times the UTF-8 « snowman » char which takes 3 bytes\n\nconsole.log( Cutter.truncateToBinarySize( utf8String, 20 ) ); // 'abc☃☃☃'  -> no change\nconsole.log( Cutter.truncateToBinarySize( utf8String, 12 ) ); // 'abc☃☃☃'  -> no change\nconsole.log( Cutter.truncateToBinarySize( utf8String, 11 ) ); // 'abc☃...' -> to avoid cutting utf8 chars,\n  // the two last snowmen had to be removed. Final size = 9 bytes\nconsole.log( Cutter.truncateToBinarySize( utf8String, 10 ) ); // 'abc☃...' -> idem\nconsole.log( Cutter.truncateToBinarySize( utf8String,  9 ) ); // 'abc☃...' -> idem\nconsole.log( Cutter.truncateToBinarySize( utf8String,  8 ) ); // 'abc...'\n```\n\n* `truncateFieldsToBinarySize()` multiple truncations at the same time :\n  * NOTE : returns a new object.\n  * NOTE : iterates only on own properties\n  * NOTE : only truncated strings are copied, other members are shared with original object.\n\n```javascript\nvar maxBinarySizes = {\n  title: 40,\n  content: 200\n};\n\nconsole.log( Cutter.truncateFieldsToBinarySize({\n    title: '☃☃☃ A véry véry long title with UTF-8 ☃☃☃',\n    content: 'I ❤ utf8-binary-cutter !',\n    foo: 42\n  },\n  maxBinarySizes\n));\n\n--> {\n  title: '☃☃☃ A véry véry long title wi...',\n  content: 'I ❤ utf8-binary-cutter !',\n  foo: 42\n}\n```\n\n\n* `truncateToCharLength()` normal truncate is also provided for convenience : truncate so that final char length is lower or equal than the given limit :\n\n```javascript\nvar utf8String = 'abc☃☃☃'; // 6 chars\n\nconsole.log( Cutter.truncateToCharLength( utf8String, 10 ) ); // 'abc☃☃☃'  -> no change\nconsole.log( Cutter.truncateToBinarySize( utf8String,  6 ) ); // 'abc☃☃☃'  -> no change\nconsole.log( Cutter.truncateToBinarySize( utf8String,  5 ) ); // 'ab...'   -> 5 chars, ok\n```\n\n* optional callback when truncating (useful for logging) :\n\n```\ntruncateToBinarySize(foo, 42, function(maxBinarySize, originalString, truncatedString) {\n  logger.warn(...\n});\n\ntruncateToCharLength(foo, 42, function(maxCharLength, originalString, truncatedString) {\n  logger.warn(...\n});\n\nCutter.truncateFieldsToBinarySize({\n    title: '☃☃☃ A véry véry long title with UTF-8 ☃☃☃',\n    content: 'I ❤ utf8-binary-cutter !',\n    foo: 42\n  },\n  // maxBinarySizes\n  {\n    title: 40,\n    content: 200\n  },\n  // callback\n  // will be called for each member truncated.\n  // 4th param : the key of the member being truncated.\n  function(maxCharLength, originalString, truncatedString, key) {\n    logger.warn(...\n  }\n);\n\n```\n\nContributing\n============\n* clone repo\n* ensure your editor is decent and pick up the `.editorconfig` and `.jshintrc` files\n* `npm install`\n* `npm test`\n* add tests, add features, send a PR\n\nThanks !","maintainers":[{"email":"berge.greg@gmail.com","name":"neoziro"},{"email":"laleu@lemonde.fr","name":"dolmac"},{"email":"morard@lemonde.fr","name":"sachamorard"},{"email":"jeremy@smooth-code.com","name":"jsfez"},{"email":"baron@lemonde.fr","name":"mbar"},{"email":"werwinski@lemonde.fr","name":"ludowic"},{"email":"offirmo.net@gmail.com","name":"offirmo"},{"email":"justin.bourrousse@ymail.com","name":"jbustin"}],"time":{"modified":"2022-06-28T07:08:21.086Z","created":"2014-12-08T16:18:33.164Z","0.8.0":"2014-12-08T16:18:33.164Z","0.8.1":"2014-12-08T16:53:42.317Z","0.9.0":"2014-12-09T13:27:23.001Z","0.9.1":"2014-12-10T15:26:19.201Z","0.9.2":"2018-06-15T15:23:35.936Z"},"homepage":"https://github.com/lemonde/utf8-binary-cutter","keywords":["utf-8","truncate"],"repository":{"type":"git","url":"git://github.com/lemonde/utf8-binary-cutter.git"},"author":{"name":"Yvem","email":"jutard@lemonde.fr"},"bugs":{"url":"https://github.com/lemonde/utf8-binary-cutter/issues"},"license":"public domain","readmeFilename":"README.md","users":{"yjutard":true}}