css-list-helpers
Advanced tools
| /** | ||
| * Splits a CSS declaration value (shorthand) using provided separators | ||
| * as the delimiters. | ||
| */ | ||
| export declare function split( | ||
| /** | ||
| * A CSS declaration value (shorthand). | ||
| */ | ||
| value: string, | ||
| /** | ||
| * Any number of separator characters used for splitting. | ||
| */ | ||
| separators: string[], {last}?: { | ||
| last?: boolean; | ||
| }): string[]; | ||
| /** | ||
| * Splits a CSS declaration value (shorthand) using whitespace characters | ||
| * as the delimiters. | ||
| */ | ||
| export declare function splitBySpaces( | ||
| /** | ||
| * A CSS declaration value (shorthand). | ||
| */ | ||
| value: string): string[]; | ||
| /** | ||
| * Splits a CSS declaration value (shorthand) using commas as the delimiters. | ||
| */ | ||
| export declare function splitByCommas( | ||
| /** | ||
| * A CSS declaration value (shorthand). | ||
| */ | ||
| value: string): string[]; |
+102
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| /** | ||
| * Splits a CSS declaration value (shorthand) using provided separators | ||
| * as the delimiters. | ||
| */ | ||
| function split( | ||
| /** | ||
| * A CSS declaration value (shorthand). | ||
| */ | ||
| value, | ||
| /** | ||
| * Any number of separator characters used for splitting. | ||
| */ | ||
| separators, _a) { | ||
| var _b = (_a === void 0 ? {} : _a).last, last = _b === void 0 ? false : _b; | ||
| if (typeof value !== 'string') { | ||
| throw new TypeError('expected a string'); | ||
| } | ||
| if (!Array.isArray(separators)) { | ||
| throw new TypeError('expected a string array of separators'); | ||
| } | ||
| if (typeof last !== 'boolean') { | ||
| throw new TypeError('expected a Boolean value for options.last'); | ||
| } | ||
| var array = []; | ||
| var current = ''; | ||
| var splitMe = false; | ||
| var func = 0; | ||
| var quote = false; | ||
| var escape = false; | ||
| for (var _i = 0, value_1 = value; _i < value_1.length; _i++) { | ||
| var char = value_1[_i]; | ||
| if (quote) { | ||
| if (escape) { | ||
| escape = false; | ||
| } | ||
| else if (char === '\\') { | ||
| escape = true; | ||
| } | ||
| else if (char === quote) { | ||
| quote = false; | ||
| } | ||
| } | ||
| else if (char === '"' || char === '\'') { | ||
| quote = char; | ||
| } | ||
| else if (char === '(') { | ||
| func += 1; | ||
| } | ||
| else if (char === ')') { | ||
| if (func > 0) { | ||
| func -= 1; | ||
| } | ||
| } | ||
| else if (func === 0) { | ||
| if (separators.indexOf(char) !== -1) { | ||
| splitMe = true; | ||
| } | ||
| } | ||
| if (splitMe) { | ||
| if (current !== '') { | ||
| array.push(current.trim()); | ||
| } | ||
| current = ''; | ||
| splitMe = false; | ||
| } | ||
| else { | ||
| current += char; | ||
| } | ||
| } | ||
| if (last || current !== '') { | ||
| array.push(current.trim()); | ||
| } | ||
| return array; | ||
| } | ||
| exports.split = split; | ||
| /** | ||
| * Splits a CSS declaration value (shorthand) using whitespace characters | ||
| * as the delimiters. | ||
| */ | ||
| function splitBySpaces( | ||
| /** | ||
| * A CSS declaration value (shorthand). | ||
| */ | ||
| value) { | ||
| var spaces = [' ', '\n', '\t']; | ||
| return split(value, spaces); | ||
| } | ||
| exports.splitBySpaces = splitBySpaces; | ||
| /** | ||
| * Splits a CSS declaration value (shorthand) using commas as the delimiters. | ||
| */ | ||
| function splitByCommas( | ||
| /** | ||
| * A CSS declaration value (shorthand). | ||
| */ | ||
| value) { | ||
| var comma = ','; | ||
| return split(value, [comma], { last: true }); | ||
| } | ||
| exports.splitByCommas = splitByCommas; |
+5
-0
@@ -0,1 +1,6 @@ | ||
| ## 2.0.0 | ||
| - **Breaking:** Remove tcomb dependency (use `typeof` instead). The only breaking change about this is that it will provide different error messages, which could potentially break existing implementations. Most people should be able to upgrade w/o changes to their code. | ||
| - Convert source code into TypeScript. | ||
| - Provide TypeScript-generated type definitions. | ||
| ## 1.0.1 | ||
@@ -2,0 +7,0 @@ - Fix calling split w/o options. |
+39
-10
| { | ||
| "name": "css-list-helpers", | ||
| "version": "1.0.1", | ||
| "version": "2.0.0", | ||
| "description": "Helper methods for splitting CSS lists (e.g., spaces, commas).", | ||
| "main": "index.js", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "scripts": { | ||
| "test": "npm run cover && npm run check-coverage", | ||
| "cover": "istanbul cover test/index.js", | ||
| "check-coverage": "istanbul check-coverage" | ||
| "clean": "rimraf coverage dist *.log css-list-helpers-*", | ||
| "codecov": "codecov -f coverage/lcov.info", | ||
| "prebuild": "npm run clean && npm run lint", | ||
| "build": "tsc", | ||
| "prebuild:watch": "npm run prebuild", | ||
| "build:watch": "tsc --watch", | ||
| "lint": "tslint --project tsconfig.test.json", | ||
| "pretest": "npm run build -- --project tsconfig.test.json", | ||
| "test": "nyc ava --verbose", | ||
| "watch": "concurrently \"npm run build:watch\" \"npm test -- --watch\"", | ||
| "prepack": "npm test && npm run build" | ||
| }, | ||
| "nyc": { | ||
| "lines": 100, | ||
| "statements": 100, | ||
| "functions": 100, | ||
| "branches": 100, | ||
| "include": [ | ||
| "dist/**/*.js" | ||
| ], | ||
| "exclude": [ | ||
| "dist/**/*.test.js" | ||
| ], | ||
| "reporter": [ | ||
| "lcov", | ||
| "text" | ||
| ], | ||
| "cache": true, | ||
| "all": true, | ||
| "check-coverage": true | ||
| }, | ||
| "repository": { | ||
@@ -29,9 +57,10 @@ "type": "git", | ||
| "homepage": "https://github.com/jedmao/css-list-helpers#readme", | ||
| "dependencies": { | ||
| "tcomb": "^2.5.0" | ||
| }, | ||
| "devDependencies": { | ||
| "istanbul": "^0.3.21", | ||
| "tape": "^4.2.0" | ||
| "ava": "^0.25.0", | ||
| "concurrently": "^3.5.1", | ||
| "nyc": "^11.7.1", | ||
| "rimraf": "^2.6.2", | ||
| "tslint": "^5.10.0", | ||
| "typescript": "^2.8.3" | ||
| } | ||
| } |
+23
-3
@@ -6,2 +6,3 @@ # css-list-helpers | ||
| [](https://travis-ci.org/jedmao/css-list-helpers) | ||
| [](https://codecov.io/gh/jedmao/css-list-helpers) | ||
@@ -22,7 +23,26 @@ [](https://nodei.co/npm/css-list-helpers/) | ||
| var listHelpers = require('css-list-helpers'); | ||
| listHelpers.splitBySpaces(' 0 a(b / c) "d e" '); // ['0', 'a(b / c)', '"d e"'] | ||
| listHelpers.splitByCommas(' 0, a(b / c), "d e" '); // ['0', 'a(b / c)', '"d e"'] | ||
| listHelpers.split('a/fn(b / c)', ['/']); // ['a', 'fn(b / c)'] | ||
| listHelpers.splitBySpaces(' 0 a(b / c) "d e" '); | ||
| // ['0', 'a(b / c)', '"d e"'] | ||
| listHelpers.splitByCommas(' 0, a(b / c), "d e" '); | ||
| // ['0', 'a(b / c)', '"d e"'] | ||
| listHelpers.split('a/fn(b / c)', ['/']); | ||
| // ['a', 'fn(b / c)'] | ||
| ``` | ||
| ### ES6/2015 import | ||
| ```ts | ||
| import * as listHelpers from 'css-list-helpers'; | ||
| ``` | ||
| ## Docs | ||
| This project provides first-class TypeScript support via generated TypeScript | ||
| definitions, included with the package. As such, you shouldn't have to | ||
| look-up documentation in your editor, so long as your editor supports | ||
| TypeScript. | ||
| ## Testing | ||
@@ -29,0 +49,0 @@ |
-82
| var t = require('tcomb'); | ||
| var Options = t.struct({ | ||
| last: t.maybe(t.Boolean) | ||
| }); | ||
| var helpers = { | ||
| split: function(value, separators, options) { | ||
| return split(value, separators, options || {}); | ||
| }, | ||
| splitBySpaces: t.func(t.String, t.Array).of( | ||
| function(value) { | ||
| var spaces = [' ', '\n', '\t']; | ||
| return helpers.split(value, spaces); | ||
| } | ||
| ), | ||
| splitByCommas: t.func(t.String, t.Array).of( | ||
| function(value) { | ||
| var comma = ','; | ||
| return helpers.split(value, [comma], { last: true }); | ||
| } | ||
| ) | ||
| }; | ||
| var split = t.func([t.String, t.Array, Options], t.Array).of( | ||
| function(value, separators, options) { | ||
| var array = []; | ||
| var current = ''; | ||
| var split = false; | ||
| var func = 0; | ||
| var quote = false; | ||
| var escape = false; | ||
| for (var i = 0; i < value.length; i++) { | ||
| var char = value[i]; | ||
| if (quote) { | ||
| if (escape) { | ||
| escape = false; | ||
| } else if (char === '\\') { | ||
| escape = true; | ||
| } else if (char === quote) { | ||
| quote = false; | ||
| } | ||
| } else if (char === '"' || char === '\'') { | ||
| quote = char; | ||
| } else if (char === '(') { | ||
| func += 1; | ||
| } else if (char === ')') { | ||
| if (func > 0) { | ||
| func -= 1; | ||
| } | ||
| } else if (func === 0) { | ||
| if (separators.indexOf(char) !== -1) { | ||
| split = true; | ||
| } | ||
| } | ||
| if (split) { | ||
| if (current !== '') { | ||
| array.push(current.trim()); | ||
| } | ||
| current = ''; | ||
| split = false; | ||
| } else { | ||
| current += char; | ||
| } | ||
| } | ||
| if (options.last || current !== '') { | ||
| array.push(current.trim()); | ||
| } | ||
| return array; | ||
| } | ||
| ); | ||
| module.exports = helpers; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8333
72.03%0
-100%6
20%134
94.2%53
60.61%6
200%1
Infinity%- Removed
- Removed