diff --git a/.gitignore b/.gitignore index d3f18a9..323abcd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ node_modules Thumbs.db -.DS_Store \ No newline at end of file +.DS_Store +index.js +index.d.ts +.idea +yarn.lock +package-lock.json diff --git a/.travis.yml b/.travis.yml index 4ebe695..5ae4894 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ language: node_js node_js: - - 4.4.7 - - 5 - - 6 \ No newline at end of file + - 10 diff --git a/index.js b/index.js deleted file mode 100644 index 85fdb24..0000000 --- a/index.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Stringify object values - * { hello: 'world' } -> { hello: "'world'" } - * - * @param {object} object - * @return {object} - */ -module.exports = function stringify(object) { - return Object.keys(object) - .reduce((previous, next) => { - return (previous[next] = JSON.stringify(object[next]), previous); - }, {}); -} \ No newline at end of file diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..97fef75 --- /dev/null +++ b/index.ts @@ -0,0 +1,13 @@ +/** + * Stringify object values + * { hello: 'world' } -> { hello: "'world'" } + * + * @param {object} object + * @return {object} + */ +export = (function stringify(object: { [x: string]: any; }) { + return Object.keys(object) + .reduce(function (previous: any, next: any) { + return (previous[next] = JSON.stringify(object[next]), previous); + }, {}) as {[x: string]: string}; +}); diff --git a/package.json b/package.json index cfbeb9a..d7e3e99 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "Stringify object values", "main": "index.js", "scripts": { - "test": "mocha test.js" + "build": "tsc", + "prepublish": "tsc", + "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'test.ts'" }, "repository": { "type": "git", @@ -19,7 +21,12 @@ "author": "Kier Borromeo (http://srph.github.io)", "license": "ISC", "devDependencies": { - "chai": "^3.5.0", - "mocha": "^3.0.2" - } + "@types/chai": "^4.2.12", + "@types/mocha": "^8.0.0", + "chai": "^4.2.0", + "mocha": "^8.0.1", + "ts-node": "^8.10.2", + "typescript": "^3.9.7" + }, + "files": ["index.js", "index.d.ts"] } diff --git a/test.js b/test.js deleted file mode 100644 index fc9ddbb..0000000 --- a/test.js +++ /dev/null @@ -1,22 +0,0 @@ -var expect = require('chai').expect; -var stringify = require('./'); - -describe('stringify', function() { - it('should stringify each of the object\'s value', function() { - var test = { - hello: 'world', - favorite: 1, - equation: '1+1', - random: {}, - arr: [] - }; - - expect(stringify(test)).to.eql({ - hello: JSON.stringify('world'), - favorite: JSON.stringify(1), - equation: JSON.stringify('1+1'), - random: JSON.stringify({}), - arr: JSON.stringify([]) - }); - }); -}); \ No newline at end of file diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..bb495b8 --- /dev/null +++ b/test.ts @@ -0,0 +1,21 @@ +import * as chai from "chai"; +import stringify from "./"; +var expect = chai.expect; +describe('stringify', function () { + it('should stringify each of the object\'s value', function () { + var test = { + hello: 'world', + favorite: 1, + equation: '1+1', + random: {}, + arr: [] + }; + expect(stringify(test)).to.eql({ + hello: JSON.stringify('world'), + favorite: JSON.stringify(1), + equation: JSON.stringify('1+1'), + random: JSON.stringify({}), + arr: JSON.stringify([]) + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..cac858c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "CommonJS", + "moduleResolution": "node", + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "noUnusedLocals": true, + "pretty": true, + "declaration": true, + "lib": [ + "esnext" + ], + }, + "files": [ + "index.ts" + ] +} \ No newline at end of file