初始化

This commit is contained in:
yziiy
2025-08-11 11:06:07 +08:00
parent 083bc37c00
commit 5607d11395
19772 changed files with 3108723 additions and 18 deletions

View File

@@ -0,0 +1,10 @@
## 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
- Fix calling split w/o options.
## 1.0.0
- Initial release.

View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Jed Mao
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.

View File

@@ -0,0 +1,52 @@
# css-list-helpers
[![NPM version](http://img.shields.io/npm/v/css-list-helpers.svg?style=flat)](https://www.npmjs.org/package/css-list-helpers)
[![npm license](http://img.shields.io/npm/l/css-list-helpers.svg?style=flat-square)](https://www.npmjs.org/package/css-list-helpers)
[![Travis Build Status](https://img.shields.io/travis/jedmao/css-list-helpers.svg?label=unix)](https://travis-ci.org/jedmao/css-list-helpers)
[![codecov](https://codecov.io/gh/jedmao/css-list-helpers/branch/master/graph/badge.svg)](https://codecov.io/gh/jedmao/css-list-helpers)
[![npm](https://nodei.co/npm/css-list-helpers.svg?downloads=true)](https://nodei.co/npm/css-list-helpers/)
Helper methods for splitting CSS lists (i.e., by spaces or commas), extracted from [PostCSS#list](https://github.com/postcss/postcss/blob/master/lib/list.es6).
## Installation
```
$ npm install css-list-helpers [--save[-dev]]
```
## Usage
```js
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)']
```
### 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
```
$ npm test
```
This will run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.

View File

@@ -0,0 +1,32 @@
/**
* 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[];

View File

@@ -0,0 +1,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;

View File

@@ -0,0 +1,65 @@
{
"name": "css-list-helpers",
"version": "2.0.0",
"description": "Helper methods for splitting CSS lists (e.g., spaces, commas).",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"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": {
"type": "git",
"url": "git+https://github.com/jedmao/css-list-helpers.git"
},
"keywords": [
"css",
"list",
"helpers",
"split",
"space",
"comma"
],
"author": "Jed Mao <jedmao@outlook.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/jedmao/css-list-helpers/issues"
},
"homepage": "https://github.com/jedmao/css-list-helpers#readme",
"devDependencies": {
"ava": "^0.25.0",
"concurrently": "^3.5.1",
"nyc": "^11.7.1",
"rimraf": "^2.6.2",
"tslint": "^5.10.0",
"typescript": "^2.8.3"
}
}