UNPKG

5.86 kBMarkdownView Raw
1**Protege is a versatile NodeJS extension library that aims to make code as simple as possible**
2
3
4## Installation
5
6To install Protege, use [npm](http://github.com/isaacs/npm):
7
8 $ npm install -g protege
9
10## Usage
11
12```require('protege')``` - it's that easy
13
14### Object
15####These apply to all types, some are Object specific though
16```
17.clone() - Duplicates the object into a new reference
18.clear() - Removes all keys and values from the objects
19.concat(source) - Adds all properties/values from source to object.
20 (optional) overwrite = true will overwrite existing values with source values
21.merge(source, overwrite, deep) - Merge source properties/values into object.
22 (optional) overwrite = true will overwrite existing values with source values
23 (optional) deep = true will initiate a deep merge, merging descriptors and non-enumerable properties
24
25.extend(source) - Alias for merge
26.unique(merge) - Returns a unique copy of the object. (optional) merge will merge values for duplicate keys into arrays instead of removing them
27
28Object.isEmpty(object) - Returns true if object is empty
29Object.isObject(object) - Returns true if object is an object
30Object.isArray(object) - Returns true if object is an array
31Object.isElement(object) - Returns true if object is a DOM element
32Object.isBoolean(object) - Returns true if object is a boolean
33Object.isNumber(object) - Returns true if object is a number
34Object.isString(object) - Returns true if object is a string
35Object.isFunction(object) - Returns true if object is a function
36Object.isXML(object) - Returns true if object is an XML object
37
38.keys() - Returns all keys in the object
39.values() - Returns all values in the object
40
41.getKey() - Returns first key in object
42.getValue() - Returns first value in object
43.getKeys(value) - Returns all keys for the corresponding value
44.getValues(key) - Returns all values for the corresponding key
45
46.remove(key) - Removes key from object
47
48.stringify() - Returns JSON string for object
49.prettify() - Returns a human readable JSON string for object
50```
51
52### Array
53####These also apply to String (since String is just an array after all) but some are only really useful for true arrays
54```
55.clone() - Duplicates the array into a new reference.
56
57.merge(arr) - Adds array arr to array
58.unique() - Returns a copy of the array with duplicates removed
59.flatten() - Returns a one-dimensional copy of the array
60.compact() - Returns a copy of the array with all undefined and null items removed
61.intersect(arr) - Returns an array of all items in both arr and the array
62
63.size() - Returns size of array
64.first() - Returns first value or array or undefined
65.last() - Returns last value or array or undefined
66
67.replace(value, newval) - Replaces first instance of value with newval
68.replaceIndex(index, value) - Replaces item at index with value
69.replaceAll(value, newval) - Replaces all instances of value with newval
70.remove(value) - Removes first instance of value from array
71.removeAll(value) - Removes all instances of value from array.
72.removeAllIgnoreCase(value) - Removes all instances of value from array ignoring case
73.removeIndex(idx) - Removes index of idx from array
74```
75
76### String
77```
78.upcase() - Alias for toUpperCase(), inspired by Ruby syntax
79.downcase() - Alias for toLowerCase(), inspired by Ruby syntax
80
81.strip() - Alias for trim(), inspired by Ruby syntax
82.rstrip() - Alias for trimRight(), inspired by Ruby syntax
83.lstrip() - Alias for trimLeft(), inspired by Ruby syntax
84
85.replaceAll(value, newval) - Replaces all instances of value with newval
86
87.startsWith(value) - Returns true if string starts with value, inspired by Java syntax
88.endsWith(value) - Returns true if string ends with value, inspired by Java syntax
89.startsWithIgnoreCase(value) - Returns true if string starts with value ignoring case, inspired by Java syntax
90.endsWithIgnoreCase(value) - Returns true if string ends with value ignoring case, inspired by Java syntax
91
92.contains(value) - Returns true if the string contains value, inspired by Java syntax
93.containsIgnoreCase(value) - Returns true if the string contains value ignoring case, inspired by Java syntax
94.equalsIgnoreCase(value) - Returns true if the string equals value ignoring case, inspired by Java syntax
95```
96
97### Function
98```
99.memoize() - Caches result for parameters so any future calls will skip execution and return previous result
100 Example: var cacheFunc = myFunc.memoize(); cacheFunc(15); cacheFunc(13); cacheFunc(15);
101 Only the first two calls will actually be executed.
102```
103## Examples
104
105You can view further examples in the [example folder.](https://github.com/wearefractal/protege/tree/master/examples)
106
107## Contributors
108
109- [Contra](https://github.com/Contra)
110
111## LICENSE
112
113(MIT License)
114
115Copyright (c) 2011 Fractal <contact@wearefractal.com>
116
117Permission is hereby granted, free of charge, to any person obtaining
118a copy of this software and associated documentation files (the
119"Software"), to deal in the Software without restriction, including
120without limitation the rights to use, copy, modify, merge, publish,
121distribute, sublicense, and/or sell copies of the Software, and to
122permit persons to whom the Software is furnished to do so, subject to
123the following conditions:
124
125The above copyright notice and this permission notice shall be
126included in all copies or substantial portions of the Software.
127
128THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
129EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
130MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
131NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
132LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
133OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
134WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
135
\No newline at end of file