Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
remove humpsjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mg901 committed Mar 24, 2018
1 parent 543f51f commit 5911e73
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/breakpoints/breakpointsToCebabCase/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { decamelize } = require('humps');
const { decamelize } = require('../../../helpers');

/**
*
Expand Down
2 changes: 1 addition & 1 deletion api/breakpoints/calcBreakpointAbove/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { camelize } = require('humps');
const { camelize } = require('../../../helpers');
const getBreakpointValue = require('../getBreakpointValue');
const { toEm } = require('../../../helpers');

Expand Down
2 changes: 1 addition & 1 deletion api/breakpoints/calcBreakpointBelow/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { camelize } = require('humps');
const { camelize } = require('../../../helpers');
const getBreakpointMax = require('../getBreakpointMax');
const getNamesOfBreakpoints = require('../getNamesOfBreakpoints');
const { toEm } = require('../../../helpers');
Expand Down
2 changes: 1 addition & 1 deletion api/breakpoints/calcBreakpointOnly/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { camelize } = require('humps');
const { camelize } = require('../../../helpers');
const getBreakpointValue = require('../getBreakpointValue');
const getBreakpointMax = require('../getBreakpointMax');
const getNamesOfBreakpoints = require('../getNamesOfBreakpoints');
Expand Down
2 changes: 1 addition & 1 deletion api/breakpoints/calcBreakpointsBetween/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { camelize } = require('humps');
const { camelize } = require('../../../helpers');
const getBreakpointValue = require('../getBreakpointValue');
const getBreakpointMax = require('../getBreakpointMax');
const getNamesOfBreakpoints = require('../getNamesOfBreakpoints');
Expand Down
14 changes: 14 additions & 0 deletions constants/regexes/dashHyphenWhitespaceAnyCharacters.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS } = require('./');

describe('regexes', () => {
describe('DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS', () => {
it('should replace dash, hyphen, whitespace and any characters', () => {
expect(
'Hello_World'.replace(
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS,
(match, chr) => (chr ? chr.toUpperCase() : ''),
),
).toBe('HelloWorld');
});
});
});
4 changes: 4 additions & 0 deletions constants/regexes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ALL_ROUND_BRACKETS = /[()]/g;
const AMPERSAND = /&/;
const DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS = /[-_\s]+(.)?/g;
const HAS_AMPERSAND = /^&/;
const HAS_AT = /-?\b\d+(\.\d+)?(px|em) at -?\d+(\.\d+)??\b/;
const HAS_EM = /-?\b\d+(\.\d+)?em/;
Expand All @@ -14,10 +15,12 @@ const MS_UNIT = /ms/;
const POSITIVE_OR_NEGATIVE_FLOATING_POINT_NUMBER = /^-?\d+(\.\d+)?$/;
const POSITIVE_OR_NEGATIVE_FLOATING_POINT_NUMBER_WITH_MS_UNIT_MEASURE = /^-?\d+(\.\d+)?ms$/;
const ROUND_BRACKETS_AND_TMS_FUNCTION = /[()tms-]/g;
const SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER = /(?=[A-Z])/;

module.exports = {
ALL_ROUND_BRACKETS,
AMPERSAND,
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS,
HAS_AMPERSAND,
HAS_AT,
HAS_EM,
Expand All @@ -32,4 +35,5 @@ module.exports = {
POSITIVE_OR_NEGATIVE_FLOATING_POINT_NUMBER,
POSITIVE_OR_NEGATIVE_FLOATING_POINT_NUMBER_WITH_MS_UNIT_MEASURE,
ROUND_BRACKETS_AND_TMS_FUNCTION,
SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER,
};
11 changes: 11 additions & 0 deletions constants/regexes/separateStringIntoWordsWithCapitalLetter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER } = require('./');

describe('helpers', () => {
describe('SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER', () => {
it('should separate string', () => {
expect(
'HelloWorld'.split(SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER),
).toEqual(['Hello', 'World']);
});
});
});
9 changes: 9 additions & 0 deletions helpers/camelize/camelize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const camelize = require('./');

describe('helpers', () => {
describe('camelize', () => {
it('should camelize string', () => {
expect(camelize('hello-world', { separator: '-' })).toBe('helloWorld');
});
});
});
22 changes: 22 additions & 0 deletions helpers/camelize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS,
} = require('../../constants/regexes');
const isNumeric = require('../isNumeric/');

/**
* @example camelize('Hello_World') => 'HelloWorld'
* @param {string} value Decamelize string.
* @return {string} Camelize string.
*/
module.exports = value => {
let string = value;
if (isNumeric(string)) {
return string;
}
string = string.replace(
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS,
(match, chr) => (chr ? chr.toUpperCase() : ''),
);
// Ensure 1st char is always lowercase
return string.substr(0, 1).toLowerCase() + string.substr(1);
};
13 changes: 13 additions & 0 deletions helpers/decamelize/decamelize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const decamelize = require('./');

