pax_global_header00006660000000000000000000000064143214561020014510gustar00rootroot0000000000000052 comment=aab5ad9158e63b57f294cd4b6cbca195afa9e820 camelize-1.0.1/000077500000000000000000000000001432145610200133005ustar00rootroot00000000000000camelize-1.0.1/.eslintrc000066400000000000000000000006651432145610200151330ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "camelcase": 0, "func-style": 1, "max-statements-per-line": 0, "no-param-reassign": 1, "no-restricted-syntax": 1, "no-use-before-define": 1, "sort-keys": 0, }, "overrides": [ { "files": "example/**", "rules": { "no-console": 0, }, } ] } camelize-1.0.1/.github/000077500000000000000000000000001432145610200146405ustar00rootroot00000000000000camelize-1.0.1/.github/FUNDING.yml000066400000000000000000000011141432145610200164520ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/es-value-fixtures community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] camelize-1.0.1/.github/workflows/000077500000000000000000000000001432145610200166755ustar00rootroot00000000000000camelize-1.0.1/.github/workflows/node-aught.yml000066400000000000000000000005161432145610200214550ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' camelize-1.0.1/.github/workflows/node-pretest.yml000066400000000000000000000002061432145610200220270ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main camelize-1.0.1/.github/workflows/node-tens.yml000066400000000000000000000005211432145610200213120ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only node: name: 'node >= 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' camelize-1.0.1/.github/workflows/rebase.yml000066400000000000000000000004111432145610200206550ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} camelize-1.0.1/.github/workflows/require-allow-edits.yml000066400000000000000000000003031432145610200233120ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main camelize-1.0.1/.gitignore000066400000000000000000000001721432145610200152700ustar00rootroot00000000000000# gitignore node_modules/ # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore camelize-1.0.1/.npmrc000066400000000000000000000000671432145610200144230ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s camelize-1.0.1/CHANGELOG.md000066400000000000000000000100021432145610200151020ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v1.0.1](https://github.com/ljharb/camelize/compare/v1.0.0...v1.0.1) - 2022-10-11 ### Commits - [eslint] fix indentation [`1c978b3`](https://github.com/ljharb/camelize/commit/1c978b349113cef7564e869470ee46a4a0b2ed12) - [readme] rename, add badges [`640a9c9`](https://github.com/ljharb/camelize/commit/640a9c9509c934fa0af0871cf3a2c57b44e2e17d) - [actions] add reusable workflows [`0c27439`](https://github.com/ljharb/camelize/commit/0c2743965ceadbf10928b112b2f505bf8bd1d70e) - [eslint] add eslint [`c2f99b1`](https://github.com/ljharb/camelize/commit/c2f99b1ca92adf2d68077f9c9814cbe5c35283e3) - [meta] add `auto-changelog` [`18083fe`](https://github.com/ljharb/camelize/commit/18083fed5ac1f60d34371c25c25939829fc359b1) - [Dev Deps] update `tape` [`f11a870`](https://github.com/ljharb/camelize/commit/f11a870a40077552d28cfaaf85b97c638d90d696) - [meta] create FUNDING.yml; add `funding` in package.json [`83d0195`](https://github.com/ljharb/camelize/commit/83d0195aef76624fbbf0e75b55878da2897a890e) - [meta] use `npmignore` to autogenerate an npmignore file [`34862da`](https://github.com/ljharb/camelize/commit/34862dac5a9566f5d30ddcfc73d735875a8fe13a) - Only apps should have lockfiles [`270fb10`](https://github.com/ljharb/camelize/commit/270fb103d8061b687f705c49f512ff01353e3ca2) - [meta] update URLs [`fa51c88`](https://github.com/ljharb/camelize/commit/fa51c88806e3347b564dccd8df9dfcd440f523b3) - [meta] add `safe-publish-latest` [`f141183`](https://github.com/ljharb/camelize/commit/f141183b01229d0a3db085464ecd052dc0dbf331) - [Tests] add `aud` in `posttest` [`276e8a2`](https://github.com/ljharb/camelize/commit/276e8a2285d1cc37656cf630ec7961fc6efffe16) ## [v1.0.0](https://github.com/ljharb/camelize/compare/v0.2.0...v1.0.0) - 2014-07-07 ## [v0.2.0](https://github.com/ljharb/camelize/compare/v0.1.2...v0.2.0) - 2014-07-07 ### Commits - add support for dates and regex [`5c3ae6c`](https://github.com/ljharb/camelize/commit/5c3ae6cb8d5c14fdc47967d194359eced981fb00) ## [v0.1.2](https://github.com/ljharb/camelize/compare/v0.1.1...v0.1.2) - 2013-12-18 ### Commits - shims for ie<9 [`e38b6aa`](https://github.com/ljharb/camelize/commit/e38b6aa03bdd586cd190544515e25d6f9d965a09) ## [v0.1.1](https://github.com/ljharb/camelize/compare/v0.1.0...v0.1.1) - 2013-12-18 ### Commits - failing test for camelizing nested strings [`e4830da`](https://github.com/ljharb/camelize/commit/e4830da24b3f786b1080d726221a48fc708c98ae) - do not camelcase nested string values [`5adb7c6`](https://github.com/ljharb/camelize/commit/5adb7c6e2d5d41e21f02a59df0bc7eff6ad8890a) ## [v0.1.0](https://github.com/ljharb/camelize/compare/v0.0.0...v0.1.0) - 2013-06-30 ### Commits - camelCase the value if it's a string. [`2322d77`](https://github.com/ljharb/camelize/commit/2322d771557115a95133a5422e07a3f472b65018) - test for strings [`2bb412c`](https://github.com/ljharb/camelize/commit/2bb412c43485f8e810ce5353628ea00a6fb250de) - return object [`caa3f44`](https://github.com/ljharb/camelize/commit/caa3f44e053895ae1471b8ba3ab247dda1b88ddb) ## v0.0.0 - 2013-03-22 ### Commits - docs [`055791a`](https://github.com/ljharb/camelize/commit/055791a45b4fefb87ff598b8f6dcda8f34e45be6) - package.json etc [`859ff9b`](https://github.com/ljharb/camelize/commit/859ff9b475df18a09b9785068ec1730f84081291) - a passing test [`8987c4b`](https://github.com/ljharb/camelize/commit/8987c4bd9d2ca798551cf01443ddcfe6a3ebf5f9) - working example [`46e18af`](https://github.com/ljharb/camelize/commit/46e18afcfded7d3a5d525b4765eb488b998db791) - add testling [`9b3ae79`](https://github.com/ljharb/camelize/commit/9b3ae7979689614dd1b88b4dea7b970d27ff6ce0) - badges [`f140dfd`](https://github.com/ljharb/camelize/commit/f140dfd33e89493c69a001643bae911a297303e6) - using travis [`ef4251b`](https://github.com/ljharb/camelize/commit/ef4251bd3b4f86f3207a84bd3527cbfe0f4750d5) camelize-1.0.1/LICENSE000066400000000000000000000020611432145610200143040ustar00rootroot00000000000000This software is released under the MIT license: 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. camelize-1.0.1/README.md000066400000000000000000000037001432145610200145570ustar00rootroot00000000000000# camelize [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] recursively transform key strings to camel-case # example ``` js var camelize = require('camelize'); var obj = { fee_fie_foe: 'fum', beep_boop: [ { 'abc.xyz': 'mno' }, { 'foo-bar': 'baz' } ] }; var res = camelize(obj); console.log(JSON.stringify(res, null, 2)); ``` output: ``` { "feeFieFoe": "fum", "beepBoop": [ { "abcXyz": "mno" }, { "fooBar": "baz" } ] } ``` # methods ``` js var camelize = require('camelize') ``` ## camelize(obj) Convert the key strings in `obj` to camel-case recursively. # install With [npm](https://npmjs.org) do: ``` npm install camelize ``` To use in the browser, use [browserify](http://browserify.org). # license MIT [package-url]: https://npmjs.org/package/camelize [npm-version-svg]: https://versionbadg.es/ljharb/camelize.svg [deps-svg]: https://david-dm.org/ljharb/camelize.svg [deps-url]: https://david-dm.org/ljharb/camelize [dev-deps-svg]: https://david-dm.org/ljharb/camelize/dev-status.svg [dev-deps-url]: https://david-dm.org/ljharb/camelize#info=devDependencies [npm-badge-png]: https://nodei.co/npm/camelize.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/camelize.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/camelize.svg [downloads-url]: https://npm-stat.com/charts.html?package=camelize [codecov-image]: https://codecov.io/gh/ljharb/camelize/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/ljharb/camelize/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/camelize [actions-url]: https://github.com/ljharb/camelize/actions camelize-1.0.1/example/000077500000000000000000000000001432145610200147335ustar00rootroot00000000000000camelize-1.0.1/example/camel.js000066400000000000000000000003261432145610200163530ustar00rootroot00000000000000'use strict'; var camelize = require('../'); var obj = { fee_fie_foe: 'fum', beep_boop: [ { 'abc.xyz': 'mno' }, { 'foo-bar': 'baz' } ] }; var res = camelize(obj); console.log(JSON.stringify(res, null, 2)); camelize-1.0.1/index.js000066400000000000000000000025531432145610200147520ustar00rootroot00000000000000'use strict'; module.exports = function (obj) { if (typeof obj === 'string') { return camelCase(obj); } return walk(obj); }; function walk(obj) { if (!obj || typeof obj !== 'object') { return obj; } if (isDate(obj) || isRegex(obj)) { return obj; } if (isArray(obj)) { return map(obj, walk); } return reduce(objectKeys(obj), function (acc, key) { var camel = camelCase(key); acc[camel] = walk(obj[key]); return acc; }, {}); } function camelCase(str) { return str.replace(/[_.-](\w|$)/g, function (_, x) { return x.toUpperCase(); }); } var isArray = Array.isArray || function (obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }; var isDate = function (obj) { return Object.prototype.toString.call(obj) === '[object Date]'; }; var isRegex = function (obj) { return Object.prototype.toString.call(obj) === '[object RegExp]'; }; var has = Object.prototype.hasOwnProperty; var objectKeys = Object.keys || function (obj) { var keys = []; for (var key in obj) { if (has.call(obj, key)) { keys.push(key); } } return keys; }; function map(xs, f) { if (xs.map) { return xs.map(f); } var res = []; for (var i = 0; i < xs.length; i++) { res.push(f(xs[i], i)); } return res; } function reduce(xs, f, acc) { if (xs.reduce) { return xs.reduce(f, acc); } for (var i = 0; i < xs.length; i++) { acc = f(acc, xs[i], i); } return acc; } camelize-1.0.1/package.json000066400000000000000000000034711432145610200155730ustar00rootroot00000000000000{ "name": "camelize", "version": "1.0.1", "description": "recursively transform key strings to camel-case", "main": "index.js", "devDependencies": { "@ljharb/eslint-config": "^21.0.0", "aud": "^2.0.1", "auto-changelog": "^2.4.0", "eslint": "=8.8.0", "in-publish": "^2.0.1", "npmignore": "^0.3.0", "safe-publish-latest": "^2.0.0", "tape": "^5.6.1" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "tests-only": "tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "repository": { "type": "git", "url": "git://github.com/ljharb/camelize.git" }, "homepage": "https://github.com/ljharb/camelize", "keywords": [ "camel-case", "json", "transform" ], "testling": { "files": "test/*.js", "browsers": { "iexplore": [ "6.0", "7.0", "8.0", "9.0" ], "chrome": [ "20.0" ], "firefox": [ "10.0", "15.0" ], "safari": [ "5.1" ], "opera": [ "12.0" ] } }, "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "funding": { "url": "https://github.com/sponsors/ljharb" }, "license": "MIT", "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "publishConfig": { "ignore": [ ".github/workflows" ] } } camelize-1.0.1/test/000077500000000000000000000000001432145610200142575ustar00rootroot00000000000000camelize-1.0.1/test/camel.js000066400000000000000000000015311432145610200156760ustar00rootroot00000000000000'use strict'; var test = require('tape'); var camelize = require('../'); var obj = { fee_fie_foe: 'fum', beep_boop: [ { 'abc.xyz': 'mno' }, { 'foo-bar': 'baz' } ] }; test('camelize a nested object', function (t) { t.plan(1); var res = camelize(obj); t.deepEqual(res, { feeFieFoe: 'fum', beepBoop: [ { abcXyz: 'mno' }, { fooBar: 'baz' } ] }); }); test('string', function (t) { t.plan(1); t.equal(camelize('one_two'), 'oneTwo'); }); test('date', function (t) { t.plan(1); var d = new Date(); t.equal(camelize(d), d); }); test('regex', function (t) { t.plan(1); var r = /1234/; t.equal(camelize(r), r); }); test('only camelize strings that are the root value', function (t) { t.plan(2); t.equal(camelize('foo-bar'), 'fooBar'); var res = camelize({ 'foo-bar': 'baz-foo' }); t.deepEqual(res, { fooBar: 'baz-foo' }); });