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

Commit

Permalink
[fixed] favor lodash over native methods
Browse files Browse the repository at this point in the history
  • Loading branch information
thealjey committed Apr 5, 2017
1 parent 41c8c95 commit f29f23d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/SASSLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type {LintCallback} from './typedef';
import {join} from 'path';
import forEach from 'lodash/forEach';
import replace from 'lodash/replace';
import {lint} from 'stylelint';
import {logError} from './logger';

Expand Down Expand Up @@ -69,7 +70,7 @@ export class SASSLint {

forEach(results, ({source: file, warnings}) => {
forEach(warnings, ({line, column, text, rule}) => {
errors.push({file, line, column, message: text.replace(new RegExp(`\\s*\\(${rule}\\)$`), ''), rule});
errors.push({file, line, column, message: replace(text, new RegExp(`\\s*\\(${rule}\\)$`), ''), rule});
});
});
callback(errors.length ? errors : null);
Expand Down
12 changes: 8 additions & 4 deletions src/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import has from 'lodash/has';
import flattenDeep from 'lodash/flattenDeep';
import isString from 'lodash/isString';
import trim from 'lodash/trim';
import replace from 'lodash/replace';
import toUpper from 'lodash/toUpper';
import toLower from 'lodash/toLower';
import split from 'lodash/split';

/**
* Useful utilities for working with JSX.
Expand Down Expand Up @@ -43,7 +47,7 @@ export function parseHTML(html: string): Object {
* @return {string} JSX style key
*/
export function toJSXKey(key: string): string {
return (/^-ms-/.test(key) ? key.substr(1) : key).replace(/-(.)/g, (match, chr) => chr.toUpperCase());
return replace(/^-ms-/.test(key) ? key.substr(1) : key, /-(.)/g, (match, chr) => toUpper(chr));
}

/**
Expand All @@ -56,12 +60,12 @@ export function toJSXKey(key: string): string {
*/
export function transformStyle(object: Object) {
if (has(object, 'style')) {
object.style = transform(object.style.split(';'), (result, style) => {
object.style = transform(split(object.style, ';'), (result, style) => {
const firstColon = style.indexOf(':'),
key = style.substr(0, firstColon).trim();
key = trim(style.substr(0, firstColon));

if (key) {
result[toJSXKey(key.toLowerCase())] = style.substr(firstColon + 1).trim();
result[toJSXKey(toLower(key))] = trim(style.substr(firstColon + 1));
}
}, {});
}
Expand Down

0 comments on commit f29f23d

Please sign in to comment.