describe('helpers', () => {
describe('decamelize', () => {
it('should decamelize string with hyphen separator', () => {
expect(decamelize('helloWorld', { separator: '-' })).toBe('hello-world');
});

it('should decamelize string with underscore separator', () => {
expect(decamelize('helloWorld', { separator: '_' })).toBe('hello_world');
});
});
});
12 changes: 12 additions & 0 deletions helpers/decamelize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const separateWords = require('../separateWords');

/**
* @example decamelize('helloWorld', {separator: '-'}) => 'hello_world'
* @param {string} string
* @param {Object} [options] User options.
* @param {string} [options.separator] separating line.
* @param {regex|string} [options.split] line break.
* @return {string} Decamelize string.
*/
module.exports = (string, options) =>
separateWords(string, options).toLowerCase();
4 changes: 4 additions & 0 deletions helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const calcLeading = require('./calcLeading');
const calcRoot = require('./calcRoot');
const findAll = require('./findAll');
const camelize = require('./camelize');
const decamelize = require('./decamelize');
const getBase = require('./getBase');
const isArray = require('./isArray');
const isNumeric = require('./isNumeric');
Expand All @@ -16,6 +18,8 @@ const toRem = require('./toRem');
module.exports = {
calcLeading,
calcRoot,
camelize,
decamelize,
findAll,
getBase,
isArray,
Expand Down
19 changes: 19 additions & 0 deletions helpers/separateWords/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const {
SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER,
} = require('../../constants/regexes');

/**
* @example HelloWorld => Hello_world
* @param {string} string String.
* @param {Object} [options] User options.
* @param {string} [options.separator] separating line.
* @param {regex|string} [options.split] line break.
* @return {string}
*
*/
module.exports = (string, options = {}) => {
const separator = options.separator || '_';
const split = options.split || SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER;

return string.split(split).join(separator);
};
8 changes: 8 additions & 0 deletions helpers/separateWords/separateWords.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const separateWords = require('./');

describe('helpers', () =>
describe('separateWords', () => {
it('should separate word', () => {
expect(separateWords('HelloWorld')).toEqual('Hello_World');
});
}));
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
},
"main": "./index.js",
"scripts": {
"unit": "node-env jest",
"unit:watch": "node-env jest --watch",
"lint": "node-env eslint **/*.js"
"unit": "cross-env jest",
"unit:watch": "cross-env jest --watch",
"lint": "cross-env eslint **/*.js"
},
"devDependencies": {
"eslint": "^4.15.0",
Expand Down
2 changes: 1 addition & 1 deletion transformator/decls/variableDecl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const postcss = require('postcss');
const { decamelize } = require('humps');
const { decamelize } = require('../../helpers');

/**
*
Expand Down
3 changes: 1 addition & 2 deletions transformator/transformAtrules/transformTAbove/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { camelize, decamelize } = require('humps');
const { toEm } = require('../../../helpers');
const { toEm, camelize, decamelize } = require('../../../helpers');
const { HAS_EM, HAS_PX } = require('../../../constants/regexes');
const {
breakpointsToCebabCase,
Expand Down
3 changes: 1 addition & 2 deletions transformator/transformAtrules/transformTBelow/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { camelize, decamelize } = require('humps');
const { toEm } = require('../../../helpers');
const { toEm, camelize, decamelize } = require('../../../helpers');
const { HAS_EM, HAS_PX } = require('../../../constants/regexes');
const {
calcBreakpointBelow,
Expand Down
2 changes: 1 addition & 1 deletion transformator/transformAtrules/transformTBetween/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { camelize } = require('humps');
const { camelize } = require('../../../helpers');
const { HAS_EM, HAS_PX } = require('../../../constants/regexes');
const isInvalidFirstParameter = require('./isInvalidFirstParameter');
const {
Expand Down
3 changes: 1 addition & 2 deletions transformator/transformAtrules/transformTOnly/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { camelize, decamelize } = require('humps');
const { isArray } = require('../../../helpers');
const { isArray, camelize, decamelize } = require('../../../helpers');
const {
breakpointsToCebabCase,
calcBreakpointOnly,
Expand Down
2 changes: 1 addition & 1 deletion transformator/transformDecls/transformMsUnit/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { camelize } = require('humps');
const { camelize } = require('../../../helpers');
const msToRem = require('../../../api/modularScale/msToRem');
const { makeBreakpointsModel } = require('../../../api/makeBreakpointsModel');
const {
Expand Down

0 comments on commit 5911e73

Please sign in to comment.